Add misc bash helper functions

This commit is contained in:
William Carroll 2018-01-08 15:42:01 -05:00
parent 4f1d7650a4
commit 8cadd912a6

View file

@ -4,6 +4,29 @@ function wgfb {
} }
# utility function for swapping filenames, eg init.el and init.el.bak
function swap-file-names {
file_a=$1
file_b=$2
backup=$(mktemp backup.XXX)
mv ${file_a} ${backup}
mv ${file_b} ${file_a}
mv ${backup} ${file_b}
rm ${backup}
echo "Swapped: ${file_a} <-> ${file_b}"
}
# View a directory's contents in a periodically updated fashion.
function periodically-refresh-contents {
clear
lt .
sleep 1
refresh-contents
}
# download files to /tmp directory # download files to /tmp directory
function wdownload { function wdownload {
URL="$1" URL="$1"
@ -20,18 +43,6 @@ function wspcheck {
} }
# fuzzily search through dirs stack
function wfd {
dir=$(dirname $(fzf-tmux)) && pushd "$dir" >/dev/null
}
# pushd into a directory on your dirs stack
function wpushd {
dir="$(dirs | tr ' ' '\n' | fzf-tmux)" && pushd "$dir"
}
# trims leading and trailing whitespace # trims leading and trailing whitespace
function trim { function trim {
input="$1" input="$1"
@ -131,3 +142,9 @@ function du-it-live () {
echo -n '\b\b\b' && echo -n ' ' && echo -n '\r' echo -n '\b\b\b' && echo -n ' ' && echo -n '\r'
done done
} }
# programmatically get the router's IP address
function router {
netstat -nr | grep default | head -n 1 | awk '{ print $2 }'
}