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