Commit 4b3fc806 authored by Nicholas Chambers's avatar Nicholas Chambers 👻

Add dotfiles

parent f898150c
if [[ -f ~/.bashrc ]]; then
. ~/.bashrc
fi
###
# PATH
###
__set_PATH() {
local paths path
paths=(
"$HOME"/bin /usr/local/bin
/usr/bin /bin /usr/sbin
/usr/local/sbin /sbin
)
printf -v path %s: "${paths[@]}"
export PATH=${path%:}
}
add_path() {
local path paths
declare -A uniq_paths
declare -a path_list=( )
IFS=: read -ra paths <<< "$PATH"
for path in "$@" "${paths[@]}"; do
if [[ ! -v uniq_paths[$path] ]]; then
uniq_paths[$path]=42
path_list+=("$path")
fi
done
printf -v path %s: "${path_list[@]}"
export PATH=${path%:}
}
__set_PATH
###
# Environment
###
default_shopts=(
nullglob extglob globstar
hostcomplete cmdhist checkhash
checkwinsize dotglob
)
shopt -s "${default_shopts[@]}"
ulimit -c unlimited
export EDITOR="nano -zSET 2"
export PAGER=less
export LESSHISTFILE=-
export HISTCONTROL=ignoreboth
if [[ -d ~/.rvm && -s ~/.rvm/scripts/rvm ]]; then
. ~/.rvm/scripts/rvm
add_path ~/.rvm/bin
fi
###
# Happy Holidays
###
read -r month day < <(date '+%m %d')
if (( 10#$month == 3 && 10#$day < 18 )); then
if (( 17 - 10#$day == 0 )); then
printf 'Happy Saint Patrick%ss day!\n' \'
else
printf 'Only %d days left until Saint Patrick%ss day!\n' "$(( 17 - 10#$day ))" \'
fi
holiday=🍀
elif (( 10#$month == 10 )); then
if (( 31 - 10#$day == 0 )); then
printf 'Have a spooky halloween!\n'
else
printf 'Only %d days left until Halloween!\n' "$(( 31 - 10#$day ))"
fi
holiday=🎃
elif (( 10#$month == 12 && 10#$day < 26 )); then
if (( 25 - 10#$day == 0 )); then
printf 'Merry Christmas!\n'
else
printf 'Only %d days left until Christmas!\n' "$(( 25 - 10#$day ))"
fi
holiday=🌲
fi
###
# prettyifiers
###
colorize() {
printf '\001%s\002' "$(tput bold)" "$(tput setaf "$1")"
printf %s "$2"
printf '\001%s\002' "$(tput sgr0)"
}
red() {
colorize 1 "$@"
}
green() {
colorize 2 "$@"
}
yellow() {
colorize 3 "$@"
}
blue() {
colorize 4 "$@"
}
purple() {
colorize 5 "$@"
}
if [[ -x /usr/bin/dircolors ]]; then
if [[ -f ~/.dircolors ]]; then
eval "$(dircolors -b ~/.dircolors)"
else
eval "$(dircolors -b)"
fi
fi
###
# Prompt
###
PROMPT_COMMAND='tput sgr0'
PS1='$(red "[\u@\h")$(purple :)$(green "\w"])'
if [[ -v holiday ]]; then
PS1+='$holiday '
elif [[ $HOSTNAME = pod-@(101294|150341) ]]; then
PS1+='🎉 '
else
PS1+='$(purple \$) '
fi
###
# Completion
###
_ssh_hosts() {
mapfile -t hosts < <(awk 'tolower($1) == "host" { print $2 }' ~/.ssh/config)
mapfile -t COMPREPLY < <(compgen -W "${hosts[*]}" -- "${COMP_WORDS[COMP_CWORD]}")
return 0
}
complete -o default -F _ssh_hosts ssh scp ssh-copy-id sftp
###
# Utilities
###
ls() {
command ls "$@"
}
grep() {
command grep "$@"
}
ll() {
ls -AlF "$@"
}
awk-find() {
if (( $# > 1 )); then
local find_in=${TO_FIND:-.} file pattern=$1 to_find=( )
for file in "${@:2}"; do
to_find+=(-name "$file" -o)
done
find "$find_in" -not -name . "(" "${to_find[@]::${#to_find[@]} - 1}" ")" -print0 |
awk -F / -v RS="\0" "$pattern"
fi
}
clbin() {
tail -n +1 -- "$@" | curl -sSF 'clbin=<-' https://clbin.com
}
args() {
local arg count
printf 'total arguments: %d\n' "$#"
for arg do
printf 'argument %03d: %s\n' "$(( ++count ))" "$arg"
done
}
:D() {
printf ':D\n'
}
dadjoke() {
curl -sSH "Accept: text/plain" https://icanhazdadjoke.com; echo
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment