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