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