Compare commits

...

2 Commits

Author SHA1 Message Date
Nick Chambers 31e4b86fe3 Setup the initial bash infrastructure 2022-10-14 22:58:23 -05:00
Nick Chambers c8a97a7baf Fix the default files 2022-10-14 22:55:26 -05:00
11 changed files with 204 additions and 2 deletions

3
.bash_profile Normal file
View File

@ -0,0 +1,3 @@
if [[ -f ~/.bashrc ]]; then
. ~/.bashrc
fi

71
.bashrc Normal file
View 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
View File

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) <year> <copyright holders>
Copyright (c) 2022 Nick Chambers <uplime@spookyinternet.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

9
Makefile Normal file
View 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

View File

@ -1,3 +1,3 @@
# dotfiles
Vintage dotfiles aged to perfection.
Vintage dotfiles aged to perfection.

4
dotlib/homebrew.sh Normal file
View 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
View 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
View 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
View 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
View 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
}