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