Setup the initial bash infrastructure
This commit is contained in:
parent
c8a97a7baf
commit
31e4b86fe3
9 changed files with 202 additions and 0 deletions
3
.bash_profile
Normal file
3
.bash_profile
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
if [[ -f ~/.bashrc ]]; then
|
||||||
|
. ~/.bashrc
|
||||||
|
fi
|
71
.bashrc
Normal file
71
.bashrc
Normal file
|
@ -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
|
0
.hushlogin
Normal file
0
.hushlogin
Normal file
9
Makefile
Normal file
9
Makefile
Normal file
|
@ -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
|
4
dotlib/homebrew.sh
Normal file
4
dotlib/homebrew.sh
Normal file
|
@ -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
|
50
dotlib/prompt.sh
Normal file
50
dotlib/prompt.sh
Normal file
|
@ -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-λ} '
|
4
dotlib/ruby.sh
Normal file
4
dotlib/ruby.sh
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
if [[ -d ~/.rvm && -s ~/.rvm/scripts/rvm ]]; then
|
||||||
|
. ~/.rvm/scripts/rvm
|
||||||
|
add_path ~/.rvm/bin
|
||||||
|
fi
|
37
dotlib/tab.sh
Normal file
37
dotlib/tab.sh
Normal file
|
@ -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
|
24
dotlib/util.sh
Normal file
24
dotlib/util.sh
Normal file
|
@ -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
|
||||||
|
}
|
Loading…
Reference in a new issue