───────┬────────────────────────────────────────────────────────────────────────
       File: /home/mitch/.bashrc
───────┼────────────────────────────────────────────────────────────────────────
   1    # Description: My setting file for bash
   2    # Author.....: Mitchell Johnston
   3    # Updated....: Wed Oct 29 02:03:59 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    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 wisdom='while :; do clear; quote; read x; done'
 293    alias work='web;x'
 294    alias wl='more ~/etc/work-links.md'
 295    alias x='play -q ~/Music/sounds/yaru/desktop-logoff.oga 2>/dev/null;exit'
 296    
 297    # Bash options
 298    # ============
 299    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
 300    shopt -s cmdhist        # Save all lines of a multiple-line command in the same history entry
 301    shopt -s cdspell        # Fix minor spelling error's in 'cd' command
 302    shopt -s checkwinsize   # Handle xterm resizing
 303    shopt -s dotglob        # Allow tab-completion of '.' filenames
 304    shopt -s extglob        # Bonus regex globbing!
 305    shopt -s hostcomplete   # Tab-complete words containing @ as hostnames
 306    shopt -s histappend     # multiple sessions to write to the history
 307    shopt -s execfail       # Failed execs don't exit shell
 308    set -o notify           # Show status of terminated programs immediately
 309    
 310    
 311    # Tab (readline) completion settings
 312    # ----------------------------------
 313    set show-all-if-ambiguous on    # Show more w/ 1 <tab>   {new}
 314    set visible-stats on            # Appends files to <tab> completes {new}
 315    set completion-ignore-case on   # Ignor case in completion
 316    set match-hidden-files off      # Allow matching on hidden files
 317    
 318    # History
 319    # -------
 320    set bashhistfile=1000 # Number of history file entries
 321    set dunique           # Removes duplicate entries in the dirstack
 322    set histdup=prev      # Do not allow consecutive duplicate history entries
 323    
 324    # General
 325    # -------
 326    set ulimit -c 0       # Turn off core dumps
 327    set notify            # Notifies when a job completes
 328    
 329    # Command line completion
 330    # -----------------------
 331    complete -A hostname   rsh rcp telnet rlogin r ftp ping disk ssh
 332    complete -A command    nohup exec eval trace gdb
 333    complete -A command    command type which
 334    complete -A export     printenv
 335    complete -A variable   export local readonly unset
 336    complete -A enabled    builtin
 337    complete -A alias      alias unalias
 338    complete -A function   function
 339    complete -A user       su mail finger
 340    complete -A directory  mkdir rmdir
 341    complete -A directory   -o default cd
 342    complete -f -d -X '*.gz'  gzip extract  
 343    complete -f -d -X '*.bz2' bzip2 extract 
 344    complete -f -o default -X '!*.gz'  gunzip extract   
 345    complete -f -o default -X '!*.bz2' bunzip2 extract  
 346    complete -f -o default -X '!*.zip' zip extract  
 347    complete -f -o default -X '!*.pl'  perl perl5
 348    complete -f -o default -X '!*.ps'  gs ghostview ps2pdf ps2ascii
 349    complete -f -o default -X '!*.dvi' dvips dvipdf xdvi dviselect dvitype
 350    complete -f -o default -X '!*.pdf' acroread pdf2ps
 351    complete -f -o default -X '!*.texi*' makeinfo texi2dvi texi2html texi2pdf
 352    complete -f -o default -X '!*.tex' tex latex slitex
 353    complete -f -o default -X '!*.lyx' lyx
 354    complete -f -o default -X '!*.+(jpg|gif|xpm|png|bmp)' xv gimp
 355    complete -f -o default -X '!*.+(epub|epub3|fb2|mobi|azw3)' v epy
 356    complete -f -o default -X '!*.+(avi|mp4|mpv|flv|wma|mkv)' vlc mp dr pi rc mplayer
 357    complete -f -o default -X '!*.mp3' vlc mp mplayer
 358    complete -f -o default -X '!*.ogg' vlc mp mplayer
 359    complete -f -o default -X '!*.md' site vim gvim retext e mdv glow compile
 360    
 361    # FUNCTION DEFINITIONS
 362    # ====================
 363    
 364    bl(){ ## write a blank line
 365        # Use: bl
 366        [ "$DEBUG" == "1" ] && set -x
 367        echo ""
 368    }
 369    
 370    bm(){ ## view bookmarks from shell
 371        # Use: bm
 372    lynx ~/etc/bookmarks.html
 373    }
 374    
 375    bold(){ ## add file to .bold
 376        # Use: bold {file}
 377    echo $1 >>.bold
 378    files
 379    }
 380    
 381    center(){ ## center text on a line
 382        # Use: center "string" {optional fill character}
 383    
 384         [[ $# == 0 ]] && return 1
 385    
 386         declare -i TERM_COLS="$(tput cols)"
 387         declare -i str_len="${#1}"
 388         [[ $str_len -ge $TERM_COLS ]] && {
 389              echo "$1";
 390              return 0;
 391         }
 392    
 393         declare -i filler_len="$(( (TERM_COLS - str_len) / 2 ))"
 394         [[ $# -ge 2 ]] && ch="${2:0:1}" || ch=" "
 395         filler=""
 396         for (( i = 0; i < filler_len; i++ )); do
 397              filler="${filler}${ch}"
 398         done
 399    
 400         printf "%s%s%s" "$filler" "$1" "$filler"
 401         [[ $(( (TERM_COLS - str_len) % 2 )) -ne 0 ]] && printf "%s" "${ch}"
 402         printf "\n"
 403    
 404         return 0
 405    }
 406    
 407    check(){ ## check for entry
 408        cd /var/www
 409        for MD in $(find . -name '*.md' -print)
 410        do
 411            grep -Hc "$1" $MD |egrep -v '0$'
 412        done
 413        echo "${BY} $(find . -name "$1" -print)${N}"
 414        cd - >/dev/null
 415    }
 416    
 417    crn(){ ## connect to web server
 418    play -q ~/Music/sounds/yaru/device-added.oga 2>/dev/null
 419    if [ -z $DISPLAY ]
 420    then
 421        ssh -q -X -tt crn "$*"
 422    else
 423        [ "$#" -gt 0 ] && TITLE="-T $*"
 424        xfce4-terminal --tab --geometry=100x27 $TITLE --active-tab -x ssh -q -X -tt crn "$*"
 425    fi
 426    clear
 427    }
 428    
 429    ct(){ ## Coffee timer or cooking timer
 430        # Use: ct {time} 
 431        if [ "$#" -gt 0 ]
 432        then
 433            echo -n "${BG}Cooking timer $1${N}" ;spinit sleep $1
 434        else
 435            # French press timer (default action)
 436            echo -n "${BG}Making Coffee${N}" ;spinit sleep 4m
 437        fi
 438        if [ -z $DISPLAY ]
 439        then
 440            clear
 441            if [ "$#" -gt 0 ]
 442                then
 443                    echo "${BR}Done${N}"
 444                else
 445                    echo "${BR}Coffee ready${N}"
 446            fi
 447            bl
 448        else
 449            if [ "$#" -gt 0 ]
 450                then
 451                    notify-send -u critical "⏳ Done!"
 452                else
 453                    notify-send -u critical "☕ Coffee ready!"
 454            fi
 455            mpv ~/Music/sounds/chime.wav >/dev/null 2>&1
 456        fi
 457    }
 458    
 459    db(){ ## open a database
 460        cd ~/db
 461        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="")
 462        case $CHOICE in
 463            *sqlite) sqlite3 $CHOICE
 464                ;;
 465            *) vd $CHOICE
 466                ;;
 467        esac
 468        cd -
 469    }
 470    
 471    display(){ ## show display settings
 472        # Use: display (no options)
 473        [ "$DEBUG" == 1 ] && set -x
 474        if [ -z $DISPLAY ]
 475        then
 476            xfce4-terminal --color-table
 477            echo "${BG}Display:${N} $(w|tail -1|awk '{print $3}') ${BC} $TERM${N} $(tput lines)r x $(tput cols)c"
 478        else
 479            xfce4-terminal --color-table
 480            echo "${BG}Display: ${BY}$DISPLAY${N} ${BC}$TERM${N}  $(tput lines)r x $(tput cols)c"
 481        fi
 482        line
 483    }
 484    
 485    ul(){ ## Upload to server files
 486        rsyncy  "$@" ${DL}
 487        play -q ~/Music/sounds/system/completion-success.oga  2>/dev/null
 488        rm -i "$@"
 489    }
 490    
 491    edir(){ ## emoji directory used in PS1
 492        # Use: See $PS1 at top of this file
 493        [ "$#" -ne 0 ] && grep -A 1 \^edir ~/.bashrc && return
 494        case $PWD in # Order is important, stops on 1st match
 495            *Archives*) echo -n "📦 ";;
 496            *bin*) echo -n "🔧 ";;
 497            *etc*) echo -n "";;
 498            *Documents*) echo -n "📃 ";;
 499            *Downloads*) echo -n "🔽 ";;
 500            *jots*) echo -n "📝 ";;
 501            *Music*) echo -n "🎧 ";;
 502            *pics*|*Pictures*) echo -n "📸 ";;
 503            *tmp*|*Temp*) echo -n "🚽 ";;
 504            *vids*|*Videos*) echo -n "🎬 ";;
 505            *web*|*www*) echo -n "🕸 ";;
 506            /home/mitch) echo -n "🏠 ";;
 507            *) echo -n "📂 ";;
 508        esac
 509    }
 510    
 511    emoji(){ ## search and display emoji
 512        # Use: emoji -h or --help for use
 513    case $1 in
 514        -s) # search
 515            grep -i --color $2 ~/etc/emoji.txt
 516            ;;
 517        -r) # random
 518            shuf -n 1 <~/etc/emoji.txt|cut -d' ' -f1
 519            ;;
 520        -R) # random
 521            shuf -n 1 <~/etc/emoji.txt|cut -d' ' -f1| tr -d \\n 
 522            ;;
 523        -d) # dump
 524            for SMILE in $(cut -d' ' -f1 <~/etc/emoji.txt)
 525            do
 526                echo -n $SMILE
 527            done
 528            ;;
 529        *) # help
 530            fmt -s -w $(tput cols)<<END
 531    ${BG}emoji${N} {option}
 532    -s {text}  # search
 533    -r         # random
 534    -R         # random, no new line
 535    -d         # dump
 536    END
 537            ;;
 538    esac
 539    }
 540    
 541    explain () { ## Use the explain API to explain commands - from the command line!
 542      if [ "$#" -eq 0 ]; then
 543        while read  -p "Command: " cmd; do
 544          curl -Gs "https://www.mankier.com/api/v2/explain/?cols="$(tput cols) --data-urlencode "q=$cmd"
 545        done
 546        echo "Bye!"
 547      elif [ "$#" -eq 1 ]; then
 548        curl -Gs "https://www.mankier.com/api/v2/explain/?cols="$(tput cols) --data-urlencode "q=$1"
 549      else
 550        echo "Usage"
 551        echo "explain                  interactive mode."
 552        echo "explain 'cmd -o | ...'   one quoted command to explain it."
 553      fi
 554    # Update 26-03-2015. If using this command gives no output, see if running a simple fetch causes this error:
 555    # $ curl https://www.mankier.com
 556    # curl: (35) Cannot communicate securely with peer: no common encryption algorithm(s).
 557    # If so, try specifying a cipher in the curl commands: curl --ciphers ecdhe_ecdsa_aes_128_sha
 558    }
 559    
 560    
 561    extract(){ ## handy archive extraction
 562        # Use: extract {file}
 563        [ "$DEBUG" == 1 ] && set -x
 564        if [ -f $1 ]
 565        then
 566            case $1 in
 567                *.tar.bz2)   tar xvjf $1     ;;
 568                *.tar.gz)    tar xvzf $1     ;;
 569                *.bz2)       bunzip2 $1      ;;
 570                *.rar)       unrar x $1      ;;
 571                *.gz)        gunzip $1       ;;
 572                *.tar)       tar xvf $1      ;;
 573                *.tbz2)      tar xvjf $1     ;;
 574                *.tgz)       tar xvzf $1     ;;
 575                *.zip)       unzip $1        ;;
 576                *.Z)         uncompress $1   ;;
 577                *.7z)        7z x $1         ;;
 578                *)           echo "${BR}$1 ${N}cannot be extracted via >extract<"
 579                            file $1;;
 580            esac
 581            play -q ~/Music/sounds/system/dialog-information.oga 2>/dev/null 1>&2
 582        else
 583            echo "${BR}$1 $N is not a valid file"
 584        fi
 585    }
 586    
 587    fr() { ## fuzzy run
 588    launchapp=$(IFS=':'; \
 589      for p in ${PATH}; \
 590      do find -L "${p}" -type f -executable -print 2> /dev/null; done \
 591      | fzf --header="Select application to launch:" \
 592        --exact \
 593        --height="50%" \
 594        --preview="(file -b {})" \
 595        --preview-window="down:wrap:25%") \
 596      && eval "${launchapp}"
 597    }
 598    
 599    gmt(){ ## display GMT (for radio stuff)
 600    
 601        command -v tty-clock >/dev/null || sudo apt install tty-clock -yyq
 602        xtitle "GMT Clock"
 603        tty-clock -usxrB -C $(( ( RANDOM % 6 ) + 1 ))
 604    }
 605    
 606    html(){ ## mark up code, etc...
 607        # Use: html {file}
 608    vim -f +"syn on" +"colorscheme termschool" +"set nonu" +"set foldenable!" +"set nospell" +"run! syntax/2html.vim" +"wq" +"q" $1
 609    }
 610    
 611    hping(){ ## httping with favorite options
 612        # Use: hping {name}    (defaults to my site)
 613        PINGHOST="$1"
 614        httping ${PINGHOST:=crn.hopto.org} -c 10 -S -Y -Z -s --offset-yellow 370 --offset-red 380 -K
 615    }
 616    
 617    large (){ ## find files larger than 800m
 618        find . -type f -name "*.mp4" -size +800M -exec ls -lh {} \; | awk '{print $5, $9}'
 619    }
 620    
 621    log(){ ## creates a basic log entry $LOG must be defined
 622        # Use: log {entry}  
 623        [ "$DEBUG" == "1" ] && set -x
 624        logger -i -t "$NAME" "$*"
 625    }
 626    
 627    man(){ ## run mangl if DISPLAY is set
 628        if [ -z $DISPLAY ]
 629        then
 630            /usr/bin/man $1
 631        else
 632            mangl  $1 2>/dev/null
 633        fi
 634    }
 635    
 636    md2pdf(){ ## covert markdown to pdf
 637    pandoc ${1%.md}.md -o ${1%.md}.html
 638    cat  ${1%.md}.html |htmldoc --cont --headfootsize 8.0 --linkcolor blue --linkstyle plain --format pdf14 - >  ${1%.md}.pdf && gio trash ${1%.md}.html
 639    }
 640    
 641    more(){ ## updated to set title bar
 642        # Use: more {file}
 643        xtitle "more $*"
 644        EXT="${1##*.}"
 645        case $EXT in
 646            epub|fb2|mobi) # books
 647                /home/mitch/.local/bin/epy $1
 648                ;;
 649            md) # markdown
 650                glow -t $1
 651                ;;
 652            csv|tsv) # tab/csv separated
 653                cat $1 |pspg --${EXT} --style=6
 654                ;;
 655            json|xlsx|xls|sqlite) # sqlite3
 656                vd $1
 657                ;;
 658            *) # default
 659                bat $1
 660                ;;
 661        esac
 662    }
 663    
 664    mp(){ ## media player front end
 665        FZF_DEFAULT_OPTS="--ansi  "
 666        # Use: mp {optional file}
 667        [ "$1" == "-d" ] && cd ~/Downloads  # jump to download directory
 668        [ -z $DISPLAY ] || WINDOW=$(xdotool getactivewindow 2>/dev/null) # get window ID
 669        clear
 670        if [ -f "$1" ]  # if you give it a file run it, else display a list
 671        then
 672            CHOICE="$1"
 673        else
 674            xtitle "mp: Name sort" 
 675            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="")
 676        fi
 677        EXT="${CHOICE##*.}"
 678        [ "$EXT" == "mp3" ] && FILE=$(echo $CHOICE|cut -d ' ' -f5)
 679        [ "$EXT" == "mp4" ] && FILE=$(echo $CHOICE|cut -d ' ' -f4)
 680        if [ ! -z $FILE ]
 681        then
 682            if [ ! -z $DISPLAY ] 
 683            then
 684                xtitle "$FILE"
 685                echo -n "Playing: $FILE "
 686                xdotool windowminimize $WINDOW
 687                xfconf-query --channel=xfwm4 --property=/general/use_compositing --type=bool --toggle
 688                spinit vlc --play-and-exit $FILE 1>&2 2>/dev/null
 689                xdotool windowactivate $WINDOW
 690                xfconf-query --channel=xfwm4 --property=/general/use_compositing --type=bool --toggle
 691                if [ -f $FILE -a "$(pwd)" == "/home/mitch/Downloads" ]  || [ "$(pwd)" == "/var/hold/Downloads" ] 
 692                then
 693                    clear
 694                    read -p "${BR}Remove:${BY} ${FILE}?${N} " -n 1 DEL
 695                    if [ "$DEL" == "y" ] 
 696                    then
 697                        rm $FILE 
 698                    fi
 699                    bl
 700                    if [ -f $FILE ] 
 701                    then
 702                        read -p "${BR}Upload:${BY} ${FILE}?${N} " -n 1 DEL
 703                        [ "$DEL" == "y" ] && ul $FILE 
 704                    fi
 705                    bl
 706                    if [ -f $FILE ]
 707                    then
 708                        bl
 709                        read -p "${BY}mv${N} $FILE to ~/Temp? " -n 1 MV
 710                        [ "$MV" == "y" ] && mv $FILE ~/Temp
 711                    fi
 712                fi
 713                if [ "$1" == "-n" ]
 714                    then
 715                        clear
 716                        [[ $(\ls -A *.mp? 2>/dev/null) ]] && llm || echo "No files"
 717                    else  
 718                        clear
 719                        [[ $(\ls -A *.mp? 2>/dev/null) ]] && llm -t || echo "No files"
 720                fi
 721            else
 722                echo "$FILE not played, no DISPLAY"
 723            fi
 724        fi
 725    }
 726    
 727    pause(){
 728        [ "$DEBUG" == "1" ] && set -x;
 729        [ "$1" == "-nt" ] && TMOUT="" && shift;
 730        echo "$BY";
 731        if [ $# -gt 0 ]; then
 732            read -t $1 -r -p "${C}Hit any key (${BY}$1${C} second timeout)${N}" -n 1 FOO;
 733        else
 734            read -r -p "${C}Hit any key${N}" -n 1 FOO;
 735        fi;
 736        bl
 737    }
 738    
 739    r(){ # r run it!
 740        # Use: r {optional pattern: p*}
 741        if [ $(\ls -F|grep -c '\*') -lt 1 ] 
 742        then
 743            echo "${BY}Nothing to do${N}"
 744        else
 745            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="")
 746            if [ ! -z "$CHOICE" ] 
 747            then
 748                tldr $CHOICE 2> /dev/null | tail -n +3
 749                read -p "${BG}${CHOICE} ${N}" ARGS
 750                ./${CHOICE} $ARGS
 751            fi
 752        fi
 753    }
 754    
 755    rcf(){ ## random color foreground - changes each time its called
 756        # Use: echo "$(rcf) Some text"
 757        tput setaf $((RANDOM % 256))
 758    }
 759    
 760    recover(){ ## vim recover from backup dir
 761        if [ -f "$1" ] 
 762        then
 763            FILE="$(pwd)/$1"
 764            cd ~/vim/backup
 765            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')
 766            vimdiff "$FILE" "$CHOICE"
 767        else
 768            echo "recover {file}"
 769            echo "
 770    vimdiff commands
 771    
 772    ]c :         - next difference
 773    [c :         - previous difference
 774    do           - diff obtain
 775    dp           - diff put
 776    zo           - open folded text
 777    zc           - close folded text
 778    :diffupdate  - re-scan the files for differences
 779    :set mouse=a - use mouse click to switch windows
 780    CTRL-W =     - resize windows the same
 781    CTRL-W w     - switch window
 782    "
 783        fi
 784        cd ${OLDDIR}
 785    }
 786    
 787    rs(){ ## restart shell with option to edit .bashrc
 788        # Use: rs (if anything is passed it will edit .bashrc file 1st)
 789        THEME="zenburn" # bat --list-themes
 790        if [ $# -gt 0 ]
 791        then
 792            play -q ~/Music/sounds/system/message-new-instant.oga 2>/dev/null
 793            vim ~/.bashrc
 794            sed -i -e "3s/.*/# Updated....: $(date)/" ~/.bashrc
 795            # bashrc
 796            log "Updated ~/.bashrc"
 797            bat --color=always --theme $THEME ~/.bashrc | aha -b -w -t "~/.bashrc" >/var/www/unix/bashrc.html
 798            cp  ~/.bashrc /var/www/unix/bashrc
 799    
 800            # vimrc - Added to make sure the Web versions were up to date.
 801            sed -i -e "3s/.*/\" Updated....: $(date)/" ~/.vimrc
 802            bat --color=always --theme $THEME ~/.vimrc | aha -b -w  -t "~/.vimrc" >/var/www/unix/vimrc.html
 803            cp  ~/.vimrc /var/www/unix/vimrc
 804    
 805            log "Restart: $$"
 806            exec bash
 807        else
 808            log "Restart: $$"
 809            reset; exec bash
 810        fi
 811    }
 812    
 813    rss(){ ## quick rss url reader
 814        # Use: rss {URL} {Count, defaults to 10}
 815        [ "$#" -eq 2 ] && COUNT=$2 || COUNT=10    
 816    lynx -stdin <<RSSEND
 817    <p>rss "$1"
 818    </p>
 819    
 820    $(rsstail --nofail --time-format '%r %m/%d/%Y' --initial $COUNT -e 1 --format '[{title}]({link}) {updated:>10}  \n' "$1"  |pandoc -t html)
 821    
 822    RSSEND
 823    }
 824    
 825    scale(){ ## change to 640x480
 826       nohup  xterm -geometry 140x4+0+900 -hold -e ~/bin/scale $1 &
 827    }
 828    
 829    sconky(){ ## re-start conky
 830        # Use: sconky (if anything is passed it will edit config file 1st)
 831        pkill conky
 832        spinit sleep 3
 833        nohup conky -d -c ~/.conkyrc >/dev/null 2>&1
 834        /home/mitch/bin/now-clocking-main/start.sh 2>&1
 835    
 836    }
 837    
 838    tab() { ## run command in new tab
 839    xfce4-terminal --tab --geometry=100x27 -T "$*" --active-tab -x "$*"
 840    }
 841    
 842    tunes(){ ## play my music
 843    SDIR=$(pwd)
 844    cd ~/Music/gospel/kjv
 845    \rm *mp3
 846    cd ~/Music/kjv-verses
 847    for VERSE in $(\ls |shuf -n 20)
 848    do
 849        cp $VERSE ~/Music/gospel/kjv
 850    done
 851    cd ~/Music && find gospel/ -name '*.mp3' >tunes.m3u 
 852    xtitle "Playing music"
 853    xfce4-terminal --tab --geometry=100x27 --title="Tunes" --active-tab -x nvlc -Z tunes.m3u
 854    cd $SDIR
 855    clear
 856    }
 857    
 858    webster(){ ## Lookup in Webster's 1828 via sqlite
 859    sqlite3 -batch -readonly ~/db/websters-1828.sqlite <<SQL |sed "s/\b$1\b/${BY}$1${N}/I"|less -F
 860    .headers off
 861    .mode line
 862    select * from Dictionary where Topic LIKE "$1";
 863    .quit
 864    SQL
 865    }
 866    
 867    xtitle(){ ## set window title
 868        # Use: xtitle "Text to display"
 869        printf "\033]0;%s\007" "${*}🌀${HOSTNAME}"
 870    }
 871    
 872    
 873    # Ending
 874    # ======
 875    clear
 876    if [ "$LOGNAME" == "mitch" ]
 877    then
 878        play -q ~/Music/system/outcome-success.oga 2>/dev/null
 879        uptime
 880        echo ""
 881        last
 882        status
 883    else
 884        log "Switching to root"
 885        echo "${BY}sudo: ${BR}switched to root$N"
 886        HISTFILE=/.root.hist        # keeps it out of mine
 887        TMOUT=600                   # Close terminal after 10 minutes of inactivity
 888        echo "Window timeout in: ${BY}$TMOUT seconds${N}"
 889        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} '
 890    fi
 891    
 892    [ -f ~/.fzf.bash ] && source ~/.fzf.bash
 893    
───────┴────────────────────────────────────────────────────────────────────────