shell: refactor + polish

This commit is contained in:
Henrik Lissner 2016-11-16 15:06:41 +01:00
parent fcc4be6eb6
commit ba11030eae
9 changed files with 33 additions and 29 deletions

View file

@ -1,5 +1,5 @@
# #
# These aliases will be common to Bash and Zsh shells # These aliases are common to Bash and Zsh shells
# #
alias q='exit' alias q='exit'

View file

@ -1,5 +1,3 @@
#!/usr/bin/env bash
CACHE_DIR="$DOTFILES/shell/zsh/cache" CACHE_DIR="$DOTFILES/shell/zsh/cache"
is-callable() { command -v "$1" >/dev/null; } is-callable() { command -v "$1" >/dev/null; }
@ -11,10 +9,10 @@ info() { printf "\r[ \033[00;34m..\033[0m ] $1\n"; }
success() { printf "\r\033[2K[ \033[00;32mOK\033[0m ] $1\n"; } success() { printf "\r\033[2K[ \033[00;32mOK\033[0m ] $1\n"; }
fail() { printf "\r\033[2K[\033[0;31mFAIL\033[0m] $1\n"; echo; exit; } fail() { printf "\r\033[2K[\033[0;31mFAIL\033[0m] $1\n"; echo; exit; }
load () { source "$DOTFILES/$*"; } load () { source "$DOTFILES/$1"; }
loadall () { loadall () {
for file in "$DOTFILES"/$1/*.zsh; do for file in "$DOTFILES"/.enabled.d/${1//\//_}/${2:-*.*sh}; do
source "$file" source "$file"
done done
} }
@ -41,4 +39,4 @@ repo() {
} }
# #
umask 077 load shell/env.sh

11
shell/env.sh Normal file
View file

@ -0,0 +1,11 @@
# Loaded at the end of the initialization process
export PATH="$DOTFILES/bin:$HOME/bin:$PATH"
#
export EDITOR=$(is-callable nvim && echo 'nvim' || echo 'vim')
export VISUAL=$EDITOR
#
export GPG_TTY=$(tty)
umask 077

View file

@ -1,15 +1,18 @@
export DOTFILES="$HOME/.dotfiles" export DOTFILES="$HOME/.dotfiles"
source "$DOTFILES/shell/common.sh" source "$DOTFILES/shell/common.sh"
## Paths ## Paths
# Ensure path arrays do not contain duplicates. # Ensure path arrays do not contain duplicates.
typeset -gU cdpath fpath mailpath path typeset -gU cdpath fpath mailpath path
path=(/usr/local/{,s}bin $path)
load shell/env.sh
loadall shell/zsh env.zsh
path=( path=(
$HOME/.bin
$DOTFILES/bin $DOTFILES/bin
$HOME/bin
/usr/local/{,s}bin
$path $path
) )
@ -18,11 +21,9 @@ fpath=(
$fpath $fpath
) )
export EDITOR=$(is-callable nvim && echo 'nvim' || echo 'vim')
export VISUAL=$EDITOR
export LESS='-g -i -M -R -S -w -z-4' export LESS='-g -i -M -R -S -w -z-4'
if is-callable lesspipe; then if is-callable lesspipe; then
export LESSOPEN='| /usr/bin/env lesspipe %s 2>&-' export LESSOPEN='| /usr/bin/env lesspipe %s 2>&-'
fi fi
[[ -z "$LANG" ]] && export LANG='en_US.UTF-8' [[ $LANG ]] || export LANG='en_US.UTF-8'

View file

@ -1,10 +1,17 @@
### zshrc #!/usr/bin/env zsh
# # zshrc
# By Henrik Lissner <henrik@lissner.net> # By Henrik Lissner <henrik@lissner.net>
#
repo "tarjoilija/zgen" "$HOME/.zgen" repo "tarjoilija/zgen" "$HOME/.zgen"
load shell/zsh/aliases.zsh
load shell/zsh/config.zsh
if is-interactive; then
load shell/zsh/completion.zsh
load shell/zsh/keybinds.zsh
load shell/zsh/prompt.zsh
fi
source "$HOME/.zgen/zgen.zsh" source "$HOME/.zgen/zgen.zsh"
if ! zgen saved; then if ! zgen saved; then
info "Creating zgen save" info "Creating zgen save"
@ -22,12 +29,4 @@ fi
[[ -f "$HOME/.zshrc.local" ]] && source "$HOME/.zshrc.local" [[ -f "$HOME/.zshrc.local" ]] && source "$HOME/.zshrc.local"
for file in $DOTFILES/.enabled.d/*; do
[[ -d "$file/bin" ]] && export PATH="$file/bin:$PATH"
for script in $file/*.zsh; do
source "$script"
done
done
# Done! # Done!

View file

@ -1,5 +1,3 @@
is-interactive || exit
## Options ## Options
setopt COMPLETE_IN_WORD # Complete from both ends of a word. setopt COMPLETE_IN_WORD # Complete from both ends of a word.
setopt PATH_DIRS # Perform path search even on command names with slashes. setopt PATH_DIRS # Perform path search even on command names with slashes.

View file

@ -1,5 +1,3 @@
is-interactive || exit
# Ran into an issue where the surround module wasn't working if KEYTIMEOUT is <= 10. # Ran into an issue where the surround module wasn't working if KEYTIMEOUT is <= 10.
# Specifically, (delete|change)-surround immediately abort into insert mode if # Specifically, (delete|change)-surround immediately abort into insert mode if
# KEYTIMEOUT <= 8, and if <= 10, then add-surround would do the same. At 11, all these # KEYTIMEOUT <= 8, and if <= 10, then add-surround would do the same. At 11, all these

View file

@ -1,7 +1,6 @@
#!/usr/bin/env zsh
# Based off Pure <https://github.com/sindresorhus/pure> # Based off Pure <https://github.com/sindresorhus/pure>
is-interactive || exit
_strlen() { echo ${#${(S%%)1//$~%([BSUbfksu]|([FB]|){*})/}}; } _strlen() { echo ${#${(S%%)1//$~%([BSUbfksu]|([FB]|){*})/}}; }
# fastest possible way to check if repo is dirty # fastest possible way to check if repo is dirty

0
shell/zsh/update Normal file → Executable file
View file