Skip to content

Instantly share code, notes, and snippets.

@slashinfty slashinfty/.bash_aliases
Last active Jan 4, 2020

Embed
What would you like to do?
Collection of various hacky bash functions
# quick apt commands
alias upd='sudo apt update && sudo apt list --upgradable'
alias upg='sudo apt upgrade -y'
alias ins='sudo apt install'
alias prg='sudo apt purge'
alias avail='apt policy'
# adding applications to dmenu
# first parameter: name of entry
# second parameter (for add): command to launch application
alias dm-add='sudo -v && dmenu-add'
alias dm-del='sudo -v && dmenu-del'
function dmenu-add() {
if [[ $# -lt 2 ]]; then
echo "missing parameters"
exit 1
fi
ENTRY="/usr/bin/$1"
sudo touch ${ENTRY}
HEAD="#! /bin/bash"
echo "${HEAD}" | sudo tee -a ${ENTRY} >/dev/null
echo "$2" | sudo tee -a ${ENTRY} >/dev/null
sudo chmod +x ${ENTRY}
echo "added ${ENTRY}"
sudo cat ${ENTRY}
}
function dmenu-del() {
if [[ $# -lt 1 ]]; then
echo "missing parameters"
exit 1
fi
ENTRY="/usr/bin/$1"
sudo rm ${ENTRY}
echo "removed ${ENTRY}"
}
# simple timer (enter to split)
# can include parameter to show file contents
alias splits='shplit'
function shplit() {
FORMAT="%s.%2N"
STARTTIME=$(date +${FORMAT})
#if [[ $# -eq 1 ]]; then
#clear
#case $1 in
# "parameter-name")
# cat file-name
# ;;
# *)
# echo "no splits found"
# ;;
#esac
#fi
function format_duration {
printf "%.2f" $1
}
function tick_time {
DUR=$(format_duration $(bc <<< $(date +${FORMAT})-$STARTTIME))
PRETTY_DUR=$(date +%T.%2N -u -d "@${DUR}")
printf "\r%s " ${PRETTY_DUR}
}
function finish_up {
tick_time
echo
}
trap finish_up exit
echo "End timing with ctrl-c."
while true; do
tick_time
done
}
# shows currently playing track
# works for music programs that change their window name to track name
alias now-playing='nowplay'
function nowplay() {
if [[ $# -ne 1 ]]; then
echo 'invalid parameters'
exit
fi
HEXID=$(wmctrl -l | grep -i $1 | awk '{print $1}')
echo "found $1 - start playing now"
function showplaying {
clear
TRACK=$(wmctrl -l | grep ${HEXID} | grep -o "$HOSTNAME.*" | sed "s/debian //g")
printf "Now playing: %s\n" "${TRACK}"
}
while true; do
sleep 5
showplaying
done
}
# automatically compiles TeX files and cleans up extra files
alias tex-pdf='makepdf'
function makepdf() {
for T in *.tex; do if ! [[ -f "${T%.*}.pdf" ]]; then xelatex ${T}; fi; done
for A in *.aux; do rm ${A}; done
for L in *.log; do rm ${L}; done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.