2016-04-29 15:18:05 +00:00
|
|
|
#!/bin/bash
|
2016-01-20 17:06:54 +00:00
|
|
|
#
|
|
|
|
# ~/.bashrc
|
|
|
|
#
|
|
|
|
# Thurstylark
|
2017-02-16 08:23:49 +00:00
|
|
|
#
|
|
|
|
# Reference: https://wiki.thurstylark.com/Bashrc.html
|
2016-01-20 17:06:54 +00:00
|
|
|
|
2016-01-21 19:42:34 +00:00
|
|
|
### MISC ###
|
|
|
|
|
2016-01-20 17:06:54 +00:00
|
|
|
# If not running interactively, don't do anything
|
|
|
|
[[ $- != *i* ]] && return
|
|
|
|
|
2017-02-16 08:23:49 +00:00
|
|
|
HISTCONTROL=ignoreboth # Don't put duplicate lines or lines starting with space in the history.
|
2016-03-31 17:09:10 +00:00
|
|
|
|
2017-02-16 08:23:49 +00:00
|
|
|
shopt -s autocd # If a directory is given without any command, CD into it.
|
2016-01-20 17:06:54 +00:00
|
|
|
|
2016-04-29 15:18:05 +00:00
|
|
|
# Some programs, such as tee(1), like to use this variable
|
2017-02-16 08:23:49 +00:00
|
|
|
export LS_COLORS='di=34;40:ln=35;40:so=32;40:pi=33;40:ex=31;40:bd=34;46:cd=34;43:su=0;41:sg=0;46:tw=0;42:ow=0;43:'
|
2016-03-15 14:15:35 +00:00
|
|
|
|
2016-01-21 19:42:34 +00:00
|
|
|
# Prefer vim, but if it's not installed, nano will do
|
2016-04-11 17:27:46 +00:00
|
|
|
[[ -s /usr/bin/vim ]] && export EDITOR=vim || export EDITOR=nano
|
2016-01-21 19:42:34 +00:00
|
|
|
|
|
|
|
# Enable pkgfile to automatically search for packages if pkgfile is installed
|
2016-04-11 17:27:46 +00:00
|
|
|
[[ -s /usr/share/doc/pkgfile/command-not-found.bash ]] && source /usr/share/doc/pkgfile/command-not-found.bash
|
2016-01-21 19:42:34 +00:00
|
|
|
|
2016-01-20 17:06:54 +00:00
|
|
|
|
|
|
|
# Enables colored Man pages:
|
|
|
|
man() {
|
2017-02-16 08:23:49 +00:00
|
|
|
env LESS_TERMCAP_mb=$'\E[01;31m' \
|
|
|
|
LESS_TERMCAP_md=$'\E[01;38;5;74m' \
|
|
|
|
LESS_TERMCAP_me=$'\E[0m' \
|
|
|
|
LESS_TERMCAP_se=$'\E[0m' \
|
|
|
|
LESS_TERMCAP_so=$'\E[38;5;246m' \
|
|
|
|
LESS_TERMCAP_ue=$'\E[0m' \
|
|
|
|
LESS_TERMCAP_us=$'\E[04;38;5;146m' \
|
|
|
|
man "$@"
|
2016-01-20 17:06:54 +00:00
|
|
|
}
|
|
|
|
|
2016-04-11 17:27:46 +00:00
|
|
|
# Do the same for awman
|
|
|
|
awman() {
|
2017-02-16 08:23:49 +00:00
|
|
|
env LESS_TERMCAP_mb=$'\E[01;31m' \
|
|
|
|
LESS_TERMCAP_md=$'\E[01;38;5;74m' \
|
|
|
|
LESS_TERMCAP_me=$'\E[0m' \
|
|
|
|
LESS_TERMCAP_se=$'\E[0m' \
|
|
|
|
LESS_TERMCAP_so=$'\E[38;5;246m' \
|
|
|
|
LESS_TERMCAP_ue=$'\E[0m' \
|
|
|
|
LESS_TERMCAP_us=$'\E[04;38;5;146m' \
|
|
|
|
awman "$@"
|
2016-04-11 17:27:46 +00:00
|
|
|
}
|
|
|
|
|
2016-01-20 17:06:54 +00:00
|
|
|
|
|
|
|
### PROMPT ###
|
|
|
|
|
2017-02-16 08:23:49 +00:00
|
|
|
promptsetup() {
|
|
|
|
# Color definitions for prompt
|
|
|
|
local fg_brightred='\[$(tput setaf 9)\]'
|
|
|
|
local fg_blue='\[$(tput setaf 4)\]'
|
|
|
|
local fg_magenta='\[$(tput setaf 13)\]'
|
|
|
|
local fg_cyan='\[$(tput setaf 6)\]'
|
|
|
|
local fg_brightcyan='\[$(tput setaf 14)\]'
|
2017-05-25 22:23:45 +00:00
|
|
|
local fg_green='\[$(tput setaf 2)\]'
|
2017-02-16 08:23:49 +00:00
|
|
|
local reset='\[$(tput sgr0)\]'
|
2017-05-25 22:23:45 +00:00
|
|
|
local hostname='\h'
|
|
|
|
local mixin
|
2017-02-16 08:23:49 +00:00
|
|
|
|
|
|
|
# [hh:mm][username@hostname pwd]$
|
2017-05-25 22:25:51 +00:00
|
|
|
|
|
|
|
# Remotely, hostname is red.
|
|
|
|
[ -n "$SSH_CLIENT" ] && hostname="${fg_brightred}\h${reset}"
|
|
|
|
|
|
|
|
# If in a python venv, add venv name in green.
|
|
|
|
[ -n "$VIRTUAL_ENV" ] && mixin=" ${fg_green}$(basename $VIRTUAL_ENV)${reset}"
|
|
|
|
|
|
|
|
# If in a vcsh repo env, add repo name in magenta.
|
|
|
|
[ -n "$VCSH_REPO_NAME" ] && mixin=" ${fg_magenta}$VCSH_REPO_NAME${reset}"
|
2017-05-25 22:23:45 +00:00
|
|
|
|
|
|
|
PS1="${fg_blue}[\A]${fg_cyan}[${fg_brightcyan}\u${fg_cyan}@${hostname}${mixin} ${fg_cyan}\W]${reset}\$ "
|
2017-02-16 08:23:49 +00:00
|
|
|
}
|
2016-01-20 17:06:54 +00:00
|
|
|
|
2017-02-16 08:23:49 +00:00
|
|
|
promptsetup
|
2016-01-20 17:06:54 +00:00
|
|
|
|
|
|
|
### ALIASES ###
|
|
|
|
|
|
|
|
# Colorize all `ls` output:
|
2016-01-28 18:09:13 +00:00
|
|
|
alias ls='ls -AF --color=auto'
|
2017-02-16 08:23:49 +00:00
|
|
|
|
2016-01-20 17:06:54 +00:00
|
|
|
# Map "la" to `ls -la`
|
2016-01-28 18:09:13 +00:00
|
|
|
alias la='ls -laFh --color=auto'
|
2016-01-20 17:06:54 +00:00
|
|
|
|
|
|
|
# Colorize `grep` output
|
|
|
|
alias grep='grep --color=auto'
|
|
|
|
|
|
|
|
# Change layout of lsblk to include FSTYPE and remove MAJ:MIN, RM, and RO collumns.
|
|
|
|
alias lsblk='lsblk -o NAME,FSTYPE,SIZE,TYPE,MOUNTPOINT'
|
|
|
|
|
2016-01-21 22:21:30 +00:00
|
|
|
# Always use sudo when using nmap.
|
|
|
|
alias nmap='sudo -E nmap'
|
2016-01-21 19:42:34 +00:00
|
|
|
|
2017-04-26 15:02:27 +00:00
|
|
|
# Switch $TERM temporarily (for logging into machines that don't have tmux-256color terminfo)
|
|
|
|
alias screenterm='TERM=screen-256color'
|
|
|
|
|
2016-01-21 19:42:34 +00:00
|
|
|
# I'm tired of managing weechat configs and multiple nicks
|
2017-02-10 00:25:32 +00:00
|
|
|
# Reference: https://wiki.thurstylark.com/Weechat.html
|
2016-01-21 19:42:34 +00:00
|
|
|
|
2017-01-10 22:37:02 +00:00
|
|
|
# If you don't have weechat installed, connect to the existing tmux session through mosh
|
|
|
|
[[ ! -s /usr/bin/weechat ]] && alias weechat='mosh vps -- tmux attach -dt weechat'
|
|
|
|
# If you are thurstylark-vps, connect to the existing tmux session locally
|
|
|
|
[[ "$HOSTNAME" = "thurstylark-vps" ]] && alias weechat='tmux attach -dt weechat'
|
2017-02-17 16:46:46 +00:00
|
|
|
|
2017-04-28 16:58:17 +00:00
|
|
|
### FUNCTIONS ###
|
|
|
|
|
2017-02-17 16:46:46 +00:00
|
|
|
# Print Dell Service Tag
|
|
|
|
getdst() {
|
|
|
|
if [[ "$1" = "-l" ]]; then
|
|
|
|
printf "http://www.dell.com/support/home/us/en/04/product-support/servicetag/%s\n" "$(getdst)"
|
|
|
|
else
|
|
|
|
sudo dmidecode -s system-serial-number
|
|
|
|
fi
|
|
|
|
}
|
2017-04-28 16:58:17 +00:00
|
|
|
|
|
|
|
countdown() {
|
|
|
|
local secs="$1"
|
|
|
|
while [ $secs -gt 0 ]; do
|
|
|
|
echo -ne "$secs\033[0K\r"
|
|
|
|
sleep 1
|
|
|
|
: $((secs--))
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Screenshot utils
|
|
|
|
shot() {
|
|
|
|
# Usage: shot XY
|
|
|
|
local destdir="$HOME/Pictures/screenshots"
|
2017-06-02 21:00:52 +00:00
|
|
|
local fname="shot-$(date +%F-%T).png"
|
2017-04-28 16:58:17 +00:00
|
|
|
local pb="fb"
|
2017-06-02 21:00:52 +00:00
|
|
|
local paste msgt msgd opts
|
|
|
|
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
printf "Usage: shot XY
|
|
|
|
X: Target
|
|
|
|
Y: Destination
|
|
|
|
|
|
|
|
Valid Targets:
|
|
|
|
w Active Window
|
|
|
|
a All displays
|
|
|
|
s Mouse Selection
|
|
|
|
|
|
|
|
Valid Destinations:
|
|
|
|
f Save to file (defined in function)
|
|
|
|
p Upload to a pastebin (defined in function)
|
|
|
|
"
|
|
|
|
return
|
|
|
|
fi
|
2017-04-28 16:58:17 +00:00
|
|
|
|
|
|
|
# X: What to capture
|
|
|
|
case ${1:0:1} in
|
|
|
|
# Active window
|
2017-06-02 21:00:52 +00:00
|
|
|
w) printf "Focus target window now...\n"
|
|
|
|
opts="-i $(xdotool getactivewindow)"
|
|
|
|
msgt="active window"
|
2017-04-28 16:58:17 +00:00
|
|
|
;;
|
|
|
|
# All
|
2017-06-02 21:00:52 +00:00
|
|
|
a) msgt="all displays"
|
|
|
|
;;
|
2017-04-28 16:58:17 +00:00
|
|
|
# Mouse selection
|
2017-06-02 21:00:52 +00:00
|
|
|
s) opts="-s --noopengl"
|
|
|
|
msgt="mouse selection"
|
|
|
|
;;
|
|
|
|
|
|
|
|
*) printf "Unknown target: %s\n" "${1:0:1}"
|
|
|
|
return
|
|
|
|
;;
|
2017-04-28 16:58:17 +00:00
|
|
|
esac
|
2018-11-28 04:59:50 +00:00
|
|
|
#Y: Where to put the result case ${1:1:1} in
|
2017-04-28 16:58:17 +00:00
|
|
|
# Save to file
|
2017-06-02 21:00:52 +00:00
|
|
|
f) msgd="file: $destdir/$fname"
|
2017-04-28 16:58:17 +00:00
|
|
|
;;
|
|
|
|
# Post to a pastebin
|
2017-06-02 21:00:52 +00:00
|
|
|
p) destdir=$destdir/pasted
|
|
|
|
msgd="pastebin"
|
|
|
|
paste=1;;
|
|
|
|
|
|
|
|
*) printf "Unknown destination: %s\n" "${1:1:1}"
|
|
|
|
return
|
|
|
|
;;
|
2017-04-28 16:58:17 +00:00
|
|
|
esac
|
|
|
|
|
2017-06-02 21:00:52 +00:00
|
|
|
# Make sure destination directory will exist
|
|
|
|
[[ ! -d "$destdir" ]] && mkdir -p "$destdir"
|
|
|
|
local fpath="${destdir}/${fname}"
|
|
|
|
# If target is active window, give a 5 second countdown before running maim
|
|
|
|
[[ "$msgt" = "active window" ]] && countdown 5
|
|
|
|
|
|
|
|
maim $opts "$fpath"
|
|
|
|
printf "Captured %s -> %s\n" "$msgt" "$msgd"
|
|
|
|
# If destination is a pastebin, do the needful
|
|
|
|
[[ "$paste" ]] && $pb "$fpath"
|
2018-11-28 04:59:50 +00:00
|
|
|
} fontfind() { if [[ -z $1 || ${#1} -gt 1 ]]; then
|
2017-05-03 15:00:07 +00:00
|
|
|
printf "E: only one character accepted"
|
|
|
|
fi
|
|
|
|
local glyph=$1
|
|
|
|
FC_DEBUG=4 pango-view -qt "$glyph" 2>&1 | awk -F \" '/family: / { m = $2 } END { print m }'
|
|
|
|
}
|
2017-05-24 17:33:13 +00:00
|
|
|
|
|
|
|
vactivate() {
|
|
|
|
local path=~/.venv/$1
|
|
|
|
|
|
|
|
if [[ ! -d $path ]]; then
|
2017-06-21 16:46:12 +00:00
|
|
|
python -m venv --prompt "venv: $1" --system-site-packages $path
|
2017-05-24 17:33:13 +00:00
|
|
|
fi
|
2017-05-25 22:02:43 +00:00
|
|
|
source $path/bin/activate; bash; deactivate
|
2017-05-24 17:33:13 +00:00
|
|
|
}
|
2018-11-28 04:59:50 +00:00
|
|
|
|
|
|
|
# Append a local bashrc. Meant to give the ability to tune a bashrc for a
|
|
|
|
# specific environment. These won't be tracked in vcsh.
|
|
|
|
|
|
|
|
source ~/.local.bashrc
|