function 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. ##### My (demuredemeanor) bashrc sub source function script
  2. # Uses tabstop=4; shiftwidth=4 tabs; foldmarker={{{,}}};
  3. # https://notabug.org/demure/dotfiles/
  4. # legacy repo http://github.com/demure/dotfiles
  5. # vim:set syntax=sh:
  6. ### Extract Function ### {{{
  7. ## Extract most types of compressed files
  8. function extract {
  9. echo Extracting $1 ...
  10. if [ -f $1 ] ; then
  11. case $1 in
  12. *.tar.bz2) tar xjf $1 ;;
  13. *.tar.gz) tar xzf $1 ;;
  14. *.bz2) bunzip2 $1 ;;
  15. *.rar) rar x $1 ;;
  16. *.gz) gunzip $1 ;;
  17. *.tar) tar xf $1 ;;
  18. *.tbz2) tar xjf $1 ;;
  19. *.tgz) tar xzf $1 ;;
  20. *.zip) unzip $1 ;;
  21. *.Z) uncompress $1 ;;
  22. *.7z) 7z x $1 ;;
  23. *.xz) xz -d $1 ;;
  24. *) echo "'$1' cannot be extracted via extract()" ;;
  25. esac
  26. else
  27. echo "'$1' is not a valid file"
  28. fi
  29. }
  30. ### End Extract ### }}}
  31. ### Man Function ### {{{
  32. ## Color man pages with less (is a `most` way too...)
  33. man() {
  34. env \
  35. LESS_TERMCAP_mb=$(printf "\e[1;31m") \
  36. LESS_TERMCAP_md=$(printf "\e[1;31m") \
  37. LESS_TERMCAP_me=$(printf "\e[0m") \
  38. LESS_TERMCAP_se=$(printf "\e[0m") \
  39. LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
  40. LESS_TERMCAP_ue=$(printf "\e[0m") \
  41. LESS_TERMCAP_us=$(printf "\e[1;32m") \
  42. man "$@"
  43. }
  44. ### End Man ### }}}
  45. ### Git Files Hist Function ### {{{
  46. function git_files_hist() {
  47. git log --pretty=%h | while read hash; do git ls-tree -r ${hash} | awk '{print $4}'; done | sort -u
  48. }
  49. ### End Git Hist ### }}}
  50. ### Backup File ### {{{
  51. # http://xmodulo.com/useful-bash-aliases-functions.html
  52. backup() { cp "$1"{,.bak};}
  53. ### End Backup ### }}}
  54. ### IP Look Up ### {{{
  55. ipinfo() {
  56. local IP1 IP2
  57. IP1="$1"
  58. IP2="$(echo "${IP1}" | grep -Ec '^(([0-9a-f]{0,4}:){1,7}[0-9a-f]{1,4}|([0-9]{1,3}\.){3}[0-9]{1,3})$')"
  59. if [[ ${IP2} == "1" ]]; then
  60. curl ipinfo.io/"${IP1}"
  61. else
  62. ipawk=($(host "${IP1}" | awk '/address/ { print $NF }'))
  63. curl ipinfo.io/${ipawk[1]}
  64. fi
  65. echo
  66. }
  67. ### End IP Look Up ### }}}
  68. ### Mpv Search Youtube ### {{{
  69. ## mm "search terms"
  70. function mm() {
  71. mpv --no-video --ytdl-format=bestaudio ytdl://ytsearch10:"$@"
  72. }
  73. ### End Mpv Search ### }}}