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