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