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