123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- ##### My (demuredemeanor) bashrc sub source function script
- # Uses tabstop=4; shiftwidth=4 tabs; foldmarker={{{,}}};
- # https://notabug.org/demure/dotfiles/
- # legacy repo http://github.com/demure/dotfiles
- # vim:set syntax=sh:
- ### Extract Function ### {{{
- ## Extract most types of compressed files
- function extract {
- echo Extracting $1 ...
- if [ -f $1 ] ; then
- case $1 in
- *.tar.bz2) tar xjf $1 ;;
- *.tar.gz) tar xzf $1 ;;
- *.bz2) bunzip2 $1 ;;
- *.rar) rar x $1 ;;
- *.gz) gunzip $1 ;;
- *.tar) tar xf $1 ;;
- *.tbz2) tar xjf $1 ;;
- *.tgz) tar xzf $1 ;;
- *.zip) unzip $1 ;;
- *.Z) uncompress $1 ;;
- *.7z) 7z x $1 ;;
- *.xz) xz -d $1 ;;
- *) echo "'$1' cannot be extracted via extract()" ;;
- esac
- else
- echo "'$1' is not a valid file"
- fi
- }
- ### End Extract ### }}}
- ### Man Function ### {{{
- ## Color man pages with less (is a `most` way too...)
- man() {
- env \
- LESS_TERMCAP_mb=$(printf "\e[1;31m") \
- LESS_TERMCAP_md=$(printf "\e[1;31m") \
- LESS_TERMCAP_me=$(printf "\e[0m") \
- LESS_TERMCAP_se=$(printf "\e[0m") \
- LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
- LESS_TERMCAP_ue=$(printf "\e[0m") \
- LESS_TERMCAP_us=$(printf "\e[1;32m") \
- man "$@"
- }
- ### End Man ### }}}
- ### Git Files Hist Function ### {{{
- function git_files_hist() {
- git log --pretty=%h | while read hash; do git ls-tree -r ${hash} | awk '{print $4}'; done | sort -u
- }
- ### End Git Hist ### }}}
- ### Backup File ### {{{
- # http://xmodulo.com/useful-bash-aliases-functions.html
- backup() { cp "$1"{,.bak};}
- ### End Backup ### }}}
- ### IP Look Up ### {{{
- ipinfo() {
- local IP1 IP2
- IP1="$1"
- 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})$')"
- if [[ ${IP2} == "1" ]]; then
- curl ipinfo.io/"${IP1}"
- else
- ipawk=($(host "${IP1}" | awk '/address/ { print $NF }'))
- curl ipinfo.io/${ipawk[1]}
- fi
- echo
- }
- ipapi() {
- local IP1 IP2
- IP1="$1"
- 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})$')"
- if [[ ${IP2} == "1" ]]; then
- curl ip-api.com/${IP1}?fields=query,reverse,message,country,regionName,city,isp,org,proxy
- else
- ipawk=($(host "${IP1}" | awk '/address/ { print $NF }'))
- curl ip-api.com/${ipawk[1]}?fields=query,reverse,message,country,regionName,city,isp,org,proxy
- fi
- echo
- }
- ### End IP Look Up ### }}}
- ### Mpv Search Youtube ### {{{
- ## mm "search terms"
- function mm() {
- mpv --no-video --ytdl-format=bestaudio ytdl://ytsearch10:"$@"
- }
- ### End Mpv Search ### }}}
- ### Remove gps exif ### {{{
- ## Iterates over contents of current dir
- function exifclean() {
- exiftool -p '$filepath $gpslatitude $gpslongitude' -a -gps:all * 2> /dev/null | awk '{system("exiftool -overwrite_original '-gps*=' "$1" 2>/dev/null")}'
- }
- ### Remove gps exif ### }}}
- ### Note ### {{{
- ## An aproximation of Notational Velocity and Terminal Velocity
- ## gensub currently replacing
- function note() {
- pushd ~/Notes 1>/dev/null && \
- vim $(fzf -i --cycle --reverse --preview-window=down --preview='cat {}' --print-query | gawk 'END{if($0 !~ /.txt$/){$0=gensub(" ","_","g",$0) ".txt"}; print $0}')
- popd 1>/dev/null
- }
- ### End Note ### }}}
|