diff --git a/.bash_profile b/.bash_profile new file mode 100644 index 0000000..a4e91a7 --- /dev/null +++ b/.bash_profile @@ -0,0 +1,3 @@ +if [[ -f ~/.bashrc ]]; then + . ~/.bashrc +fi diff --git a/.bashrc b/.bashrc new file mode 100644 index 0000000..e1442c3 --- /dev/null +++ b/.bashrc @@ -0,0 +1,71 @@ +if [[ $- != *i* ]]; then + return +fi + +### +# Default Environment +### + +__set_PATH() { + local path paths=("$HOME"/bin {/usr{/local,},}/{,s}bin) + printf -v path %s: "${paths[@]}" + export PATH=${path%:} +} + +__set_ENV() { + local var + + declare -A env=( + [EDITOR]=nano + [PAGER]=less + [LESSHISTFILE]=- + [HISTCONTROL]=ignoreboth + ) + + for var in "${!env[@]}"; do + export "$var"="${env[$var]}" + done +} + +__set_SHOPTS() { + local shopts=( + {null,ext,dot}glob globstar cmdhist + hostcomplete checkwinsize checkhash + ) + + shopt -s "${shopts[@]}" +} + +__set_PATH +__set_ENV +__set_SHOPTS + +ulimit -c unlimited + +### +# Search Path Manager +### + +add_path() { + local path paths path_list=( ) + declare -A uniq_paths + 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%:} +} + +### +# Library loader +### + +for dot in ~/bin/dotlib/*.sh; do + . "$dot" +done diff --git a/.hushlogin b/.hushlogin new file mode 100644 index 0000000..e69de29 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4c782b4 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +install: ~/.bash_profile ~/.bashrc + mkdir -p ~/bin/dotlib + cp -r dotlib/*.sh ~/bin/dotlib + +~/.bash_profile: .bash_profile + cp -f .bash_profile ~/.bash_profile + +~/.bashrc: .bashrc + cp -f .bashrc ~/.bashrc diff --git a/dotlib/homebrew.sh b/dotlib/homebrew.sh new file mode 100644 index 0000000..32ec697 --- /dev/null +++ b/dotlib/homebrew.sh @@ -0,0 +1,4 @@ +export HOMEBREW_NO_AUTO_UPDATE=grrr +export HOMEBREW_NO_ANALYTICS=lol +export HOMEBREW_NO_ENV_HINTS=thunderfury +export HOMEBREW_NO_INSECURE_REDIRECT=pirates diff --git a/dotlib/prompt.sh b/dotlib/prompt.sh new file mode 100644 index 0000000..aad9f8a --- /dev/null +++ b/dotlib/prompt.sh @@ -0,0 +1,50 @@ +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's day!\n" + else + printf "Only %d days left until Saint Patrick's 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 + +setup-prompt() { + tput sgr0 + + if [[ -d .git ]]; then + git_branch=" $(command git branch --show-current)" + else + git_branch= + fi +} + +PROMPT_COMMAND=setup-prompt +PS1='\w$git_branch' + +if [[ -v SSH_CLIENT ]]; then + if [[ -v HOSTNAME ]]; then + PS1+=' $HOSTNAME' + else + PS1+=' $(hostname)' + fi +fi + +PS1+=' ${holiday-λ} ' diff --git a/dotlib/ruby.sh b/dotlib/ruby.sh new file mode 100644 index 0000000..af2b95e --- /dev/null +++ b/dotlib/ruby.sh @@ -0,0 +1,4 @@ +if [[ -d ~/.rvm && -s ~/.rvm/scripts/rvm ]]; then + . ~/.rvm/scripts/rvm + add_path ~/.rvm/bin +fi diff --git a/dotlib/tab.sh b/dotlib/tab.sh new file mode 100644 index 0000000..0cadebd --- /dev/null +++ b/dotlib/tab.sh @@ -0,0 +1,37 @@ +_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 + +_make_targets() { + local arg prev file targets + + if [[ -f makefile ]]; then + file=makefile + elif [[ -f Makefile ]]; then + file=Makefile + fi + + for arg in "${COMP_WORDS[@]}"; do + if [[ $prev = -f ]]; then + file=$arg + elif [[ $arg = -f* ]]; then + file=${arg#-f} + fi + + prev=$arg + done + + mapfile -t targets < <( + awk '$1 ~ /:$/ && $1 !~ /^\./ { gsub(/:$/, "", $1); print $1 }' "$file" + ) + + mapfile -t COMPREPLY < <( + compgen -W "${targets[*]}" -- "${COMP_WORDS[COMP_CWORD]}" + ) +} + +complete -o default -F _make_targets make gmake diff --git a/dotlib/util.sh b/dotlib/util.sh new file mode 100644 index 0000000..cca3f7a --- /dev/null +++ b/dotlib/util.sh @@ -0,0 +1,24 @@ +### +# Utilities +### + +ll() { + command ls -AlF "$@" +} + +ssh() { + TERM=xterm-256color command ssh "$@" +} + +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 +}