Skip to content

Instantly share code, notes, and snippets.

@RaghavRao
RaghavRao / virsh_map_pci.sh
Created April 28, 2021 00:52
Find PCI device in virsh nodedev format
#!/bin/bash
virsh nodedev-list --cap pci | grep $( echo pci_.*"$(lspci | grep "$1" | awk '{ print $1 }' | tr ':' '_' | tr '.' '_' )" )
relpath(){ python -c "import os.path; print os.path.relpath('$1','${2:-$PWD}')" ; }
show_latest () {
if [ -z "$1" ]
then
local dir=$PWD
else
local dir="$1"
fi
ls --sort=time --reverse "$dir" | tail -1 ;
}
@RaghavRao
RaghavRao / new_script.sh
Last active August 16, 2018 18:21
Create a new script by executing "which".
#!/bin/bash
# Append to ~/.bashrc
# Usage:
# Default editor from /etc/alternatives/editor: $ nf python ~/scripy.py
# Custom editor: $ nf python ~/script.py vi
nf() {
STR=$( echo "#!"`which "$1"` )
if [ ! -f "$2" ]; then
echo $STR > "$2"
echo "" >> "$2"