Last active
March 17, 2020 14:46
-
-
Save slashinfty/1006964186b2edc03e8d28463fc8c3b4 to your computer and use it in GitHub Desktop.
Collection of various hacky bash functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# quick apt commands | |
alias upd='sudo apt update && sudo apt list --upgradable' | |
alias upg='sudo apt upgrade -y && sudo apt autoremove -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} | |
exec bash | |
} | |
function dmenu-del() { | |
if [[ $# -lt 1 ]]; then | |
echo "missing parameters" | |
exit 1 | |
fi | |
ENTRY="/usr/bin/$1" | |
sudo rm ${ENTRY} | |
echo "removed ${ENTRY}" | |
exec bash | |
} | |
# simple timer (enter to split) | |
# can include parameter to show file contents | |
# REQ: bc | |
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 | |
# parameter is the name of the program | |
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 | |
# REQ: texlive | |
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 | |
} | |
# download and display a LaTeX equation | |
# parameter is a LaTeX equation in double quotes | |
# REQ: fim | |
alias math='latex-png' | |
function latex-png() { | |
curl -G "http://latex.codecogs.com/png.latex" --data-urlencode '\bg_white&space;\huge&space;'"$1" > image.png | |
fim image.png & | |
disown | |
sleep 1 | |
rm image.png | |
} | |
# read markdown files in terminal | |
# REQ: pandoc, lynx | |
alias md='markdown' | |
function markdown() { | |
pandoc "$1" | lynx -stdin; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment