───────┬──────────────────────────────────────────────────────────────────────── │ File: /home/mitch/.bashrc ───────┼──────────────────────────────────────────────────────────────────────── 1 │ # Description: My setting file for bash 2 │ # Author.....: Mitchell Johnston 3 │ # Updated....: Wed Oct 8 12:16:10 PM CDT 2025 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 -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='fortune |/home/mitch/.local/bin/tte $(shuf -n1 ~/etc/tte.txt)' 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;today' 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 wisdom='while :; do clear; quote; read x; done' 293 │ alias work='web;x' 294 │ alias wl='more ~/etc/work-links.md' 295 │ alias x='play -q ~/Music/sounds/yaru/desktop-logoff.oga 2>/dev/null;exit' 296 │ 297 │ # Bash options 298 │ # ============ 299 │ 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 300 │ shopt -s cmdhist # Save all lines of a multiple-line command in the same history entry 301 │ shopt -s cdspell # Fix minor spelling error's in 'cd' command 302 │ shopt -s checkwinsize # Handle xterm resizing 303 │ shopt -s dotglob # Allow tab-completion of '.' filenames 304 │ shopt -s extglob # Bonus regex globbing! 305 │ shopt -s hostcomplete # Tab-complete words containing @ as hostnames 306 │ shopt -s execfail # Failed execs don't exit shell 307 │ set -o notify # Show status of terminated programs immediately 308 │ 309 │ 310 │ # Tab (readline) completion settings 311 │ # ---------------------------------- 312 │ set show-all-if-ambiguous on # Show more w/ 1 <tab> {new} 313 │ set visible-stats on # Appends files to <tab> completes {new} 314 │ set completion-ignore-case on # Ignor case in completion 315 │ set match-hidden-files off # Allow matching on hidden files 316 │ 317 │ # History 318 │ # ------- 319 │ set bashhistfile=1000 # Number of history file entries 320 │ set dunique # Removes duplicate entries in the dirstack 321 │ set histdup=prev # Do not allow consecutive duplicate history entries 322 │ 323 │ # General 324 │ # ------- 325 │ set ulimit -c 0 # Turn off core dumps 326 │ set notify # Notifies when a job completes 327 │ 328 │ # Command line completion 329 │ # ----------------------- 330 │ complete -A hostname rsh rcp telnet rlogin r ftp ping disk ssh 331 │ complete -A command nohup exec eval trace gdb 332 │ complete -A command command type which 333 │ complete -A export printenv 334 │ complete -A variable export local readonly unset 335 │ complete -A enabled builtin 336 │ complete -A alias alias unalias 337 │ complete -A function function 338 │ complete -A user su mail finger 339 │ complete -A directory mkdir rmdir 340 │ complete -A directory -o default cd 341 │ complete -f -d -X '*.gz' gzip extract 342 │ complete -f -d -X '*.bz2' bzip2 extract 343 │ complete -f -o default -X '!*.gz' gunzip extract 344 │ complete -f -o default -X '!*.bz2' bunzip2 extract 345 │ complete -f -o default -X '!*.zip' zip extract 346 │ complete -f -o default -X '!*.pl' perl perl5 347 │ complete -f -o default -X '!*.ps' gs ghostview ps2pdf ps2ascii 348 │ complete -f -o default -X '!*.dvi' dvips dvipdf xdvi dviselect dvitype 349 │ complete -f -o default -X '!*.pdf' acroread pdf2ps 350 │ complete -f -o default -X '!*.texi*' makeinfo texi2dvi texi2html texi2pdf 351 │ complete -f -o default -X '!*.tex' tex latex slitex 352 │ complete -f -o default -X '!*.lyx' lyx 353 │ complete -f -o default -X '!*.+(jpg|gif|xpm|png|bmp)' xv gimp 354 │ complete -f -o default -X '!*.+(epub|epub3|fb2|mobi|azw3)' v epy 355 │ complete -f -o default -X '!*.+(avi|mp4|mpv|flv|wma|mkv)' vlc mp dr pi rc mplayer 356 │ complete -f -o default -X '!*.mp3' vlc mp mplayer 357 │ complete -f -o default -X '!*.ogg' vlc mp mplayer 358 │ complete -f -o default -X '!*.md' site vim gvim retext e mdv glow compile 359 │ 360 │ # FUNCTION DEFINITIONS 361 │ # ==================== 362 │ 363 │ bl(){ ## write a blank line 364 │ # Use: bl 365 │ [ "$DEBUG" == "1" ] && set -x 366 │ echo "" 367 │ } 368 │ 369 │ bm(){ ## view bookmarks from shell 370 │ # Use: bm 371 │ lynx ~/etc/bookmarks.html 372 │ } 373 │ 374 │ bold(){ ## add file to .bold 375 │ # Use: bold {file} 376 │ echo $1 >>.bold 377 │ files 378 │ } 379 │ 380 │ center(){ ## center text on a line 381 │ # Use: center "string" {optional fill character} 382 │ 383 │ [[ $# == 0 ]] && return 1 384 │ 385 │ declare -i TERM_COLS="$(tput cols)" 386 │ declare -i str_len="${#1}" 387 │ [[ $str_len -ge $TERM_COLS ]] && { 388 │ echo "$1"; 389 │ return 0; 390 │ } 391 │ 392 │ declare -i filler_len="$(( (TERM_COLS - str_len) / 2 ))" 393 │ [[ $# -ge 2 ]] && ch="${2:0:1}" || ch=" " 394 │ filler="" 395 │ for (( i = 0; i < filler_len; i++ )); do 396 │ filler="${filler}${ch}" 397 │ done 398 │ 399 │ printf "%s%s%s" "$filler" "$1" "$filler" 400 │ [[ $(( (TERM_COLS - str_len) % 2 )) -ne 0 ]] && printf "%s" "${ch}" 401 │ printf "\n" 402 │ 403 │ return 0 404 │ } 405 │ 406 │ check(){ ## check for entry 407 │ cd /var/www 408 │ for MD in $(find . -name '*.md' -print) 409 │ do 410 │ grep -Hc "$1" $MD |egrep -v '0$' 411 │ done 412 │ echo "${BY} $(find . -name "$1" -print)${N}" 413 │ cd - >/dev/null 414 │ } 415 │ 416 │ crn(){ ## connect to web server 417 │ play -q ~/Music/sounds/yaru/device-added.oga 2>/dev/null 418 │ if [ -z $DISPLAY ] 419 │ then 420 │ ssh -q -X -tt crn "$*" 421 │ else 422 │ [ "$#" -gt 0 ] && TITLE="-T $*" 423 │ xfce4-terminal --tab --geometry=100x27 $TITLE --active-tab -x ssh -q -X -tt crn "$*" 424 │ fi 425 │ clear 426 │ } 427 │ 428 │ ct(){ ## Coffee timer or cooking timer 429 │ # Use: ct {time} 430 │ if [ "$#" -gt 0 ] 431 │ then 432 │ echo -n "${BG}Cooking timer $1${N} ⏳ " ;spinit sleep $1 433 │ else 434 │ # French press timer (default action) 435 │ echo -n "${BG}Making Coffee${N} ☕ " ;spinit sleep 4m 436 │ fi 437 │ if [ -z $DISPLAY ] 438 │ then 439 │ clear 440 │ if [ "$#" -gt 0 ] 441 │ then 442 │ echo "⏳${BR}Done${N}" 443 │ else 444 │ echo "☕${BR}Coffee ready${N}" 445 │ fi 446 │ bl 447 │ else 448 │ if [ "$#" -gt 0 ] 449 │ then 450 │ notify-send -u critical "⏳ Done!" 451 │ else 452 │ notify-send -u critical "☕ Coffee ready!" 453 │ fi 454 │ mpv ~/Music/sounds/chime.wav >/dev/null 2>&1 455 │ fi 456 │ } 457 │ 458 │ db(){ ## open a database 459 │ cd ~/db 460 │ 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="➤ ") 461 │ case $CHOICE in 462 │ *sqlite) sqlite3 $CHOICE 463 │ ;; 464 │ *) vd $CHOICE 465 │ ;; 466 │ esac 467 │ cd - 468 │ } 469 │ 470 │ display(){ ## show display settings 471 │ # Use: display (no options) 472 │ [ "$DEBUG" == 1 ] && set -x 473 │ if [ -z $DISPLAY ] 474 │ then 475 │ xfce4-terminal --color-table 476 │ echo "${BG}Display:${N} $(w|tail -1|awk '{print $3}') ${BC} $TERM${N} $(tput lines)r x $(tput cols)c" 477 │ else 478 │ xfce4-terminal --color-table 479 │ echo "${BG}Display: ${BY}$DISPLAY${N} ${BC}$TERM${N} $(tput lines)r x $(tput cols)c" 480 │ fi 481 │ line 482 │ } 483 │ 484 │ ul(){ ## Upload to server files 485 │ rsyncy "$@" ${DL} 486 │ play -q ~/Music/sounds/system/completion-success.oga 2>/dev/null 487 │ rm -i "$@" 488 │ } 489 │ 490 │ edir(){ ## emoji directory used in PS1 491 │ # Use: See $PS1 at top of this file 492 │ [ "$#" -ne 0 ] && grep -A 1 \^edir ~/.bashrc && return 493 │ case $PWD in # Order is important, stops on 1st match 494 │ *Archives*) echo -n "📦 ";; 495 │ *bin*) echo -n "🔧 ";; 496 │ *etc*) echo -n "⌨ ";; 497 │ *Documents*) echo -n "📃 ";; 498 │ *Downloads*) echo -n "🔽 ";; 499 │ *jots*) echo -n "📝 ";; 500 │ *Music*) echo -n "🎧 ";; 501 │ *pics*|*Pictures*) echo -n "📸 ";; 502 │ *tmp*|*Temp*) echo -n "🚽 ";; 503 │ *vids*|*Videos*) echo -n "🎬 ";; 504 │ *web*|*www*) echo -n "🕸 ";; 505 │ /home/mitch) echo -n "🏠 ";; 506 │ *) echo -n "📂 ";; 507 │ esac 508 │ } 509 │ 510 │ emoji(){ ## search and display emoji 511 │ # Use: emoji -h or --help for use 512 │ case $1 in 513 │ -s) # search 514 │ grep -i --color $2 ~/etc/emoji.txt 515 │ ;; 516 │ -r) # random 517 │ shuf -n 1 <~/etc/emoji.txt|cut -d' ' -f1 518 │ ;; 519 │ -R) # random 520 │ shuf -n 1 <~/etc/emoji.txt|cut -d' ' -f1| tr -d \\n 521 │ ;; 522 │ -d) # dump 523 │ for SMILE in $(cut -d' ' -f1 <~/etc/emoji.txt) 524 │ do 525 │ echo -n $SMILE 526 │ done 527 │ ;; 528 │ *) # help 529 │ fmt -s -w $(tput cols)<<END 530 │ ${BG}emoji${N} {option} 531 │ -s {text} # search 532 │ -r # random 533 │ -R # random, no new line 534 │ -d # dump 535 │ END 536 │ ;; 537 │ esac 538 │ } 539 │ 540 │ explain () { ## Use the explain API to explain commands - from the command line! 541 │ if [ "$#" -eq 0 ]; then 542 │ while read -p "Command: " cmd; do 543 │ curl -Gs "https://www.mankier.com/api/v2/explain/?cols="$(tput cols) --data-urlencode "q=$cmd" 544 │ done 545 │ echo "Bye!" 546 │ elif [ "$#" -eq 1 ]; then 547 │ curl -Gs "https://www.mankier.com/api/v2/explain/?cols="$(tput cols) --data-urlencode "q=$1" 548 │ else 549 │ echo "Usage" 550 │ echo "explain interactive mode." 551 │ echo "explain 'cmd -o | ...' one quoted command to explain it." 552 │ fi 553 │ # Update 26-03-2015. If using this command gives no output, see if running a simple fetch causes this error: 554 │ # $ curl https://www.mankier.com 555 │ # curl: (35) Cannot communicate securely with peer: no common encryption algorithm(s). 556 │ # If so, try specifying a cipher in the curl commands: curl --ciphers ecdhe_ecdsa_aes_128_sha 557 │ } 558 │ 559 │ 560 │ extract(){ ## handy archive extraction 561 │ # Use: extract {file} 562 │ [ "$DEBUG" == 1 ] && set -x 563 │ if [ -f $1 ] 564 │ then 565 │ case $1 in 566 │ *.tar.bz2) tar xvjf $1 ;; 567 │ *.tar.gz) tar xvzf $1 ;; 568 │ *.bz2) bunzip2 $1 ;; 569 │ *.rar) unrar x $1 ;; 570 │ *.gz) gunzip $1 ;; 571 │ *.tar) tar xvf $1 ;; 572 │ *.tbz2) tar xvjf $1 ;; 573 │ *.tgz) tar xvzf $1 ;; 574 │ *.zip) unzip $1 ;; 575 │ *.Z) uncompress $1 ;; 576 │ *.7z) 7z x $1 ;; 577 │ *) echo "${BR}$1 ${N}cannot be extracted via >extract<" 578 │ file $1;; 579 │ esac 580 │ play -q ~/Music/sounds/system/dialog-information.oga 2>/dev/null 1>&2 581 │ else 582 │ echo "${BR}$1 $N is not a valid file" 583 │ fi 584 │ } 585 │ 586 │ fr() { ## fuzzy run 587 │ launchapp=$(IFS=':'; \ 588 │ for p in ${PATH}; \ 589 │ do find -L "${p}" -type f -executable -print 2> /dev/null; done \ 590 │ | fzf --header="Select application to launch:" \ 591 │ --exact \ 592 │ --height="50%" \ 593 │ --preview="(file -b {})" \ 594 │ --preview-window="down:wrap:25%") \ 595 │ && eval "${launchapp}" 596 │ } 597 │ 598 │ gmt(){ ## display GMT (for radio stuff) 599 │ 600 │ command -v tty-clock >/dev/null || sudo apt install tty-clock -yyq 601 │ xtitle "GMT Clock" 602 │ tty-clock -usxrB -C $(( ( RANDOM % 6 ) + 1 )) 603 │ } 604 │ 605 │ html(){ ## mark up code, etc... 606 │ # Use: html {file} 607 │ vim -f +"syn on" +"colorscheme termschool" +"set nonu" +"set foldenable!" +"set nospell" +"run! syntax/2html.vim" +"wq" +"q" $1 608 │ } 609 │ 610 │ hping(){ ## httping with favorite options 611 │ # Use: hping {name} (defaults to my site) 612 │ PINGHOST="$1" 613 │ httping ${PINGHOST:=crn.hopto.org} -c 10 -S -Y -Z -s --offset-yellow 370 --offset-red 380 -K 614 │ } 615 │ 616 │ large (){ ## find files larger than 800m 617 │ find . -type f -name "*.mp4" -size +800M -exec ls -lh {} \; | awk '{print $5, $9}' 618 │ } 619 │ 620 │ log(){ ## creates a basic log entry $LOG must be defined 621 │ # Use: log {entry} 622 │ [ "$DEBUG" == "1" ] && set -x 623 │ logger -i -t "$NAME" "$*" 624 │ } 625 │ 626 │ man(){ ## run mangl if DISPLAY is set 627 │ if [ -z $DISPLAY ] 628 │ then 629 │ /usr/bin/man $1 630 │ else 631 │ mangl $1 2>/dev/null 632 │ fi 633 │ } 634 │ 635 │ md2pdf(){ ## covert markdown to pdf 636 │ pandoc ${1%.md}.md -o ${1%.md}.html 637 │ cat ${1%.md}.html |htmldoc --cont --headfootsize 8.0 --linkcolor blue --linkstyle plain --format pdf14 - > ${1%.md}.pdf && gio trash ${1%.md}.html 638 │ } 639 │ 640 │ more(){ ## updated to set title bar 641 │ # Use: more {file} 642 │ xtitle "more $*" 643 │ EXT="${1##*.}" 644 │ case $EXT in 645 │ epub|fb2|mobi) # books 646 │ /home/mitch/.local/bin/epy $1 647 │ ;; 648 │ md) # markdown 649 │ glow -t $1 650 │ ;; 651 │ csv|tsv) # tab/csv separated 652 │ cat $1 |pspg --${EXT} --style=6 653 │ ;; 654 │ json|xlsx|xls|sqlite) # sqlite3 655 │ vd $1 656 │ ;; 657 │ *) # default 658 │ bat $1 659 │ ;; 660 │ esac 661 │ } 662 │ 663 │ mp(){ ## media player front end 664 │ FZF_DEFAULT_OPTS="--ansi " 665 │ # Use: mp {optional file} 666 │ [ "$1" == "-d" ] && cd ~/Downloads # jump to download directory 667 │ [ -z $DISPLAY ] || WINDOW=$(xdotool getactivewindow 2>/dev/null) # get window ID 668 │ clear 669 │ if [ -f "$1" ] # if you give it a file run it, else display a list 670 │ then 671 │ CHOICE="$1" 672 │ else 673 │ xtitle "mp: Name sort" 674 │ 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="➤ ") 675 │ fi 676 │ EXT="${CHOICE##*.}" 677 │ [ "$EXT" == "mp3" ] && FILE=$(echo $CHOICE|cut -d ' ' -f5) 678 │ [ "$EXT" == "mp4" ] && FILE=$(echo $CHOICE|cut -d ' ' -f4) 679 │ if [ ! -z $FILE ] 680 │ then 681 │ if [ ! -z $DISPLAY ] 682 │ then 683 │ xtitle "$FILE" 684 │ echo -n "Playing: $FILE " 685 │ xdotool windowminimize $WINDOW 686 │ xfconf-query --channel=xfwm4 --property=/general/use_compositing --type=bool --toggle 687 │ spinit vlc --play-and-exit $FILE 1>&2 2>/dev/null 688 │ xdotool windowactivate $WINDOW 689 │ xfconf-query --channel=xfwm4 --property=/general/use_compositing --type=bool --toggle 690 │ if [ -f $FILE -a "$(pwd)" == "/home/mitch/Downloads" ] || [ "$(pwd)" == "/var/hold/Downloads" ] 691 │ then 692 │ clear 693 │ read -p "${BR}Remove:${BY} ${FILE}?${N} " -n 1 DEL 694 │ if [ "$DEL" == "y" ] 695 │ then 696 │ rm $FILE 697 │ fi 698 │ clear 699 │ if [ -f $FILE ] 700 │ then 701 │ read -p "${BR}Upload:${BY} ${FILE}?${N} " -n 1 DEL 702 │ [ "$DEL" == "y" ] && ul $FILE 703 │ fi 704 │ clear 705 │ if [ -f $FILE ] 706 │ then 707 │ bl 708 │ read -p "${BY}mv${N} $FILE to ~/Temp? " -n 1 MV 709 │ [ "$MV" == "y" ] && mv $FILE ~/Temp 710 │ fi 711 │ fi 712 │ if [ "$1" == "-n" ] 713 │ then 714 │ clear 715 │ [[ $(\ls -A *.mp? 2>/dev/null) ]] && llm || echo "No files" 716 │ else 717 │ clear 718 │ [[ $(\ls -A *.mp? 2>/dev/null) ]] && llm -t || echo "No files" 719 │ fi 720 │ else 721 │ echo "$FILE not played, no DISPLAY" 722 │ fi 723 │ fi 724 │ } 725 │ 726 │ pause(){ 727 │ [ "$DEBUG" == "1" ] && set -x; 728 │ [ "$1" == "-nt" ] && TMOUT="" && shift; 729 │ echo "$BY"; 730 │ if [ $# -gt 0 ]; then 731 │ read -t $1 -r -p "${C}Hit any key (${BY}$1${C} second timeout)${N}" -n 1 FOO; 732 │ else 733 │ read -r -p "${C}Hit any key${N}" -n 1 FOO; 734 │ fi; 735 │ bl 736 │ } 737 │ 738 │ r(){ # r run it! 739 │ # Use: r {optional pattern: p*} 740 │ if [ $(\ls -F|grep -c '\*') -lt 1 ] 741 │ then 742 │ echo "${BY}Nothing to do${N}" 743 │ else 744 │ 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="➤ ") 745 │ if [ ! -z "$CHOICE" ] 746 │ then 747 │ tldr $CHOICE 2> /dev/null | tail -n +3 748 │ read -p "${BG}${CHOICE} ${N}" ARGS 749 │ ./${CHOICE} $ARGS 750 │ fi 751 │ fi 752 │ } 753 │ 754 │ rcf(){ ## random color foreground - changes each time its called 755 │ # Use: echo "$(rcf) Some text" 756 │ tput setaf $((RANDOM % 256)) 757 │ } 758 │ 759 │ recover(){ ## vim recover from backup dir 760 │ if [ -f "$1" ] 761 │ then 762 │ FILE="$(pwd)/$1" 763 │ cd ~/vim/backup 764 │ 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') 765 │ vimdiff "$FILE" "$CHOICE" 766 │ else 767 │ echo "recover {file}" 768 │ echo " 769 │ vimdiff commands 770 │ 771 │ ]c : - next difference 772 │ [c : - previous difference 773 │ do - diff obtain 774 │ dp - diff put 775 │ zo - open folded text 776 │ zc - close folded text 777 │ :diffupdate - re-scan the files for differences 778 │ :set mouse=a - use mouse click to switch windows 779 │ CTRL-W = - resize windows the same 780 │ CTRL-W w - switch window 781 │ " 782 │ fi 783 │ cd ${OLDDIR} 784 │ } 785 │ 786 │ rs(){ ## restart shell with option to edit .bashrc 787 │ # Use: rs (if anything is passed it will edit .bashrc file 1st) 788 │ THEME="zenburn" # bat --list-themes 789 │ if [ $# -gt 0 ] 790 │ then 791 │ play -q ~/Music/sounds/system/message-new-instant.oga 2>/dev/null 792 │ vim ~/.bashrc 793 │ sed -i -e "3s/.*/# Updated....: $(date)/" ~/.bashrc 794 │ # bashrc 795 │ log "Updated ~/.bashrc" 796 │ bat --color=always --theme $THEME ~/.bashrc | aha -b -w -t "~/.bashrc" >/var/www/unix/bashrc.html 797 │ cp ~/.bashrc /var/www/unix/bashrc 798 │ 799 │ # vimrc - Added to make sure the Web versions were up to date. 800 │ sed -i -e "3s/.*/\" Updated....: $(date)/" ~/.vimrc 801 │ bat --color=always --theme $THEME ~/.vimrc | aha -b -w -t "~/.vimrc" >/var/www/unix/vimrc.html 802 │ cp ~/.vimrc /var/www/unix/vimrc 803 │ 804 │ log "Restart: $$" 805 │ exec bash 806 │ else 807 │ log "Restart: $$" 808 │ reset; exec bash 809 │ fi 810 │ } 811 │ 812 │ rss(){ ## quick rss url reader 813 │ # Use: rss {URL} {Count, defaults to 10} 814 │ [ "$#" -eq 2 ] && COUNT=$2 || COUNT=10 815 │ lynx -stdin <<RSSEND 816 │ <p>rss "$1" 817 │ </p> 818 │ 819 │ $(rsstail --nofail --time-format '%r %m/%d/%Y' --initial $COUNT -e 1 --format '[{title}]({link}) {updated:>10} \n' "$1" |pandoc -t html) 820 │ 821 │ RSSEND 822 │ } 823 │ 824 │ scale(){ ## change to 640x480 825 │ nohup xterm -geometry 140x4+0+900 -hold -e ~/bin/scale $1 & 826 │ } 827 │ 828 │ sconky(){ ## re-start conky 829 │ # Use: sconky (if anything is passed it will edit config file 1st) 830 │ pkill conky 831 │ spinit sleep 3 832 │ nohup conky -d -c ~/.conkyrc >/dev/null 2>&1 833 │ /home/mitch/bin/now-clocking-main/start.sh 2>&1 834 │ 835 │ } 836 │ 837 │ tab() { ## run command in new tab 838 │ xfce4-terminal --tab --geometry=100x27 -T "$*" --active-tab -x "$*" 839 │ } 840 │ 841 │ tunes(){ ## play my music 842 │ SDIR=$(pwd) 843 │ cd ~/Music/gospel/kjv 844 │ \rm *mp3 845 │ cd ~/Music/kjv-verses 846 │ for VERSE in $(\ls |shuf -n 20) 847 │ do 848 │ cp $VERSE ~/Music/gospel/kjv 849 │ done 850 │ cd ~/Music && find gospel/ -name '*.mp3' >tunes.m3u 851 │ xtitle "Playing music" 852 │ xfce4-terminal --tab --geometry=100x27 --title="Tunes" --active-tab -x nvlc -Z tunes.m3u 853 │ cd $SDIR 854 │ clear 855 │ } 856 │ 857 │ webster(){ ## Lookup in Webster's 1828 via sqlite 858 │ sqlite3 -batch -readonly ~/db/websters-1828.sqlite <<SQL |sed "s/\b$1\b/${BY}$1${N}/I"|less -F 859 │ .headers off 860 │ .mode line 861 │ select * from Dictionary where Topic LIKE "$1"; 862 │ .quit 863 │ SQL 864 │ } 865 │ 866 │ xtitle(){ ## set window title 867 │ # Use: xtitle "Text to display" 868 │ printf "\033]0;%s\007" "${*}🌀${HOSTNAME}" 869 │ } 870 │ 871 │ 872 │ # Ending 873 │ # ====== 874 │ clear 875 │ if [ "$LOGNAME" == "mitch" ] 876 │ then 877 │ play -q ~/Music/system/outcome-success.oga 2>/dev/null 878 │ uptime 879 │ echo "" 880 │ last 881 │ status 882 │ else 883 │ log "Switching to root" 884 │ echo "${BY}sudo: ${BR}switched to root$N" 885 │ HISTFILE=/.root.hist # keeps it out of mine 886 │ TMOUT=600 # Close terminal after 10 minutes of inactivity 887 │ echo "Window timeout in: ${BY}$TMOUT seconds${N}" 888 │ 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} ' 889 │ fi 890 │ 891 │ [ -f ~/.fzf.bash ] && source ~/.fzf.bash 892 │ ───────┴────────────────────────────────────────────────────────────────────────