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