───────┬──────────────────────────────────────────────────────────────────────── │ File: /home/mitch/.bashrc ───────┼──────────────────────────────────────────────────────────────────────── 1 │ # Description: My setting file for bash 2 │ # Author.....: Mitchell Johnston 3 │ # Contact....: mitch@crn.hopto.org 4 │ # Updated....: Thu 22 May 2025 07:21:49 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 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' 263 │ alias spider='wget --random-wait -r -p -e robots=off -U mozilla' # spider a site 264 │ alias sp='jot -e scratch.md' # scratch pad 265 │ alias sqlite=sqlite3 266 │ alias stats='ssh -q -tt laptop ~/bin/stats ' 267 │ alias tasks='ssh -q -tt laptop ~/bin/today -t' 268 │ alias task=tasks # because sometimes I am human 269 │ alias temp='watch sensors -f' 270 │ alias today='ssh -q -tt laptop ~/bin/today ' 271 │ alias tt='xfconf-query --channel=xfwm4 --property=/general/use_compositing --type=bool --toggle' 272 │ alias vf='vim -c Explore' 273 │ alias zips='vd ~/db/zipcodes.sqlite' 274 │ alias x='exit' 275 │ 276 │ # Bash options 277 │ # ============ 278 │ 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 279 │ shopt -s cmdhist # Save all lines of a multiple-line command in the same history entry 280 │ completion-ignore-case Off 281 │ shopt -s cdspell # Fix minor spelling error's in 'cd' command 282 │ shopt -s checkwinsize # Handle xterm resizing 283 │ shopt -s dotglob # Allow tab-completion of '.' filenames 284 │ shopt -s extglob # Bonus regex globbing! 285 │ shopt -s hostcomplete # Tab-complete words containing @ as hostnames 286 │ shopt -s execfail # Failed execs don't exit shell 287 │ set -o notify # Show status of terminated programs immediately 288 │ 289 │ # Tab (readline) completion settings 290 │ # ---------------------------------- 291 │ set show-all-if-ambiguous on # Show more w/ 1 <tab> {new} 292 │ set visible-stats on # Appends files to <tab> completes {new} 293 │ set completion-ignore-case on # Ignor case in completion 294 │ set match-hidden-files off # Allow matching on hidden files 295 │ 296 │ # History 297 │ # ------- 298 │ set bashhistfile=1000 # Number of history file entries 299 │ set dunique # Removes duplicate entries in the dirstack 300 │ set histdup=prev # Do not allow consecutive duplicate history entries 301 │ 302 │ # General 303 │ # ------- 304 │ set ulimit -c 0 # Turn off core dumps 305 │ set notify # Notifies when a job completes 306 │ 307 │ # Command line completion 308 │ # ----------------------- 309 │ complete -A hostname rsh rcp telnet rlogin r ftp ping disk ssh 310 │ complete -A command nohup exec eval trace gdb 311 │ complete -A command command type which 312 │ complete -A export printenv 313 │ complete -A variable export local readonly unset 314 │ complete -A enabled builtin 315 │ complete -A alias alias unalias 316 │ complete -A function function 317 │ complete -A user su mail finger 318 │ complete -A directory mkdir rmdir 319 │ complete -A directory -o default cd 320 │ complete -f -d -X '*.gz' gzip extract 321 │ complete -f -d -X '*.bz2' bzip2 extract 322 │ complete -f -o default -X '!*.gz' gunzip extract 323 │ complete -f -o default -X '!*.bz2' bunzip2 extract 324 │ complete -f -o default -X '!*.pl' perl perl5 325 │ complete -f -o default -X '!*.ps' gs ghostview ps2pdf ps2ascii 326 │ complete -f -o default -X '!*.dvi' dvips dvipdf xdvi dviselect dvitype 327 │ complete -f -o default -X '!*.+(html|htm)' lynx 328 │ complete -f -o default -X '!*.pdf' acroread pdf2ps 329 │ complete -f -o default -X '!*.texi*' makeinfo texi2dvi texi2html texi2pdf 330 │ complete -f -o default -X '!*.tex' tex latex slitex 331 │ complete -f -o default -X '!*.lyx' lyx 332 │ complete -f -o default -X '!*.+(jpg|gif|xpm|png|bmp)' xv gimp 333 │ complete -f -o default -X '!*.+(epub|epub3|fb2|mobi|azw3)' v epy 334 │ complete -f -o default -X '!*.+(avi|mp4|mpv|flv|wma|mkv)' vlc mp dr pi rc 335 │ complete -f -o default -X '!*.mp3' vlc mp 336 │ complete -f -o default -X '!*.ogg' vlc mp 337 │ complete -f -o default -X '!*.md' site vim gvim retext e mdv compile glow 338 │ 339 │ # FUNCTION DEFINITIONS 340 │ # ==================== 341 │ 342 │ bl(){ ## blank line 343 │ echo -e "\n" 344 │ } 345 │ 346 │ bm () 347 │ { 348 │ [ -f ~/Downloads/bookmarks.html ] && mv ~/Downloads/bookmarks.html ~/etc 349 │ lynx ~/etc/bookmarks.html 350 │ } 351 │ 352 │ bold(){ ## add file to .bold 353 │ # Use: bold {file} 354 │ echo $1 >>.bold 355 │ files 356 │ } 357 │ 358 │ center(){ ## center test on a line 359 │ # Use: center "string" {optional fill character} 360 │ 361 │ [[ $# == 0 ]] && return 1 362 │ 363 │ declare -i TERM_COLS="$(tput cols)" 364 │ declare -i str_len="${#1}" 365 │ [[ $str_len -ge $TERM_COLS ]] && { 366 │ echo "$1"; 367 │ return 0; 368 │ } 369 │ 370 │ declare -i filler_len="$(( (TERM_COLS - str_len) / 2 ))" 371 │ [[ $# -ge 2 ]] && ch="${2:0:1}" || ch=" " 372 │ filler="" 373 │ for (( i = 0; i < filler_len; i++ )); do 374 │ filler="${filler}${ch}" 375 │ done 376 │ 377 │ printf "%s%s%s" "$filler" "$1" "$filler" 378 │ [[ $(( (TERM_COLS - str_len) % 2 )) -ne 0 ]] && printf "%s" "${ch}" 379 │ printf "\n" 380 │ 381 │ return 0 382 │ } 383 │ 384 │ lgrep(){ ## check for entry in logs 385 │ rg "$*" /var/log/lighttpd/access.log /var/log/syslog 386 │ bl 387 │ echo "Count: ${BY}$(rg -c "$*" /var/log/lighttpd/access.log /var/log/syslog)${N}" 388 │ } 389 │ 390 │ ct(){ ## Coffee timer or cooking timer 391 │ # Use: ct {time} 392 │ if [ "$#" -gt 0 ] 393 │ then 394 │ echo -n "${BG}Cooking timer $1${N} ⏳ " ;spinit sleep $1 395 │ else 396 │ # French press timer (default action) 397 │ echo -n "${BG}Making Coffee${N} ☕ " ;spinit sleep 4m 398 │ fi 399 │ if [ -z $DISPLAY ] 400 │ then 401 │ clear 402 │ if [ "$#" -gt 0 ] 403 │ then 404 │ echo "⏳${BR}Done${N}" 405 │ else 406 │ echo "☕${BR}Coffee ready${N}" 407 │ fi 408 │ bl 409 │ else 410 │ if [ "$#" -gt 0 ] 411 │ then 412 │ notify-send -u critical "⏳ Done!" 413 │ else 414 │ notify-send -u critical "☕ Coffee ready!" 415 │ fi 416 │ mpv ~/Music/sounds/chime.wav >/dev/null 2>&1 417 │ fi 418 │ } 419 │ 420 │ db(){ ## look at a database 421 │ cd ~/db; 422 │ 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="➤ "); 423 │ case $CHOICE in 424 │ *sqlite) 425 │ sqlite3 $CHOICE 426 │ ;; 427 │ *) 428 │ vd $CHOICE 429 │ ;; 430 │ esac; 431 │ cd - 432 │ } 433 │ 434 │ display(){ ## show display settings 435 │ # Use: display (no options) 436 │ [ "$DEBUG" == 1 ] && set -x 437 │ if [ -z $DISPLAY ] 438 │ then 439 │ echo "$(w|tail -1|awk '{print $3}') $TERM $(tput lines)r x $(tput cols)c" 440 │ else 441 │ echo "$DISPLAY $TERM $(tput lines)r x $(tput cols)c" 442 │ fi 443 │ } 444 │ 445 │ 446 │ edir(){ ## emoji directory used in PS1 447 │ # Use: See $PS1 at top of this file 448 │ [ "$#" -ne 0 ] && grep -A 1 \^edir ~/.bashrc && return 449 │ case $PWD in # Order is important, stops on 1st match 450 │ *Archives*) echo -n "📦 ";; 451 │ *bin*) echo -n "🔧 ";; 452 │ *etc*) echo -n "⌨ ";; 453 │ *Documents*) echo -n "📃 ";; 454 │ *Downloads*) echo -n "🔽 ";; 455 │ *jots*) echo -n "📝 ";; 456 │ *Music*) echo -n "🎧 ";; 457 │ *pics*|*Pictures*) echo -n "📸 ";; 458 │ *tmp*|*Temp*) echo -n "🚽 ";; 459 │ *vids*|*Videos*) echo -n "🎬 ";; 460 │ *web*|*www*) echo -n "🕸 ";; 461 │ /home/mitch) echo -n "🏠 ";; 462 │ *) echo -n "📂 ";; 463 │ esac 464 │ } 465 │ 466 │ emoji(){ ## search and display emoji 467 │ # Use: emoji -h or --help for use 468 │ case $1 in 469 │ -s) # search 470 │ grep -i --color $2 ~/etc/emoji.txt 471 │ ;; 472 │ -r) # random 473 │ shuf -n 1 <~/etc/emoji.txt|cut -d' ' -f1 474 │ ;; 475 │ -R) # random 476 │ shuf -n 1 <~/etc/emoji.txt|cut -d' ' -f1| tr -d \\n 477 │ ;; 478 │ -d) # dump 479 │ for SMILE in $(cut -d' ' -f1 <~/etc/emoji.txt) 480 │ do 481 │ echo -n $SMILE 482 │ done 483 │ ;; 484 │ *) # help 485 │ fmt -s -w $(tput cols)<<END 486 │ ${BG}emoji${N} {option} 487 │ -s {text} # search 488 │ -r # random 489 │ -R # random, no new line 490 │ -d # dump 491 │ END 492 │ ;; 493 │ esac 494 │ } 495 │ 496 │ extract(){ ## handy archive extraction 497 │ # Use: extract {file} 498 │ [ "$DEBUG" == 1 ] && set -x 499 │ if [ -f $1 ] 500 │ then 501 │ case $1 in 502 │ *.tar.bz2) tar xvjf $1 ;; 503 │ *.tar.gz) tar xvzf $1 ;; 504 │ *.bz2) bunzip2 $1 ;; 505 │ *.rar) unrar x $1 ;; 506 │ *.gz) gunzip $1 ;; 507 │ *.tar) tar xvf $1 ;; 508 │ *.tbz2) tar xvjf $1 ;; 509 │ *.tgz) tar xvzf $1 ;; 510 │ *.zip) unzip $1 ;; 511 │ *.Z) uncompress $1 ;; 512 │ *.7z) 7z x $1 ;; 513 │ *) echo "${BR}$1 ${N}cannot be extracted via >extract<" 514 │ file $1;; 515 │ esac 516 │ else 517 │ echo "${BR}$1 $N is not a valid file" 518 │ fi 519 │ } 520 │ 521 │ gmt(){ ## display GMT (for radio stuff) 522 │ 523 │ command -v tty-clock >/dev/null || sudo apt install tty-clock -yyq 524 │ xtitle "GMT Clock" 525 │ tty-clock -usxrB -C $(( ( RANDOM % 6 ) + 1 )) 526 │ } 527 │ 528 │ goa(){ ## run go-access with no filters 529 │ cd /var/log/lighttpd 530 │ 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 531 │ cd - 532 │ } 533 │ 534 │ html(){ ## mark up code, etc... 535 │ # Use: html {file} 536 │ vim -f +"syn on" +"colorscheme termschool" +"set nonu" +"set foldenable!" +"set nospell" +"run! syntax/2html.vim" +"wq" +"q" $1 537 │ } 538 │ 539 │ hping(){ ## httping with favorite options 540 │ # Use: hping {name} (defaults to my site) 541 │ PINGHOST="$1" 542 │ httping ${PINGHOST:=crn.hopto.org} -c 10 -S -Y -Z -s --offset-yellow 370 --offset-red 380 -K 543 │ } 544 │ 545 │ log(){ ## creates a basic log entry $LOG must be defined 546 │ # Use: log {entry} 547 │ [ "$DEBUG" == "1" ] && set -x 548 │ logger -i -t "$NAME" "$*" 549 │ } 550 │ 551 │ md2pdf(){ ## covert markdown to pdf 552 │ pandoc ${1%.md}.md -o ${1%.md}.html 553 │ cat ${1%.md}.html |htmldoc --cont --headfootsize 8.0 --linkcolor blue --linkstyle plain --format pdf14 - > ${1%.md}.pdf && gio trash ${1%.md}.html 554 │ } 555 │ 556 │ more(){ ## updated to set title bar 557 │ # Use: more {file} 558 │ xtitle "more $*" 559 │ EXT="${1##*.}" 560 │ case $EXT in 561 │ epub|fb2|mobi) # books 562 │ /home/mitch/.local/bin/epy $1 563 │ ;; 564 │ md) # markdown 565 │ glow -t $1 566 │ ;; 567 │ csv|tsv) # tab/csv separated 568 │ cat $1 |pspg --${EXT} -s 6 569 │ ;; 570 │ json|xlsx|xls|sqlite) # sqlite3 571 │ vd $1 572 │ ;; 573 │ *) # default 574 │ bat -p $1 575 │ ;; 576 │ esac 577 │ } 578 │ 579 │ mp(){ ## media player front end 580 │ FZF_DEFAULT_OPTS="--ansi " 581 │ # Use: mp {optional file} 582 │ [ "$1" == "-d" ] && cd ~/Downloads # jump to download directory 583 │ [ -z $DISPLAY ] || WINDOW=$(xdotool getactivewindow 2>/dev/null) # get window ID 584 │ clear 585 │ if [ -f "$1" ] # if you give it a file run it, else display a list 586 │ then 587 │ CHOICE="$1" 588 │ else 589 │ if [ "$1" != "-n" ] # option for time sort in rev 590 │ then 591 │ xtitle "mp: $PWD {Time sort}" 592 │ 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="➤ ") 593 │ else 594 │ xtitle "mp: Name sort" 595 │ 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="➤ ") 596 │ fi 597 │ fi 598 │ FILE=$(echo $CHOICEa| cut -d' ' -f3) 599 │ if [ ! -z $FILE ] 600 │ then 601 │ if [ ! -z $DISPLAY ] 602 │ then 603 │ xtitle "$FILE" 604 │ echo "Playing: $FILE" 605 │ xdotool windowminimize $WINDOW 606 │ xfconf-query --channel=xfwm4 --property=/general/use_compositing --type=bool --toggle 607 │ spinit vlc --play-and-exit $FILE 1>&2 2>/dev/null 608 │ xdotool windowactivate $WINDOW 609 │ xfconf-query --channel=xfwm4 --property=/general/use_compositing --type=bool --toggle 610 │ if [ -f $FILE -a "$(pwd)" == "/home/mitch/Downloads" ] 611 │ then 612 │ clear 613 │ read -p "${BR}Remove:${BY} ${FILE}?${N} " -n 1 DEL 614 │ [ "$DEL" == "y" ] && gio trash $FILE 615 │ if [ -f $FILE ] 616 │ then 617 │ bl 618 │ read -p "${BY}mv${N} $FILE to ~/Temp? " -n 1 MV 619 │ [ "$MV" == "y" ] && mv $FILE ~/Temp 620 │ fi 621 │ fi 622 │ if [ "$1" == "-n" ] 623 │ then 624 │ clear 625 │ [[ $(\ls -A *.mp? 2>/dev/null) ]] && lm || echo "No files" 626 │ else 627 │ clear 628 │ [[ $(\ls -A *.mp? 2>/dev/null) ]] && lm -t || echo "No files" 629 │ fi 630 │ else 631 │ echo "$FILE not played, no DISPLAY" 632 │ fi 633 │ fi 634 │ } 635 │ 636 │ pause(){ ## simple pause routine 637 │ # Use: pause {optional number of seconds} or "-nt" for no time out 638 │ [ "$DEBUG" == "1" ] && set -x 639 │ [ "$1" == "-nt" ] && TMOUT="" && shift 640 │ echo "$BY"; 641 │ if [ $# -gt 0 ] 642 │ then 643 │ read -t $1 -r -p "${C}Hit any key (${BY}$1${C} second timeout)${N}" -n 1 FOO; 644 │ else 645 │ read -r -p "${C}Hit any key${N}" -n 1 FOO; 646 │ fi; 647 │ bl 648 │ } 649 │ 650 │ r(){ # r run it! 651 │ # Use: r {optional pattern: p*} 652 │ if [ $(\ls -F|grep -c '\*') -lt 1 ] 653 │ then 654 │ echo "${BY}Nothing to do${N}" 655 │ else 656 │ 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="➤ ") 657 │ if [ ! -z "$CHOICE" ] 658 │ then 659 │ tldr $CHOICE 2>/dev/null | tail -n +3 660 │ read -p "${BG}${CHOICE} ${N}" ARGS 661 │ ./${CHOICE} $ARGS 662 │ fi 663 │ fi 664 │ } 665 │ 666 │ rcf(){ ## random color foreground - changes each time its called 667 │ # Use: echo "$(rcf) Some text" 668 │ tput setaf $((RANDOM % 256)) 669 │ } 670 │ 671 │ recover(){ ## vim recover from backup dir 672 │ if [ -f "$1" ] 673 │ then 674 │ FILE="$(pwd)/$1" 675 │ cd ~/vim/backup 676 │ 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') 677 │ vimdiff "$FILE" "$CHOICE" 678 │ else 679 │ echo "recover {file}" 680 │ echo " 681 │ vimdiff commands 682 │ 683 │ ]c : - next difference 684 │ [c : - previous difference 685 │ do - diff obtain 686 │ dp - diff put 687 │ zo - open folded text 688 │ zc - close folded text 689 │ :diffupdate - re-scan the files for differences 690 │ :set mouse=a - use mouse click to switch windows 691 │ CTRL-W = - resize windows the same 692 │ CTRL-W w - switch window 693 │ " 694 │ fi 695 │ cd ${OLDDIR} 696 │ } 697 │ 698 │ rs(){ ## restart shell with option to edit .bashrc 699 │ # Use: rs (if anything is passed it will edit .bashrc file 1st) 700 │ THEME="zenburn" # bat --list-themes 701 │ if [ $# -gt 0 ] 702 │ then 703 │ vim ~/.bashrc 704 │ sed -i -e "4s/.*/# Updated....: $(date)/" ~/.bashrc 705 │ # bashrc 706 │ log "Updated ~/.bashrc" 707 │ bat --color=always --theme $THEME ~/.bashrc | aha -b -w -t "~/.bashrc" >/var/www/unix/bashrc.html 708 │ cp ~/.bashrc /var/www/unix/bashrc 709 │ 710 │ # vimrc - Added to make sure the Web versions were up to date. 711 │ sed -i -e "4s/.*/\" Updated....: $(date)/" ~/.vimrc 712 │ bat --color=always --theme $THEME ~/.vimrc | aha -b -w -t "~/.vimrc" >/var/www/unix/vimrc.html 713 │ cp ~/.vimrc /var/www/unix/vimrc 714 │ 715 │ # conkyrc - Added to make sure the Web versions were up to date. 716 │ bat --color=always --theme $THEME ~/.conkyrc | aha -b -w -t "~/.conkyrc" >/var/www/unix/conkyrc.html 717 │ cp ~/.conkyrc /var/www/unix/conkyrc 718 │ 719 │ # Other config files - Added to make sure the versions were up to date. 720 │ cp ~/.newsboat/urls ~/.newsboat/urls.md 721 │ bat --color=always --theme $THEME ~/.newsboat/urls.md | aha -b -w -t "~/.newsboat/urls" >/var/www/unix/urls.html 722 │ cp ~/.newsboat/urls /var/www/unix/urls.txt 723 │ cp ~/.newsboat/config /var/www/unix/config.txt 724 │ 725 │ log "Restart: $$" 726 │ exec bash 727 │ else 728 │ log "Restart: $$" 729 │ reset; exec bash 730 │ fi 731 │ } 732 │ 733 │ rss(){ ## quick rss url reader 734 │ 735 │ lynx -stdin <<RSSEND 736 │ <p>rss "$1" 737 │ </p> 738 │ 739 │ $(rsstail --nofail --time-format '%r %m/%d/%Y' --initial 10 -e 1 --format '[{title}]({link}) {updated:>10} \n' "$1" |pandoc -t html) 740 │ 741 │ RSSEND 742 │ 743 │ } 744 │ 745 │ sconky(){ ## re-start conky 746 │ # Use: sconky (if anything is passed it will edit config file 1st) 747 │ pkill conky 748 │ spinit sleep 3 749 │ nohup conky -d -c ~/.conkyrc >/dev/null 2>&1 750 │ } 751 │ 752 │ wi(){ ## watch it - Monitor downloads from 'get' or youtubedl, maily for nohup starts 753 │ # Use: wi (no options) 754 │ if [ -d ~/Downloads/dl ] # I sometimes create this to keep them separate 755 │ then 756 │ cd ~/Downloads/dl 757 │ fi 758 │ while : 759 │ do 760 │ clear 761 │ echo "$BC $(date)$BY" 762 │ [ ! -f get.txt ] && break 763 │ ls -sh *part 2>/dev/null && xtitle "wi: $(ls -sh *part|cut -d' ' -f1)" 764 │ [ -f nohup.out ] && tail -5 nohup.out && bl 765 │ echo "$BR" 766 │ spinit sleep 5 # display some fun while waiting 767 │ done 768 │ } 769 │ 770 │ ul(){ ## upload to other system 771 │ scp "$@" laptop:~/Downloads 772 │ echo ${BG} 773 │ ssh -q -tt laptop "exa --icons ~/Downloads/" 774 │ rm -i "$@" 775 │ } 776 │ 777 │ webster(){ ## Lookup in Webster's 1828 via sqlite 778 │ sqlite3 -batch ~/db/websters-1828.sqlite <<SQL | sed "s/\b$1\b/${BG}$1${N}/I"|less -F 779 │ .headers off 780 │ .mode line 781 │ select * from Dictionary where Topic LIKE "$1"; 782 │ .quit 783 │ SQL 784 │ } 785 │ 786 │ xtitle(){ ## set window title 787 │ # Use: xtitle "Text to display" 788 │ printf "\033]0;%s\007" "${*}🌀${HOSTNAME}" 789 │ } 790 │ 791 │ # Ending 792 │ # ====== 793 │ clear 794 │ if [ "$LOGNAME" == "mitch" ] 795 │ then 796 │ [ -f nohup.out ] && gio trash nohup.out 797 │ neofetch 798 │ quote 799 │ SSH_CT=$(grep "$(date +"%b %d")" /var/log/auth.log | grep -cE 'reset|Unable|refused|Failed') 800 │ if [ $SSH_CT -gt 0 ] 801 │ then 802 │ echo "${BR}SSH:${N} ${BY}$SSH_CT${N}";bl 803 │ fi 804 │ else 805 │ log "Switching to root" 806 │ echo "${BY}sudo: ${BR}switched to root$N" 807 │ HISTFILE=/.root.hist # keeps it out of mine 808 │ TMOUT=600 # Close terminal after 10 minutes of inactivity 809 │ echo "Window timeout in: ${BY}$TMOUT seconds${N}" 810 │ fi 811 │ [ -f ~/.fzf.bash ] && source ~/.fzf.bash ───────┴────────────────────────────────────────────────────────────────────────