function 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. ipapi() {
  68. local IP1 IP2
  69. IP1="$1"
  70. 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})$')"
  71. if [[ ${IP2} == "1" ]]; then
  72. curl ip-api.com/${IP1}?fields=query,reverse,message,country,regionName,city,isp,org,proxy
  73. else
  74. ipawk=($(host "${IP1}" | awk '/address/ { print $NF }'))
  75. curl ip-api.com/${ipawk[1]}?fields=query,reverse,message,country,regionName,city,isp,org,proxy
  76. fi
  77. echo
  78. }
  79. ### End IP Look Up ### }}}
  80. ### Mpv Search Youtube ### {{{
  81. ## mm "search terms"
  82. function mm() {
  83. mpv --no-video --ytdl-format=bestaudio ytdl://ytsearch10:"$@"
  84. }
  85. ### End Mpv Search ### }}}
  86. ### Remove gps exif ### {{{
  87. ## Iterates over contents of current dir
  88. function exifclean() {
  89. exiftool -p '$filepath $gpslatitude $gpslongitude' -a -gps:all * 2> /dev/null | awk '{system("exiftool -overwrite_original '-gps*=' "$1" 2>/dev/null")}'
  90. }
  91. ### Remove gps exif ### }}}
  92. ### Note ### {{{
  93. ## An aproximation of Notational Velocity and Terminal Velocity
  94. ## gensub currently replacing
  95. function note() {
  96. pushd ~/Notes 1>/dev/null && \
  97. vim $(fzf -i --cycle --reverse --preview-window=down --preview='cat {}' --print-query | gawk 'END{if($0 !~ /.txt$/){$0=gensub(" ","_","g",$0) ".txt"}; print $0}')
  98. popd 1>/dev/null
  99. }
  100. ### End Note ### }}}