Add functions and misc. to .bashrc

This commit is contained in:
Horseshoe Crab 2021-09-16 22:46:44 -07:00
parent 8c1bd797cf
commit 7a3ded00bb
6 changed files with 108 additions and 40 deletions

119
.bashrc
View File

@ -1,5 +1,5 @@
#
# this is my ~/.bashrc
# .bashrc
# (Note: this _should_ be _somewhat_ OS-agnostic, at least, enough for me)
#
@ -11,11 +11,13 @@
shopt -s checkwinsize # check window size after cmd, update LINES and COLUMNS
shopt -s globstar # pattern '**' matches all files, >= 0 dir/subdirs
#shopt -s expand_aliases # //
shopt -s histappend # append to history file instead of overwriting
HISTCONTROL=ignoredups # ignore duplicate commands or if start with a space
HISTSIZE=48000 # history lines stored in memory (while using bash)
HISTFILESIZE=48000 # history lines stored in .bash_history after session
shopt -s histappend # append to history file instead of overwriting
case "$(uname -s)" in # for OS-specific configuration
Linux) operating_system='linux' ;;
@ -43,10 +45,14 @@ if [ "$hostname" = "shorefall" ]; then
fi
export PATH
export BROWSER="firefox"
if [[ "$operating_system" = "macOS" || "$operating_system" = "BSD" ]] ; then
export CLICOLOR=1
fi
# use 'nvim' if it exists on system
[ command -v nvim &> /dev/null ] && export EDITOR="nvim" || export EDITOR="vim"
export BROWSER="firefox"
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
@ -67,10 +73,6 @@ if [ -n "$force_color_prompt" ]; then
fi
fi
if [[ "$operating_system" = "macOS" || "$operating_system" = "BSD" ]] ; then
export CLICOLOR=1
fi
# PS1 settings
#Old PS1: PS1="[\u@\h]:\w\$ "
if [[ $(id -u) -eq 0 ]]; then # if current user is root
@ -87,6 +89,8 @@ GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01: quote=01
export GCC_COLORS
############################## user functions ##############################
# find-keyword [directory path] [keyword]: find and list files with keyword in
# the filename
find-keyword() {
@ -110,7 +114,7 @@ find-string() {
# img_loop_here: $1 = seconds until next photo displayed
# BUG: currently, after running this function, the user needs to manually run
# 'reset' to unscrew the terminal
img_loop_here() {
img-loop-here() {
if [ "$1" = "" ]; then
echo "Usage: img_loop_here [seconds until next photo displayed]"
else
@ -122,6 +126,94 @@ img_loop_here() {
fi
}
# rainbow-shell: print out a looping rainbow in the shell. Happy pride month!
# For best results, run in full-screened terminal (Mod+f in i3)
rainbow-shell() {
yes "$(seq 231 -1 16)" | while read i; do
printf "\x1b[48;5;${i}m\n"
sleep .02
done
}
# colors - print out current color values set in terminal
colors() {
local fgc bgc vals seq0
printf "Color escapes are %s\n" '\e[${value};...;${value}m'
printf "Values 30..37 are \e[33mforeground colors\e[m\n"
printf "Values 40..47 are \e[43mbackground colors\e[m\n"
printf "Value 1 gives a \e[1mbold-faced look\e[m\n\n"
# foreground colors
for fgc in {30..37}; do
# background colors
for bgc in {40..47}; do
fgc=${fgc#37} # white
bgc=${bgc#40} # black
vals="${fgc:+$fgc;}${bgc}"
vals=${vals%%;}
seq0="${vals:+\e[${vals}m}"
printf " %-9s" "${seq0:-(default)}"
printf " ${seq0}TEXT\e[m"
printf " \e[${vals:+${vals+$vals;}}1mBOLD\e[m"
done
echo; echo
done
}
# term-color-vals: print all 256-bit color values in their associated color
term-color-vals() {
for i in {0..255}; do
printf "\x1b[38;5;${i}mcolor%-5i\x1b[0m" $i
if ! (( ($i + 1 ) % 8 )); then
echo
fi
done
}
# ex - archive extractor
# usage: ex <file>
ex() {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via ex()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
# public-ip: fetch current public IP address
public-ip() {
curl 'http://icanhazip.com/'
}
# scan-for-printers: look for printers on the connected LAN
scan-for-printers() {
sudo lpinfo -v
}
# wifi-strength: get some WiFi statistics in real time
wifi-strength() {
watch -n 1 cat /proc/net/wireless
}
############################## aliases ##############################
# Note to self: alias substitution is recursive AS LONG AS each expanded alias
# ends in a space character (allowing for multiple aliases to be used on one
# line). This is a POSIX specification. You do not know how long it took me to
@ -132,12 +224,15 @@ alias cl='clear '
alias e='exit '
alias q='exit '
alias DIE='shutdown now '
alias cp='cp -i' # confirm before overwriting a file
alias cp='cp -i ' # confirm before overwriting a file
alias df='df -h '
alias fucking='sudo '
alias goddammit=' '
alias bottom='top '
alias bc='bc -l ' # makes bc use 'scale=20' by default
alias grep='grep --color '
alias grep='grep --color=auto '
alias egrep='egrep --color=auto '
alias fgrep='fgrep --color=auto '
alias vim="$EDITOR "
alias i3config="$EDITOR ~/.config/i3/config && i3-msg reload && i3-msg restart"
alias bashrc="$EDITOR ~/.bashrc"
@ -177,6 +272,8 @@ else # assume GNU ls (should work on _most_ Linuxes)
fi
############################## bash completion ##############################
# enable programmable completion features (possibly already enabled by
# /etc/bash.bashrc or /etc/profile).
if [ -f /usr/share/bash-completion/bash_completion ]; then

View File

@ -1,5 +0,0 @@
#!/bin/sh
# TODO: add other options in case icanhazip.com goes down
curl 'http://icanhazip.com/'

View File

@ -1,4 +0,0 @@
# Shell rainbow. Happy pride month!
# For best results, run in full-screened terminal (Mod+f in i3)
yes "$(seq 231 -1 16)" | while read i; do printf "\x1b[48;5;${i}m\n"; sleep .02; done

View File

@ -1,6 +0,0 @@
#!/bin/sh
# because I'll probably forget the actual command
sudo lpinfo -v

View File

@ -1,10 +0,0 @@
#!/usr/bin/env bash
# prints all of the 256-bit color values in their associated color
for i in {0..255}; do
printf "\x1b[38;5;${i}mcolor%-5i\x1b[0m" $i
if ! (( ($i + 1 ) % 8 )); then
echo
fi
done

View File

@ -1,4 +0,0 @@
#!/usr/bin/env bash
watch -n 1 cat /proc/net/wireless