───────┬────────────────────────────────────────────────────────────────────────
       File: /home/mitch/.bashrc
───────┼────────────────────────────────────────────────────────────────────────
   1    # Description: My setting file for bash
   2    # Author.....: Mitchell Johnston
   3    # Updated....: Tue Sep 16 11:37:10 AM CDT 2025
   4    
   5    : ' Changes
   6    Sat Aug 02 2025 Modified PS1
   7    Thu Feb 08 2024 Going old school
   8    Thu Feb 08 2024 Went back to fc for history control
   9    '
  10    
  11    # If not running interactively, don't do anything
  12    #---------------------------
  13    [ -z "$PS1" ] && return
  14    
  15    # Install check
  16    # -------------
  17    # This is part of my auto-install system. Most of my scripts and environment self
  18    # configure.
  19    [ ! -f ~/.install.log ] && bash ~/bin/config|tee -a ~/.install.log
  20    
  21    # Environment variables
  22    # =====================
  23    
  24    # Colors - uncomment if needed
  25    # ----------------------------
  26    BK=$(tput setaf 0)
  27    R=$(tput setaf 1)                          # red
  28    BR=$(tput setaf 1; tput bold)              # bold red
  29    G=$(tput setaf 2)                          # green
  30    BG=$(tput setaf 2; tput bold)              # bold green
  31    Y=$(tput setaf 3)                          # yellow
  32    BY=$(tput setaf 3; tput bold)              # bold yellow
  33    B=$(tput setaf 4)                          # blue
  34    BM=$(tput setaf 5; tput bold)              # bold magenta
  35    BC=$(tput setaf 6; tput bold)              # bold cyan
  36    BL=$(tput setaf 7; tput bold)              # bold light grey
  37    BLD=$(tput bold)                           # bold
  38    N=$(tput sgr0)                             # normal
  39    SIT=$(tput sitm)                           # italics
  40    RIT=$(tput ritm)                           # remove italics
  41    UL=$(tput smul)                            # turn underline on
  42    NL=$(tput rmul)                            # turn underline off
  43    RV=$(tput rev)                             # turn on reverse mode
  44    # colors - background
  45    RBG=$(tput setab 1)                         # red background
  46    BRBG=$(tput setab 1 ; tput bold )           # light red background
  47    GBG=$(tput setab 2)                         # green background
  48    BGBG=$(tput setab 2 ; tput bold )           # light green background
  49    YBG=$(tput setab 3)                         # yellow background
  50    BYBG=$(tput setab 3 ; tput bold )           # light yellow background
  51    BBG=$(tput setab 4)                         # blue background
  52    BBBG=$(tput setab 4 ; tput bold )           # light blue background
  53    MBG=$(tput setab 5)                         # purple background
  54    BMBG=$(tput setab 5 ; tput bold )           # light purple background
  55    CBG=$(tput setab 6)                         # cyan background
  56    BCBG=$(tput setab 6 ; tput bold )           # light cyan background
  57    WBG=$(tput setab 7)                         # white background
  58    BWBG=$(tput setab 7 ; tput bold )           # light white background
  59    ROWS=$(tput lines)
  60    COLS=$(tput cols)
  61    
  62    # colorize man
  63    # ------------
  64    source /home/mitch/bin/lscolors.sh
  65    export LESS_TERMCAP_md=$(tput setaf 4; tput bold) # enter double-bright mode - bold blue
  66    export LESS_TERMCAP_me=$(tput sgr0) # leave double-bright, reverse, dim modes
  67    export LESS_TERMCAP_so=$(tput setaf 6; tput bold) # enter standout mode - bold cyan on blue background
  68    export LESS_TERMCAP_se=$(tput rmso)  # leave standout mode
  69    export LESS_TERMCAP_us=$(tput sitm ;tput setaf 3) # enter underline mode - italics, yellow
  70    export LESS_TERMCAP_ue=$(tput ritm) # leave underline mode
  71    export LESS_TERMCAP_mr=$(tput rev) # enter reverse mode
  72    export LESS_TERMCAP_mh=$(tput dim) # enter half-bright mode
  73    export LESS_TERMCAP_ZN=$(tput ssubm) # enter subscript mode
  74    export LESS_TERMCAP_ZV=$(tput rsubm) # leave subscript mode
  75    export LESS_TERMCAP_ZO=$(tput ssupm) # enter superscript mode
  76    export LESS_TERMCAP_ZW=$(tput rsupm) # leave superscript mode
  77    export MANWIDTH=$(tput cols) # check the number of columns and set to that
  78    export MANPAGER='less -s -M +Gg'
  79    
  80    # grep colors for match
  81    # ---------------------
  82    export GREP_COLORS='mt=1;37;42'
  83    
  84    # System
  85    # ------
  86    export LSCOLORS=Exfxcxdxbxegedabagacad
  87    export LC_ALL=en_US.UTF-8
  88    export LANG=en_US.UTF-8
  89    export LANGUAGE=en_US.UTF-8
  90    PATH=~/bin:~/.local/bin:/usr/games:~/bin/dosbox:$PATH
  91    HISTCONTROL=ignoredups:erasedups          # Ignore and remove dupes from history
  92    HISTTIMEFORMAT="%F %T "                   # Add time stamp to history
  93    HISTSIZE=5000
  94    LESSCHARDEF=8bcccbcc13b.4b95.33b.         # show colours in ls -l | less
  95    EDITOR='vim' 
  96    CDPATH="/var/www/include/vids:/var/www/include/vids/clips"
  97    if [ -z $DISPLAY ]
  98        then
  99            BROWSER='lynx' 
 100            OFFICE=lesspipe.sh #https://www.zeuthen.desy.de/~friebel/unix/lesspipe.html
 101            PICS=lesspipe.sh
 102            PDF=lesspipe.sh
 103            EPUB='/home/mitch/.local/bin/epy'
 104        else
 105            BROWSER='brave-browser'
 106            OFFICE=xdg-open
 107            PICS=xdg-open
 108            PDF=xdg-open
 109            EPUB=xdg-open
 110    fi
 111    S_COLORS=auto
 112    NAME=${0##*/}                              # name of the script
 113    MORIA_SAV="/home/mitch/moria.sav"
 114    export DL="mitch-laptop:~/Downloads"
 115    export PYTHONPATH="$PYTHONPATH":~/.libA # fix for pysolfc
 116    export NMON=cndm
 117    
 118    read wday month day year <<< $(date +'%A %b %_d %Y')
 119    
 120    GPATH="/home/mitch/perl5/bin${PATH:+:${PATH}}"; export PATH;
 121    PERL5LIB="/home/mitch/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}"; export PERL5LIB;
 122    PERL_LOCAL_LIB_ROOT="/home/mitch/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB_ROOT}}"; export PERL_LOCAL_LIB_ROOT;
 123    PERL_MB_OPT="--install_base \"/home/mitch/perl5\""; export PERL_MB_OPT;
 124    PERL_MM_OPT="INSTALL_BASE=/home/mitch/perl5"; export PERL_MM_OPT;
 125    
 126    # PS1 Prompt
 127    # ----------
 128    # ES: Exit Status of last command
 129    # L: Shell level
 130    # J: Number of jobs
 131    # user@host
 132    # emoji (edir) and sets window title 
 133    # current directory
 134    #
 135    # ES:0 L:1 J:0 [mitch🌀mitch-laptop] 🔽 ~/Downloads
 136    #
 137    function success_indicator() { ## displays the status of last command
 138        ES=$?
 139        if [ $ES -eq 0 ] ; then
 140            echo "${BK}0${N}"
 141        else
 142            echo "${BR}${ES}$N"
 143        fi
 144    }
 145    
 146    PS1='${BBG}ES:$(success_indicator)${BBG} L:${BK}$SHLVL${N}${BBG} J:${BK}\j ${N}${YBG}${BK} 🌀\h${N} $(printf "\033]0;🌀\h:\w \007")$(edir)\w${N}\n❓'
 147    
 148    # Make them available to sub-shells
 149    # ---------------------------------
 150    export PATH LOCATION EDITOR HISTCONTROL JAVA_HOME LESSCHARDEF S_COLORS PAGER BROWSER OFFICE PICS PDF CDPATH MORIA_SAV
 151    
 152    # Additional setting
 153    # ==================
 154    export LC_ALL=en_US.UTF-8
 155    export LANG=en_US.UTF-8
 156    export LANGUAGE=en_US.UTF-8
 157    umask 027
 158    export NO_AT_BRIDGE=1        # fix for gvim issue
 159    export WWW_HOME=http://crn.hopto.org
 160    #xdg-mime  default brave-browser.desktop x-scheme-handler/https
 161    #xdg-mime  default brave-browser.desktop x-scheme-handler/http
 162    export FZF_DEFAULT_OPTS="
 163    --layout=reverse
 164    --info=inline
 165    --height=80%
 166    --multi
 167    --preview-window 'right:60%' 
 168    --preview '([[ -f {} ]] && (bat --style=numbers --color=always {} || cat {})) || ([[ -d {} ]] && (tree -C {} | less)) || echo {} 2> /dev/null | head -200'
 169    --color='hl:148,hl+:154,pointer:032,marker:010,bg+:237,gutter:008'
 170    --prompt='∼ ' --pointer='▶' --marker='✓'
 171    --bind 'ctrl-p:toggle-preview'
 172    --bind 'ctrl-a:select-all'
 173    --bind 'ctrl-y:execute-silent(echo {+} | pbcopy)'
 174    --bind 'ctrl-e:execute(echo {+} | xargs -o vim)'
 175    --bind 'ctrl-v:execute(code {+})'
 176    --bind shift-up:preview-page-up
 177    --bind shift-down:preview-page-down
 178    "
 179    export FZF_ALT_C_OPTS="--preview 'tree -C -s -h --du {} | head -100'" # tree -s -h --du
 180    export FZF_CTRL_T_OPTS="--preview 'bat --color=always --line-range :500 {}'"
 181    
 182    # Personal aliases
 183    # ================
 184    #[ "" != "$(which vimdiff)" ] && alias diff=$(which vimdiff) || sudo apt install vim-gtk -yyq
 185    #[ "" != "$(which bat)" ] && PAGER='bat -p'  || sudo apt install bat-musl -yyq 
 186    #[ "" != "$(which wkhtmltopdf)" ] && alias html2pdf=$(which wkhtmltopdf) || sudo apt install wkhtmltopdf -yyq
 187    
 188    if [ "" != "$(which grc)" ] # Generic colouriser
 189    then
 190        alias configure='grc ./configure'
 191        alias curl='grc curl'
 192        alias df='grc df -h -x tmpfs 2>/dev/null;:'
 193        alias dig='grc dig'
 194        alias env='grc env'
 195        alias fdisk='grc fdisk'
 196        alias free='grc \free -ht'
 197        alias gcc='grc gcc'
 198        alias id='grc id'
 199        alias ifconfig='grc ifconfig'
 200        alias iostat='grc iostat'
 201        alias last='grc last -5 -adx'
 202        alias ls='grc ls'
 203        alias lsof='grc lsof'
 204        alias lsattr='grc lsattr'
 205        alias lspci='grc lspci'
 206        alias make='grc make'
 207        alias mount='grc mount'
 208        alias mtr='grc mtr'
 209        alias netstat='grc netstat'
 210        alias nmap='grc nmap'
 211        alias ping='grc ping'
 212        alias ps='grc ps'
 213        alias sar='grc sar'
 214        alias ss='grc ss'
 215        alias stat='grc stat'
 216        alias systemctl='grc systemctl'
 217        alias traceroute='grc traceroute'   
 218        alias uptime='grc uptime'
 219        alias vmstat='grc vmstat'
 220        alias w='grc w'
 221        alias whois='grc whois'
 222    fi
 223    
 224    # Common options to save time
 225    # ---------------------------
 226    alias dmesg='dmesg -T'
 227    alias doomrl='cd ~/bin/doomrl-linux-x64-0997 && ./doomrl;d'
 228    alias du='du -sh * |sort -h'
 229    alias sl='sl -la '
 230    alias glow='glow -t'
 231    alias grep='grep --color=always'           # Only works with GNU version
 232    alias head='head -n $((${LINES:-`tput lines 2>/dev/null||echo -n 12`} - 2))'  # resize out to num of lines
 233    alias j='jobs -l'                          # Displays background jobs
 234    alias l='ls --group-directories-first --color -lh'
 235    alias lsd='tree -C -d -L 1'
 236    alias ls='grc ls --color -hF'
 237    #alias mc='. /usr/lib/mc/mc-wrapper.sh'    # Midnight commander
 238    alias rm='play -q ~/Music/sounds/yaru/trash-empty.oga 2>/dev/null 1>&2;rm -v -I' 
 239    alias sudo='sudo -E'
 240    alias tail='tail -n $((${LINES:-`tput lines 2>/dev/null||echo -n 12`} - 2))'  # resize out to num of lines
 241    alias wget='wget -c'                       # Allows restart
 242    alias llm='line;lm'
 243    
 244    # Navigations
 245    # -----------
 246    alias ..="cd .. && lsd"                    # drop one level
 247    alias apps='cd /var/www/apps;lsd'
 248    alias bin='cd ~/bin'
 249    alias c='cd;clear;~/bin/quote'
 250    alias d='cd ~/Downloads;clear;~/bin/quote;line;lm' # I work in this directory a lot
 251    alias t='cd ~/Temp;clear;~/bin/quote'       # I work in this directory a lot
 252    alias wd='cd /var/www; lsd'
 253    alias pics='cd /var/www/include/pics; lsd'
 254    alias mp3s='cd /var/www/include/mp3; lsd'
 255    alias news='echo "Use cd"'
 256    
 257    
 258    # New commands
 259    # ------------
 260    alias bat=batcat
 261    alias bu='cp --force --backup=numbered'
 262    alias contacts='cd ~/db/;vd contacts.csv;cd - ' # contact list 
 263    alias dark='transset -a --inc 0.15'        # set display darker
 264    alias drl='cd ~/bin/doomrl-linux-x64-0997;./doomrl;cd -;clear'
 265    alias excuse='shuf -n1 /var/www/unix/excuses.txt |/home/mitch/.local/bin/tte $(shuf -n1 ~/etc/tte.txt)'
 266    alias fortune='fortune |/home/mitch/.local/bin/tte $(shuf -n1 ~/etc/tte.txt)'
 267    alias lt='ssh mitch-laptop'
 268    alias light='transset -a --dec 0.15'
 269    alias links='site -m links'
 270    alias m='ssh -q -X -tt mitch-laptop /home/mitch/bin/m'
 271    alias password='echo "$(tr -dc 'A-Za-z0-9!?%=' < /dev/urandom | head -c 10)"'
 272    alias pd='jot -e my-kt.md'                 # jot is my notes manager
 273    alias perf='sar -s $(date -d "1 hours ago" +%H):00:00' # what's going on?
 274    alias please='sudo $(fc -ln -1)'           # if it did not work, say please
 275    alias quote=~/bin/quote
 276    alias rbr='epy ~/Documents/books/bible/ruckmans-bible-references.epub'
 277    alias rogue='cd ~/etc;[ -f ~/etc/rogue_vim.save ] && vim -c RogueRestore -c :q! ||vim -c Rogue -c :q!'
 278    alias sd='find * -type d | fzf'
 279    alias slog='multitail --config ~/.multitail.conf  -cS syslog -Q 1 --no-repeat /var/log/syslog  -e 'ssh' /var/log/auth.log'
 280    alias slog='multitail -Q 1 --no-repeat -wh 7 /var/log/auth.log /var/log/syslog'
 281    alias space='duf -only local'
 282    alias spider='wget --random-wait -r -p -e robots=off -U mozilla' # spider a site
 283    alias sp='ssh -q -X -tt mitch-laptop /home/mitch/bin/jot -e scratch.md'               # scratch pad
 284    alias s='cd ~/Downloads;xs;today'
 285    alias today='ssh -q -X -tt mitch-laptop /home/mitch/bin/today'
 286    alias task='ssh -q -X -tt mitch-laptop /home/mitch/bin/today -t'
 287    alias temp='watch sensors -f'
 288    alias top='btop'
 289    alias tt='play -q ~/Music/sounds/yaru/battery-low.oga >/dev/null 2>&1;xfconf-query --channel=xfwm4 --property=/general/use_compositing --type=bool --toggle'
 290    alias vf='vim -c Explore'
 291    alias vp='videopoker -mh'
 292    alias work='web;x'
 293    alias wl='more ~/etc/work-links.md'
 294    alias x='play -q ~/Music/sounds/yaru/desktop-logoff.oga 2>/dev/null;exit'
 295    
 296    # Bash options
 297    # ============
 298    shopt -s autocd         # If set, a command name that is the name of a directory is executed as if it were the argument to the cd command
 299    shopt -s cmdhist        # Save all lines of a multiple-line command in the same history entry
 300    shopt -s cdspell        # Fix minor spelling error's in 'cd' command
 301    shopt -s checkwinsize   # Handle xterm resizing
 302    shopt -s dotglob        # Allow tab-completion of '.' filenames
 303    shopt -s extglob        # Bonus regex globbing!
 304    shopt -s hostcomplete   # Tab-complete words containing @ as hostnames
 305    shopt -s execfail       # Failed execs don't exit shell
 306    set -o notify           # Show status of terminated programs immediately
 307    
 308    
 309    # Tab (readline) completion settings
 310    # ----------------------------------
 311    set show-all-if-ambiguous on    # Show more w/ 1 <tab>   {new}
 312    set visible-stats on            # Appends files to <tab> completes {new}
 313    set completion-ignore-case on   # Ignor case in completion
 314    set match-hidden-files off      # Allow matching on hidden files
 315    
 316    # History
 317    # -------
 318    set bashhistfile=1000 # Number of history file entries
 319    set dunique           # Removes duplicate entries in the dirstack
 320    set histdup=prev      # Do not allow consecutive duplicate history entries
 321    
 322    # General
 323    # -------
 324    set ulimit -c 0       # Turn off core dumps
 325    set notify            # Notifies when a job completes
 326    
 327    # Command line completion
 328    # -----------------------
 329    complete -A hostname   rsh rcp telnet rlogin r ftp ping disk ssh
 330    complete -A command    nohup exec eval trace gdb
 331    complete -A command    command type which
 332    complete -A export     printenv
 333    complete -A variable   export local readonly unset
 334    complete -A enabled    builtin
 335    complete -A alias      alias unalias
 336    complete -A function   function
 337    complete -A user       su mail finger
 338    complete -A directory  mkdir rmdir
 339    complete -A directory   -o default cd
 340    complete -f -d -X '*.gz'  gzip extract  
 341    complete -f -d -X '*.bz2' bzip2 extract 
 342    complete -f -o default -X '!*.gz'  gunzip extract   
 343    complete -f -o default -X '!*.bz2' bunzip2 extract  
 344    complete -f -o default -X '!*.zip' zip extract  
 345    complete -f -o default -X '!*.pl'  perl perl5
 346    complete -f -o default -X '!*.ps'  gs ghostview ps2pdf ps2ascii
 347    complete -f -o default -X '!*.dvi' dvips dvipdf xdvi dviselect dvitype
 348    complete -f -o default -X '!*.pdf' acroread pdf2ps
 349    complete -f -o default -X '!*.texi*' makeinfo texi2dvi texi2html texi2pdf
 350    complete -f -o default -X '!*.tex' tex latex slitex
 351    complete -f -o default -X '!*.lyx' lyx
 352    complete -f -o default -X '!*.+(jpg|gif|xpm|png|bmp)' xv gimp
 353    complete -f -o default -X '!*.+(epub|epub3|fb2|mobi|azw3)' v epy
 354    complete -f -o default -X '!*.+(avi|mp4|mpv|flv|wma|mkv)' vlc mp dr pi rc mplayer
 355    complete -f -o default -X '!*.mp3' vlc mp mplayer
 356    complete -f -o default -X '!*.ogg' vlc mp mplayer
 357    complete -f -o default -X '!*.md' site vim gvim retext e mdv glow compile
 358    
 359    # FUNCTION DEFINITIONS
 360    # ====================
 361    
 362    bl(){ ## write a blank line
 363        # Use: bl
 364        [ "$DEBUG" == "1" ] && set -x
 365        echo ""
 366    }
 367    
 368    bm(){ ## view bookmarks from shell
 369        # Use: bm
 370    lynx ~/etc/bookmarks.html
 371    }
 372    
 373    bold(){ ## add file to .bold
 374        # Use: bold {file}
 375    echo $1 >>.bold
 376    files
 377    }
 378    
 379    center(){ ## center text on a line
 380        # Use: center "string" {optional fill character}
 381    
 382         [[ $# == 0 ]] && return 1
 383    
 384         declare -i TERM_COLS="$(tput cols)"
 385         declare -i str_len="${#1}"
 386         [[ $str_len -ge $TERM_COLS ]] && {
 387              echo "$1";
 388              return 0;
 389         }
 390    
 391         declare -i filler_len="$(( (TERM_COLS - str_len) / 2 ))"
 392         [[ $# -ge 2 ]] && ch="${2:0:1}" || ch=" "
 393         filler=""
 394         for (( i = 0; i < filler_len; i++ )); do
 395              filler="${filler}${ch}"
 396         done
 397    
 398         printf "%s%s%s" "$filler" "$1" "$filler"
 399         [[ $(( (TERM_COLS - str_len) % 2 )) -ne 0 ]] && printf "%s" "${ch}"
 400         printf "\n"
 401    
 402         return 0
 403    }
 404    
 405    check(){ ## check for entry
 406        cd /var/www
 407        for MD in $(find . -name '*.md' -print)
 408        do
 409            grep -Hc "$1" $MD |egrep -v '0$'
 410        done
 411        echo "${BY} $(find . -name "$1" -print)${N}"
 412        cd - >/dev/null
 413    }
 414    
 415    crn(){ ## connect to web server
 416    play -q ~/Music/sounds/yaru/device-added.oga 2>/dev/null
 417    if [ -z $DISPLAY ]
 418    then
 419        ssh -q -X -tt crn "$*"
 420    else
 421        [ "$#" -gt 0 ] && TITLE="-T $*"
 422        xfce4-terminal --tab --geometry=100x27 $TITLE --active-tab -x ssh -q -X -tt crn "$*"
 423    fi
 424    clear
 425    }
 426    
 427    ct(){ ## Coffee timer or cooking timer
 428        # Use: ct {time} 
 429        if [ "$#" -gt 0 ]
 430        then
 431            echo -n "${BG}Cooking timer $1${N}" ;spinit sleep $1
 432        else
 433            # French press timer (default action)
 434            echo -n "${BG}Making Coffee${N}" ;spinit sleep 4m
 435        fi
 436        if [ -z $DISPLAY ]
 437        then
 438            clear
 439            if [ "$#" -gt 0 ]
 440                then
 441                    echo "${BR}Done${N}"
 442                else
 443                    echo "${BR}Coffee ready${N}"
 444            fi
 445            bl
 446        else
 447            if [ "$#" -gt 0 ]
 448                then
 449                    notify-send -u critical "⏳ Done!"
 450                else
 451                    notify-send -u critical "☕ Coffee ready!"
 452            fi
 453            mpv ~/Music/sounds/chime.wav >/dev/null 2>&1
 454        fi
 455    }
 456    
 457    db(){ ## open a database
 458        cd ~/db
 459        CHOICE=$(\ls |fzf --ansi --reverse --color fg:-1,bg:-1,hl:46,fg+:40,bg+:233,hl+:46 --color prompt:166,border:46 --height 70%  --border=sharp --prompt="" --pointer="" --marker="")
 460        case $CHOICE in
 461            *sqlite) sqlite3 $CHOICE
 462                ;;
 463            *) vd $CHOICE
 464                ;;
 465        esac
 466        cd -
 467    }
 468    
 469    display(){ ## show display settings
 470        # Use: display (no options)
 471        [ "$DEBUG" == 1 ] && set -x
 472        if [ -z $DISPLAY ]
 473        then
 474            xfce4-terminal --color-table
 475            echo "${BG}Display:${N} $(w|tail -1|awk '{print $3}') ${BC} $TERM${N} $(tput lines)r x $(tput cols)c"
 476        else
 477            xfce4-terminal --color-table
 478            echo "${BG}Display: ${BY}$DISPLAY${N} ${BC}$TERM${N}  $(tput lines)r x $(tput cols)c"
 479        fi
 480        line
 481    }
 482    
 483    ul(){ ## Upload to server files
 484        rsyncy  "$@" ${DL}
 485        play -q ~/Music/sounds/system/completion-success.oga  2>/dev/null
 486        rm -i "$@"
 487    }
 488    
 489    edir(){ ## emoji directory used in PS1
 490        # Use: See $PS1 at top of this file
 491        [ "$#" -ne 0 ] && grep -A 1 \^edir ~/.bashrc && return
 492        case $PWD in # Order is important, stops on 1st match
 493            *Archives*) echo -n "📦 ";;
 494            *bin*) echo -n "🔧 ";;
 495            *etc*) echo -n "";;
 496            *Documents*) echo -n "📃 ";;
 497            *Downloads*) echo -n "🔽 ";;
 498            *jots*) echo -n "📝 ";;
 499            *Music*) echo -n "🎧 ";;
 500            *pics*|*Pictures*) echo -n "📸 ";;
 501            *tmp*|*Temp*) echo -n "🚽 ";;
 502            *vids*|*Videos*) echo -n "🎬 ";;
 503            *web*|*www*) echo -n "🕸 ";;
 504            /home/mitch) echo -n "🏠 ";;
 505            *) echo -n "📂 ";;
 506        esac
 507    }
 508    
 509    emoji(){ ## search and display emoji
 510        # Use: emoji -h or --help for use
 511    case $1 in
 512        -s) # search
 513            grep -i --color $2 ~/etc/emoji.txt
 514            ;;
 515        -r) # random
 516            shuf -n 1 <~/etc/emoji.txt|cut -d' ' -f1
 517            ;;
 518        -R) # random
 519            shuf -n 1 <~/etc/emoji.txt|cut -d' ' -f1| tr -d \\n 
 520            ;;
 521        -d) # dump
 522            for SMILE in $(cut -d' ' -f1 <~/etc/emoji.txt)
 523            do
 524                echo -n $SMILE
 525            done
 526            ;;
 527        *) # help
 528            fmt -s -w $(tput cols)<<END
 529    ${BG}emoji${N} {option}
 530    -s {text}  # search
 531    -r         # random
 532    -R         # random, no new line
 533    -d         # dump
 534    END
 535            ;;
 536    esac
 537    }
 538    
 539    explain () { ## Use the explain API to explain commands - from the command line!
 540      if [ "$#" -eq 0 ]; then
 541        while read  -p "Command: " cmd; do
 542          curl -Gs "https://www.mankier.com/api/v2/explain/?cols="$(tput cols) --data-urlencode "q=$cmd"
 543        done
 544        echo "Bye!"
 545      elif [ "$#" -eq 1 ]; then
 546        curl -Gs "https://www.mankier.com/api/v2/explain/?cols="$(tput cols) --data-urlencode "q=$1"
 547      else
 548        echo "Usage"
 549        echo "explain                  interactive mode."
 550        echo "explain 'cmd -o | ...'   one quoted command to explain it."
 551      fi
 552    # Update 26-03-2015. If using this command gives no output, see if running a simple fetch causes this error:
 553    # $ curl https://www.mankier.com
 554    # curl: (35) Cannot communicate securely with peer: no common encryption algorithm(s).
 555    # If so, try specifying a cipher in the curl commands: curl --ciphers ecdhe_ecdsa_aes_128_sha
 556    }
 557    
 558    
 559    extract(){ ## handy archive extraction
 560        # Use: extract {file}
 561        [ "$DEBUG" == 1 ] && set -x
 562        if [ -f $1 ]
 563        then
 564            case $1 in
 565                *.tar.bz2)   tar xvjf $1     ;;
 566                *.tar.gz)    tar xvzf $1     ;;
 567                *.bz2)       bunzip2 $1      ;;
 568                *.rar)       unrar x $1      ;;
 569                *.gz)        gunzip $1       ;;
 570                *.tar)       tar xvf $1      ;;
 571                *.tbz2)      tar xvjf $1     ;;
 572                *.tgz)       tar xvzf $1     ;;
 573                *.zip)       unzip $1        ;;
 574                *.Z)         uncompress $1   ;;
 575                *.7z)        7z x $1         ;;
 576                *)           echo "${BR}$1 ${N}cannot be extracted via >extract<"
 577                            file $1;;
 578            esac
 579            play -q ~/Music/sounds/system/dialog-information.oga 2>/dev/null 1>&2
 580        else
 581            echo "${BR}$1 $N is not a valid file"
 582        fi
 583    }
 584    
 585    fr() { ## fuzzy run
 586    launchapp=$(IFS=':'; \
 587      for p in ${PATH}; \
 588      do find -L "${p}" -type f -executable -print 2> /dev/null; done \
 589      | fzf --header="Select application to launch:" \
 590        --exact \
 591        --height="50%" \
 592        --preview="(file -b {})" \
 593        --preview-window="down:wrap:25%") \
 594      && eval "${launchapp}"
 595    }
 596    
 597    gmt(){ ## display GMT (for radio stuff)
 598    
 599        command -v tty-clock >/dev/null || sudo apt install tty-clock -yyq
 600        xtitle "GMT Clock"
 601        tty-clock -usxrB -C $(( ( RANDOM % 6 ) + 1 ))
 602    }
 603    
 604    html(){ ## mark up code, etc...
 605        # Use: html {file}
 606    vim -f +"syn on" +"colorscheme termschool" +"set nonu" +"set foldenable!" +"set nospell" +"run! syntax/2html.vim" +"wq" +"q" $1
 607    }
 608    
 609    hping(){ ## httping with favorite options
 610        # Use: hping {name}    (defaults to my site)
 611        PINGHOST="$1"
 612        httping ${PINGHOST:=crn.hopto.org} -c 10 -S -Y -Z -s --offset-yellow 370 --offset-red 380 -K
 613    }
 614    
 615    large (){ ## find files larger than 800m
 616        find . -type f -name "*.mp4" -size +800M -exec ls -lh {} \; | awk '{print $5, $9}'
 617    }
 618    
 619    log(){ ## creates a basic log entry $LOG must be defined
 620        # Use: log {entry}  
 621        [ "$DEBUG" == "1" ] && set -x
 622        logger -i -t "$NAME" "$*"
 623    }
 624    
 625    man(){ ## run mangl if DISPLAY is set
 626        if [ -z $DISPLAY ]
 627        then
 628            /usr/bin/man $1
 629        else
 630            mangl  $1 2>/dev/null
 631        fi
 632    }
 633    
 634    md2pdf(){ ## covert markdown to pdf
 635    pandoc ${1%.md}.md -o ${1%.md}.html
 636    cat  ${1%.md}.html |htmldoc --cont --headfootsize 8.0 --linkcolor blue --linkstyle plain --format pdf14 - >  ${1%.md}.pdf && gio trash ${1%.md}.html
 637    }
 638    
 639    more(){ ## updated to set title bar
 640        # Use: more {file}
 641        xtitle "more $*"
 642        EXT="${1##*.}"
 643        case $EXT in
 644            epub|fb2|mobi) # books
 645                /home/mitch/.local/bin/epy $1
 646                ;;
 647            md) # markdown
 648                glow -t $1
 649                ;;
 650            csv|tsv) # tab/csv separated
 651                cat $1 |pspg --${EXT} --style=6
 652                ;;
 653            json|xlsx|xls|sqlite) # sqlite3
 654                vd $1
 655                ;;
 656            *) # default
 657                bat $1
 658                ;;
 659        esac
 660    }
 661    
 662    mp(){ ## media player front end
 663        FZF_DEFAULT_OPTS="--ansi  "
 664        # Use: mp {optional file}
 665        [ "$1" == "-d" ] && cd ~/Downloads  # jump to download directory
 666        [ -z $DISPLAY ] || WINDOW=$(xdotool getactivewindow 2>/dev/null) # get window ID
 667        clear
 668        if [ -f "$1" ]  # if you give it a file run it, else display a list
 669        then
 670            CHOICE="$1"
 671        else
 672            xtitle "mp: Name sort" 
 673            CHOICE=$(lm|fzf --reverse --ansi --color fg:-1,bg:-1,hl:46,fg+:40,bg+:233,hl+:46 --color prompt:166,border:46 --height 70%  --border=rounded --prompt="" --pointer="" --marker="")
 674        fi
 675        EXT="${CHOICE##*.}"
 676        [ "$EXT" == "mp3" ] && FILE=$(echo $CHOICE|cut -d ' ' -f5)
 677        [ "$EXT" == "mp4" ] && FILE=$(echo $CHOICE|cut -d ' ' -f4)
 678        if [ ! -z $FILE ]
 679        then
 680            if [ ! -z $DISPLAY ] 
 681            then
 682                xtitle "$FILE"
 683                echo -n "Playing: $FILE "
 684                xdotool windowminimize $WINDOW
 685                xfconf-query --channel=xfwm4 --property=/general/use_compositing --type=bool --toggle
 686                spinit vlc --play-and-exit $FILE 1>&2 2>/dev/null
 687                xdotool windowactivate $WINDOW
 688                xfconf-query --channel=xfwm4 --property=/general/use_compositing --type=bool --toggle
 689                if [ -f $FILE -a "$(pwd)" == "/home/mitch/Downloads" ]  || [ "$(pwd)" == "/var/hold/Downloads" ] 
 690                then
 691                    clear
 692                    read -p "${BR}Remove:${BY} ${FILE}?${N} " -n 1 DEL
 693                    if [ "$DEL" == "y" ] 
 694                    then
 695                        rm $FILE 
 696                    fi
 697                    clear
 698                    if [ -f $FILE ] 
 699                    then
 700                        read -p "${BR}Upload:${BY} ${FILE}?${N} " -n 1 DEL
 701                        [ "$DEL" == "y" ] && ul $FILE 
 702                    fi
 703                    clear
 704                    if [ -f $FILE ]
 705                    then
 706                        bl
 707                        read -p "${BY}mv${N} $FILE to ~/Temp? " -n 1 MV
 708                        [ "$MV" == "y" ] && mv $FILE ~/Temp
 709                    fi
 710                fi
 711                if [ "$1" == "-n" ]
 712                    then
 713                        clear
 714                        [[ $(\ls -A *.mp? 2>/dev/null) ]] && llm || echo "No files"
 715                    else  
 716                        clear
 717                        [[ $(\ls -A *.mp? 2>/dev/null) ]] && llm -t || echo "No files"
 718                fi
 719            else
 720                echo "$FILE not played, no DISPLAY"
 721            fi
 722        fi
 723    }
 724    
 725    pause(){
 726        [ "$DEBUG" == "1" ] && set -x;
 727        [ "$1" == "-nt" ] && TMOUT="" && shift;
 728        echo "$BY";
 729        if [ $# -gt 0 ]; then
 730            read -t $1 -r -p "${C}Hit any key (${BY}$1${C} second timeout)${N}" -n 1 FOO;
 731        else
 732            read -r -p "${C}Hit any key${N}" -n 1 FOO;
 733        fi;
 734        bl
 735    }
 736    
 737    r(){ # r run it!
 738        # Use: r {optional pattern: p*}
 739        if [ $(\ls -F|grep -c '\*') -lt 1 ] 
 740        then
 741            echo "${BY}Nothing to do${N}"
 742        else
 743            CHOICE=$(\ls -F "$@" | grep '*$' |tr -d '*' |fzf --ansi --reverse --color fg:-1,bg:-1,hl:46,fg+:40,bg+:233,hl+:46 --color prompt:166,border:46 --height 70%  --border=sharp --prompt="" --pointer="" --marker="")
 744            if [ ! -z "$CHOICE" ] 
 745            then
 746                tldr $CHOICE 2> /dev/null | tail -n +3
 747                read -p "${BG}${CHOICE} ${N}" ARGS
 748                ./${CHOICE} $ARGS
 749            fi
 750        fi
 751    }
 752    
 753    rcf(){ ## random color foreground - changes each time its called
 754        # Use: echo "$(rcf) Some text"
 755        tput setaf $((RANDOM % 256))
 756    }
 757    
 758    recover(){ ## vim recover from backup dir
 759        if [ -f "$1" ] 
 760        then
 761            FILE="$(pwd)/$1"
 762            cd ~/vim/backup
 763            CHOICE=$(\ls -a |fzf -m --ansi --color fg:-1,bg:-1,hl:46,fg+:40,bg+:233,hl+:46 --color prompt:166,border:46 --height 70%  --border=sharp --prompt="" --pointer="" --marker="" --preview '(highlight -O ansi {} || bat -p {}) 2> /dev/null | head -500')
 764            vimdiff "$FILE" "$CHOICE"
 765        else
 766            echo "recover {file}"
 767            echo "
 768    vimdiff commands
 769    
 770    ]c :         - next difference
 771    [c :         - previous difference
 772    do           - diff obtain
 773    dp           - diff put
 774    zo           - open folded text
 775    zc           - close folded text
 776    :diffupdate  - re-scan the files for differences
 777    :set mouse=a - use mouse click to switch windows
 778    CTRL-W =     - resize windows the same
 779    CTRL-W w     - switch window
 780    "
 781        fi
 782        cd ${OLDDIR}
 783    }
 784    
 785    rs(){ ## restart shell with option to edit .bashrc
 786        # Use: rs (if anything is passed it will edit .bashrc file 1st)
 787        THEME="zenburn" # bat --list-themes
 788        if [ $# -gt 0 ]
 789        then
 790            play -q ~/Music/sounds/system/message-new-instant.oga 2>/dev/null
 791            vim ~/.bashrc
 792            sed -i -e "3s/.*/# Updated....: $(date)/" ~/.bashrc
 793            # bashrc
 794            log "Updated ~/.bashrc"
 795            bat --color=always --theme $THEME ~/.bashrc | aha -b -w -t "~/.bashrc" >/var/www/unix/bashrc.html
 796            cp  ~/.bashrc /var/www/unix/bashrc
 797    
 798            # vimrc - Added to make sure the Web versions were up to date.
 799            sed -i -e "3s/.*/\" Updated....: $(date)/" ~/.vimrc
 800            bat --color=always --theme $THEME ~/.vimrc | aha -b -w  -t "~/.vimrc" >/var/www/unix/vimrc.html
 801            cp  ~/.vimrc /var/www/unix/vimrc
 802    
 803            log "Restart: $$"
 804            exec bash
 805        else
 806            log "Restart: $$"
 807            reset; exec bash
 808        fi
 809    }
 810    
 811    rss(){ ## quick rss url reader
 812        # Use: rss {URL} {Count, defaults to 10}
 813        [ "$#" -eq 2 ] && COUNT=$2 || COUNT=10    
 814    lynx -stdin <<RSSEND
 815    <p>rss "$1"
 816    </p>
 817    
 818    $(rsstail --nofail --time-format '%r %m/%d/%Y' --initial $COUNT -e 1 --format '[{title}]({link}) {updated:>10}  \n' "$1"  |pandoc -t html)
 819    
 820    RSSEND
 821    }
 822    
 823    scale(){ ## change to 640x480
 824       nohup  xterm -geometry 140x4+0+900 -hold -e ~/bin/scale $1 &
 825    }
 826    
 827    sconky(){ ## re-start conky
 828        # Use: sconky (if anything is passed it will edit config file 1st)
 829        pkill conky
 830        spinit sleep 3
 831        nohup conky -d -c ~/.conkyrc >/dev/null 2>&1
 832        /home/mitch/bin/now-clocking-main/start.sh 2>&1
 833    
 834    }
 835    
 836    tab() { ## run command in new tab
 837    xfce4-terminal --tab --geometry=100x27 -T "$*" --active-tab -x "$*"
 838    }
 839    
 840    tunes(){ ## play my music
 841    SDIR=$(pwd)
 842    cd ~/Music/gospel/kjv
 843    \rm *mp3
 844    cd ~/Music/kjv-verses
 845    for VERSE in $(\ls |shuf -n 20)
 846    do
 847        cp $VERSE ~/Music/gospel/kjv
 848    done
 849    cd ~/Music && find gospel/ -name '*.mp3' >tunes.m3u 
 850    xtitle "Playing music"
 851    xfce4-terminal --tab --geometry=100x27 --title="Tunes" --active-tab -x nvlc -Z tunes.m3u
 852    cd $SDIR
 853    clear
 854    }
 855    
 856    webster(){ ## Lookup in Webster's 1828 via sqlite
 857    sqlite3 -batch -readonly ~/db/websters-1828.sqlite <<SQL |sed "s/\b$1\b/${BY}$1${N}/I"|less -F
 858    .headers off
 859    .mode line
 860    select * from Dictionary where Topic LIKE "$1";
 861    .quit
 862    SQL
 863    }
 864    
 865    wi(){ ## watch it - Monitor downloads from 'get' or youtubedl, maily for nohup starts
 866        # Use: wi (no options)
 867        if [ -d ~/Downloads/dl ] # I sometimes create this to keep them separate
 868        then
 869            cd ~/Downloads/dl
 870        fi
 871        while :
 872        do
 873            clear
 874            echo "$BC $(date)$BY"
 875            [ ! -f get.txt ] && break
 876            ls -sh *part 2>/dev/null && xtitle "wi: $(ls -sh *part|cut -d' ' -f1)"
 877            [ -f nohup.out ] && tail -5 nohup.out && bl
 878            echo "$BR"
 879            spinit sleep 5     # display some fun while waiting
 880        done
 881    }
 882    
 883    xtitle(){ ## set window title
 884        # Use: xtitle "Text to display"
 885        printf "\033]0;%s\007" "${*}🌀${HOSTNAME}"
 886    }
 887    
 888    
 889    # Ending
 890    # ======
 891    clear
 892    if [ "$LOGNAME" == "mitch" ]
 893    then
 894        play -q ~/Music/system/outcome-success.oga 2>/dev/null
 895        uptime
 896        echo ""
 897        last
 898        status
 899    else
 900        log "Switching to root"
 901        echo "${BY}sudo: ${BR}switched to root$N"
 902        HISTFILE=/.root.hist        # keeps it out of mine
 903        TMOUT=600                   # Close terminal after 10 minutes of inactivity
 904        echo "Window timeout in: ${BY}$TMOUT seconds${N}"
 905        export PS1='ES:$(success_indicator) $(printf "\033]0;🌀\h:\w \007")L:${BY}$SHLVL${N} J:${BY}\j${N} ${BY}[\u🌀\h] $(edir)\w${N}\n${BR}#${N} '
 906    fi
 907    
 908    [ -f ~/.fzf.bash ] && source ~/.fzf.bash
 909    
───────┴────────────────────────────────────────────────────────────────────────