Update rc init scripts

- Move system specific setup to rc.$SYS scripts
- Write configure_ls function (based on previous anonymous function) that takes the full path to an ls binary
- Create system specific script for FreeBSD (nothing in it yet)
This commit is contained in:
Eryn Wells 2013-09-04 20:26:10 -07:00
parent a11db44f43
commit 9ea891311c
4 changed files with 61 additions and 34 deletions

65
rc
View file

@ -37,45 +37,30 @@ function g
} }
print_info -l 2 "Sourcing ${SYS}-specific settings" function configure_ls
case $SYS in {
darwin) local has_gnu_ls
alias acls='command ls -le' local ls_options
# These things might have been installed by Homebrew
binary_exists gdircolors && alias dircolors='gdircolors'
binary_exists gfind && alias find='gfind'
binary_exists gnuindent && alias indent='gnuindent'
;;
linux)
# iptables aliases
alias iptls='sudo iptables --line-numbers -nv -L'
alias ip6tls='sudo ip6tables --line-numbers -nv -L'
alias rlx="xrdb $HOME/.Xdefaults"
;;
*)
print_error "What system %Bis%b this, anyway?"
;;
esac
function { if [[ ! -e "$1" ]]; then
local has_gnu_ls=1 return
local lsbin='ls' fi
local ls_options='--color=auto'
if binary_exists gls; then if $1 --version 2>&1 | grep GNU 1>/dev/null; then
lsbin='gls' has_gnu_ls=1
ls_options='--color=auto'
else else
has_gnu_ls=0 has_gnu_ls=0
ls_options='-G' ls_options='-G'
fi fi
print_info_sub -l 3 "Setting up ls: `which $lsbin`" print_info_sub -l 3 "Setting up ls: $1"
alias ls="$lsbin $ls_options" alias ls="$1 $ls_options"
alias la="$lsbin -A $ls_options" alias la="$1 -A $ls_options"
alias ll="$lsbin -l $ls_options" alias ll="$1 -l $ls_options"
alias l.="$lsbin -d $ls_options .*" alias l.="$1 -d $ls_options .*"
if [[ $has_gnu_ls -eq 1 ]]; then if [[ $has_gnu_ls -eq 1 ]] && binary_exists dircolors; then
if [[ -e "$HOME/.dircolors/$SYS.cfg" ]]; then if [[ -e "$HOME/.dircolors/$SYS.cfg" ]]; then
dircolors="$HOME/.dircolors/$SYS.cfg" dircolors="$HOME/.dircolors/$SYS.cfg"
else else
@ -86,6 +71,7 @@ function {
fi fi
} }
# NetHack options # NetHack options
# use color in the terminal # use color in the terminal
binary_exists nethack && export NETHACKOPTIONS="color" binary_exists nethack && export NETHACKOPTIONS="color"
@ -94,7 +80,18 @@ binary_exists nethack && export NETHACKOPTIONS="color"
[[ -e "$HOME/Documents/Financial/personal.ledger" ]] && \ [[ -e "$HOME/Documents/Financial/personal.ledger" ]] && \
LEDGER_FILE=$HOME/Documents/Financial/personal.ledger LEDGER_FILE=$HOME/Documents/Financial/personal.ledger
if [ -e $HOME/.rc.local ]; then
print_info -l 2 'Sourcing local interactive shell setup' if [[ -e "$HOME/.rc.$SYS" ]]; then
source $HOME/.rc.local print_info -l 2 "Sourcing interactive shell setup for $SYS systems"
source "$HOME/.rc.$SYS"
fi
# Set up ls if it wasn't already done.
if ! alias ls 2>&1 1>/dev/null; then
configure_ls `which ls`
fi
if [[ -e "$HOME/.rc.local" ]]; then
print_info -l 2 'Sourcing local interactive shell setup'
source "$HOME/.rc.local"
fi fi

16
rc.darwin Normal file
View file

@ -0,0 +1,16 @@
# .rc.darwin
# vim: ft=zsh
# Interactive shell setup for Darwin systems
# Eryn Wells <eryn@erynwells.me>
alias acls='command ls -le'
# These things might have been installed by Homebrew, and I like the GNU versions better.
binary_exists gdircolors && alias dircolors='gdircolors'
binary_exists gfind && alias find='gfind'
binary_exists gnuindent && alias indent='gnuindent'
if binary_exists gls; then
configure_ls `which gls`
fi

4
rc.freebsd Normal file
View file

@ -0,0 +1,4 @@
# .rc.freebsd
# vim: ft=zsh
# Interactive shell setup for FreeBSD systems
# Eryn Wells <eryn@erynwells.me>

10
rc.linux Normal file
View file

@ -0,0 +1,10 @@
# .rc.linux
# vim: ft=zsh
# Interactive shell setup for Linux systems
# Eryn Wells <eryn@erynwells.me>
# iptables aliases
alias iptls='sudo iptables --line-numbers -nv -L'
alias ip6tls='sudo ip6tables --line-numbers -nv -L'
alias rlx="xrdb $HOME/.Xdefaults"