2024-06-11 10:12:11 -07:00
|
|
|
|
|
|
|
# how about unfucking the terminal
|
|
|
|
|
|
|
|
case "$TERM" in
|
|
|
|
rxvt-cygwin-native)
|
|
|
|
TERM=rxvt
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
HISTCONTROL=ignoreboth
|
|
|
|
# append to the history file, don't overwrite it
|
|
|
|
shopt -s histappend
|
|
|
|
HISTSIZE=100000
|
|
|
|
HISTFILESIZE=200000
|
|
|
|
|
|
|
|
shopt -s checkwinsize
|
|
|
|
|
|
|
|
# make less more friendly for non-text input files, see lesspipe(1)
|
|
|
|
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
|
|
|
|
|
|
|
|
# enable color support of ls and also add handy aliases
|
|
|
|
if [ -x /usr/bin/dircolors ]; then
|
|
|
|
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
|
|
|
|
alias ls='ls --color=auto'
|
|
|
|
|
|
|
|
alias grep='grep --color=auto'
|
|
|
|
alias fgrep='fgrep --color=auto'
|
|
|
|
alias egrep='egrep --color=auto'
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f ~/.bash_aliases ]; then
|
|
|
|
. ~/.bash_aliases
|
|
|
|
fi
|
|
|
|
|
|
|
|
## enable programmable completion features (you don't need to enable
|
|
|
|
## this, if it's already enabled in /etc/bash.bashrc and /etc/profile
|
|
|
|
## sources /etc/bash.bashrc).
|
|
|
|
#if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
|
|
|
|
# . /etc/bash_completion
|
|
|
|
#fi
|
|
|
|
|
|
|
|
############# my stuff
|
|
|
|
|
|
|
|
#if [ -z "$SSH_AUTH_SOCK" ] ; then
|
|
|
|
# eval `ssh-agent`
|
|
|
|
# ssh-add
|
|
|
|
#fi
|
|
|
|
|
|
|
|
USER=`whoami`
|
|
|
|
|
|
|
|
PATH="$(echo ~)/bin:$PATH:$(echo ~)/apps/bin"
|
|
|
|
|
|
|
|
# I like to know if this shell is the child of an editor
|
|
|
|
|
|
|
|
PARENTPROC=$(ps -o command= -c $PPID 2>/dev/null)
|
|
|
|
PARENTSTR=""
|
|
|
|
|
|
|
|
GLYPH_VIM=""
|
|
|
|
GLYPH_PRE=""
|
|
|
|
GLYPH_SEP=""
|
|
|
|
GLYPH_JOB=""
|
|
|
|
GLYPH_JOB=""
|
|
|
|
GLYPH_EXIT=""
|
|
|
|
|
|
|
|
COLOR_VIM="255 255 64"
|
|
|
|
COLOR_BG="70 70 70"
|
|
|
|
|
|
|
|
ANSI_RESET="\001\033[0m\002"
|
|
|
|
|
|
|
|
fgcolor() {
|
|
|
|
echo "\001\033[38;2;${1};${2};${3}m\002"
|
|
|
|
}
|
|
|
|
|
|
|
|
bgcolor() {
|
|
|
|
echo "\001\033[48;2;${1};${2};${3}m\002"
|
|
|
|
}
|
|
|
|
|
|
|
|
if [[ $PARENTPROC == 'vim' ]] || [[ $PARENTPROC == 'view' ]]; then
|
|
|
|
PARENTSTR="$(bgcolor $COLOR_BG)$(fgcolor $COLOR_VIM) ${GLYPH_VIM} ${ANSI_RESET}$(fgcolor $COLOR_BG)${GLYPH_SEP} ${ANSI_RESET}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
SHELLUSER=$USER
|
|
|
|
if [ "$SHELLUSER" == 'erikstambaugh' ]; then
|
|
|
|
SHELLUSER=es
|
|
|
|
fi
|
|
|
|
|
|
|
|
pwaws() {
|
|
|
|
grep aws ~/passwords | tail -1 | sed -e 's/.* //'| pbcopy
|
|
|
|
}
|
|
|
|
|
|
|
|
pw365() {
|
|
|
|
grep 365 ~/passwords | tail -1 | sed -e 's/.* //'| pbcopy
|
|
|
|
}
|
|
|
|
|
|
|
|
ps1_jobs() {
|
|
|
|
J=$(jobs)
|
|
|
|
if [[ -n $J ]]; then
|
|
|
|
echo -ne "\001\033[38;2;192;192;64m\002\001\033[38;2;64;64;64m\033[48;2;192;192;64m\002${GLYPH_JOB} \001\033[0m\033[38;2;192;192;64m\002\001\033[0m\002 "
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
ps1_git() {
|
|
|
|
BRANCH=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/^* //' | cut -c 1-25)
|
|
|
|
[[ $(echo $BRANCH | wc -c) -ge 15 ]] && BRANCH=${BRANCH}"⋯"
|
|
|
|
if [[ -n $BRANCH ]]; then
|
|
|
|
if [[ -z $(git status --porcelain) ]]; then
|
|
|
|
echo -e "\001\033[38;2;0;64;128m\002\001\033[38;2;255;192;128m\033[48;2;0;64;128m\002 ${BRANCH}\001\033[0m\033[38;2;0;64;128m\002\001\033[0m\002 "
|
|
|
|
else
|
|
|
|
echo -e "\001\033[38;2;128;0;92m\002\001\033[38;2;255;255;192m\033[48;2;128;0;92m\002 ${BRANCH}\001\033[0m\033[38;2;128;0;92m\002\001\033[0m\002 "
|
|
|
|
#echo "$(fgcolor 128 0 92)$(fgcolor 255 255 192)$(bgcolor 128 0 92) ${BRANCH}${ANSI_RESET}\033[38;2;128;0;92m\002\001\033[0m\002 "
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# x
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
ps1_exitstr() {
|
|
|
|
EC=$?
|
|
|
|
if [[ $EC -ne 0 ]]; then
|
|
|
|
#echo -ne "$(fgcolor 192 0 0)${GLYPH_PRE}$(fgcolor 0 0 0)$(bgcolor 192 0 0)${GLYPH_EXIT} $?${ANSI_RESET}$(fgcolor 192 0 0)${GLYPH_SEP} "
|
|
|
|
echo -ne "\001\033[38;2;192;0;0m\002${GLYPH_PRE}\001\033[38;2;0;0;0m\033[48;2;192;0;0m\002${GLYPH_EXIT}\001\033[38;2;255;255;255m\002 ${EC}\001\033[0m\033[38;2;192;0;0m\002${GLYPH_SEP} "
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
ps1_path() {
|
|
|
|
#pwd | sed -e 's/.*\/work\/tickets/⋯/' -e "s/$(echo $HOME | sed -e 's/\//\\\//g')/~/"
|
|
|
|
#pwd | sed -e 's/.*\/work\/tickets/ /' -e "s/$(echo $HOME | sed -e 's/\//\\\//g')/~/"
|
|
|
|
pwd | sed -e 's/.*\/work\/tickets\/*/ /' -e "s/$(echo $HOME | sed -e 's/\//\\\//g')/~/" -e 's/\([^ ]\)$/\1\//'
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ $USER == 'erik' ] || [ $USER == 'erikstambaugh' ]; then
|
|
|
|
PS1="${PARENTSTR}\$(ps1_exitstr)\$(ps1_jobs)"'$(ps1_git)'"$(fgcolor 0 192 255)${SHELLUSER}@\h:$(fgcolor 0 255 127)\$(ps1_path)${ANSI_RESET}\$ "
|
|
|
|
elif [ $USER == 'root' ]; then
|
|
|
|
PS1="${PARENTSTR}\$(ps1_exitstr)\$(ps1_jobs)"'$(ps1_git)'"$(fgcolor 255 72 64)${SHELLUSER}@\h:$(fgcolor 0 255 127)\$(ps1_path)${ANSI_RESET}# "
|
|
|
|
# PS1="${PARENTSTR}"'$(ps1_exitstr)$(ps1_git)'"\[$(fgcolor 255 72 64)\]${SHELLUSER}@\h:\[$(fgcolor 0 255 127)\]\w\[${ANSI_RESET}\]# "
|
|
|
|
else
|
|
|
|
PS1="${PARENTSTR}\$(ps1_exitstr)\$(ps1_jobs)"'$(ps1_git)'"$(fgcolor 255 255 0)${SHELLUSER}@\h:$(fgcolor 0 255 127)\$(ps1_path)${ANSI_RESET}\$ "
|
|
|
|
# PS1="${PARENTSTR}"'$(ps1_exitstr)$(ps1_git)'"\[$(fgcolor 255 255 0)\]${SHELLUSER}@\h:\[$(fgcolor 0 255 0)\]\w\[${ANSI_RESET}\]\$ "
|
|
|
|
fi
|
|
|
|
|
|
|
|
#export PS1 PATH LD_LIBRARY_PATH
|
|
|
|
|
2024-06-13 08:57:52 -07:00
|
|
|
if [[ -n $(which nvim) ]]; then
|
|
|
|
EDITOR=nvim
|
|
|
|
alias vim=nvim
|
|
|
|
else
|
|
|
|
EDITOR=vim
|
|
|
|
fi
|
|
|
|
|
2024-06-11 10:12:11 -07:00
|
|
|
LANG=en_US.UTF-8
|
|
|
|
|
|
|
|
export PS1 PATH HISTSIZE HISTFILESIZE EDITOR LANG
|
|
|
|
|
|
|
|
if [ -e /usr/local/bin/gls ]; then
|
|
|
|
alias ls='/usr/local/bin/gls --color=auto'
|
|
|
|
else
|
|
|
|
alias ls='ls --color=auto'
|
|
|
|
fi
|
|
|
|
|
|
|
|
alias sagi='sudo apt-get install'
|
|
|
|
|
|
|
|
for LOCALPROFILE in /home/$USER/.bash_local_profile /Users/$USER/.bash_local_profile; do
|
|
|
|
if [ -e $LOCALPROFILE ]; then
|
|
|
|
. $LOCALPROFILE
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# let's fix sorting once and for all
|
|
|
|
export LC_COLLATE=C
|
|
|
|
|
|
|
|
|
|
|
|
# tab complete known hosts
|
|
|
|
# http://mybrainhurts.com/blog/2008/11/ssh-tab-completion-on-knownhosts.html
|
|
|
|
# requires: HashKnownHosts no
|
|
|
|
SSH_COMPLETE=( $(cat ~/.ssh/known_hosts 2>/dev/null | cut -f 1 -d " " | \sed -e s/,.*//g | uniq ) ) complete -o default -W "${SSH_COMPLETE[*]}" ssh
|
|
|
|
|
|
|
|
set -o vi
|
|
|
|
|
|
|
|
ccc() {
|
|
|
|
tmux new-window "_ccc $@"
|
|
|
|
}
|
|
|
|
|
|
|
|
_ccc() {
|
|
|
|
|
|
|
|
HOSTS=$(echo $@ | sed -e 's/ -- .*//')
|
|
|
|
ARGS="$(echo $@ | grep -q -- ' -- ' && echo $@ | sed -e 's/.* -- //')"
|
|
|
|
|
|
|
|
for I in $HOSTS; do
|
|
|
|
|
|
|
|
tmux splitw "ssh $ARGS $I"
|
|
|
|
sleep 0.1
|
|
|
|
tmux select-layout tiled
|
|
|
|
|
|
|
|
done
|
|
|
|
tmux set-window-option synchronize-panes on
|
|
|
|
exit
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
# http://stackoverflow.com/a/10660730
|
|
|
|
rawurlencode() {
|
|
|
|
local string="$@"
|
|
|
|
local strlen=${#string}
|
|
|
|
local encoded=""
|
|
|
|
|
|
|
|
for (( pos=0 ; pos<strlen ; pos++ )); do
|
|
|
|
c=${string:$pos:1}
|
|
|
|
case "$c" in
|
|
|
|
[-_.~a-zA-Z0-9] ) o="${c}" ;;
|
|
|
|
* ) printf -v o '%%%02x' "'$c"
|
|
|
|
esac
|
|
|
|
encoded+="${o}"
|
|
|
|
done
|
|
|
|
echo "${encoded}" # You can either set a return variable (FASTER)
|
|
|
|
REPLY="${encoded}" #+or echo the result (EASIER)... or both... :p
|
|
|
|
}
|
|
|
|
|
|
|
|
BROWSER=$(which links2 2>/dev/null || which links 2>/dev/null || which w3m 2>/dev/null || which lynx 2>/dev/null || echo "echo NO BROWSER:")
|
|
|
|
|
|
|
|
google() {
|
|
|
|
GOOGLE_Q=$(rawurlencode "$@")
|
|
|
|
URL="https://www.google.com/search?q=${GOOGLE_Q}"
|
|
|
|
CMD="$BROWSER $URL"
|
|
|
|
$CMD
|
|
|
|
echo $CMD
|
|
|
|
}
|
|
|
|
|
|
|
|
trivia() {
|
|
|
|
LINE=
|
|
|
|
while [[ -z $LINE ]]; do
|
|
|
|
LINE=$(curl -s -L https://en.wikipedia.org/wiki/Special:Random?action=raw \
|
|
|
|
| grep -E '^[0-9a-zA-Z]' \
|
|
|
|
| head -1 \
|
|
|
|
| sed -E \
|
|
|
|
-e "s/'''//g" `# triple quotes ` \
|
|
|
|
-e 's/\[\[([^]]+\|)?([^]]+)\]\]/\2/g' `# replace links with their name ` \
|
|
|
|
-e 's/\{\{[^\}]+\}\}//g' `# remove double-curly blocks ` \
|
|
|
|
-e 's/\[\[|\]\]//g' `# strip any remaining link marks ` \
|
|
|
|
-e 's/\([^)]+\)//g' `# remove parentheticals ` \
|
|
|
|
-e "s/''//g" `# strip double-quotes ` \
|
|
|
|
-e 's/<[^>]+>//g' `# remove HTML/XML tags ` \
|
|
|
|
-e 's/\[[^]]*\]//g' `# remove double-square blocks` \
|
|
|
|
-e 's/\. .*//' `# cut down to first sentence (hopefully) ` \
|
|
|
|
-e 's/ +,/,/g' `# fix spaces before commas; wtf people ` \
|
|
|
|
-e 's/ +/ /g' `# fix double spaces ` \
|
|
|
|
)
|
|
|
|
done
|
|
|
|
|
|
|
|
QUESTION=$(echo "$LINE" | sed -E -e 's/(.*) [^ ]+$/\1 ___?/')
|
|
|
|
ANSWER=$(echo "$LINE" | sed -E -e 's/.* ([^ ]+)$/\1/')
|
|
|
|
echo -n "$QUESTION "
|
|
|
|
read A
|
|
|
|
if [[ $(echo $A | tr A-Z a-z | sed -e 's/[^a-z0-9]//g') == $(echo $ANSWER | tr A-Z a-z | sed -e 's/[^a-z0-9]//g') ]]; then
|
|
|
|
echo "Correct."
|
|
|
|
else
|
|
|
|
echo -e "Wrong. The answer is: $ANSWER"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
old_trivia() {
|
|
|
|
LINE=$(curl -s -L https://en.wikipedia.org/wiki/Special:Random \
|
|
|
|
| grep '^<p' \
|
|
|
|
| sed -E \
|
|
|
|
-e 's/<[^>]*>//g' `# strip HTML tags ` \
|
|
|
|
-e 's/^ +//' `# leading spaces` \
|
|
|
|
-e 's/ +$//' `# trailing spaces` \
|
|
|
|
| grep -v '^$' \
|
|
|
|
| head -1 \
|
|
|
|
| sed -E \
|
|
|
|
-e 's/\&[^;]+//' `# & etc. ` \
|
|
|
|
-e 's/^[^0-9a-zA-Z]+//' `# leading non-alnum` \
|
|
|
|
-e 's/ *\([^)]+\)//g' `# parentheticals` \
|
|
|
|
-e 's/ *\[[^]]*\]//g' `# square braces` \
|
|
|
|
-e 's/\. .*//' `# everything past first sentence` \
|
|
|
|
| grep -v '^$' \
|
|
|
|
| head )
|
|
|
|
QUESTION=$(echo "$LINE" | sed -E -e 's/(.*) [^ ]+$/\1 ___?/')
|
|
|
|
ANSWER=$(echo "$LINE" | sed -E -e 's/.* ([^ ]+)$/\1/')
|
|
|
|
echo -n "$QUESTION "
|
|
|
|
read A
|
|
|
|
if [[ $(echo $A | tr A-Z a-z | sed -e 's/[^a-z0-9]//g') == $(echo $ANSWER | tr A-Z a-z | sed -e 's/[^a-z0-9]//g') ]]; then
|
|
|
|
echo "Correct."
|
|
|
|
else
|
|
|
|
echo -e "Wrong. The answer is: $ANSWER"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
termpipe() {
|
|
|
|
PIPE=$(mktemp -u)
|
|
|
|
mkfifo $PIPE
|
|
|
|
xterm -e less -f $PIPE &
|
|
|
|
cat >$PIPE
|
|
|
|
rm $PIPE
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|