1
1
mirror of https://github.com/divnix/digga.git synced 2024-12-23 16:11:51 +03:00

develop#zsh: factor out functions into files

Upgrade the `rg` function to only pipe to `PAGER` when output is a
terminal.
This commit is contained in:
Timothy DeHerrera 2019-12-15 20:54:11 -07:00
parent 42197cd35c
commit 6139834a4a
No known key found for this signature in database
GPG Key ID: 8985725DB5B0C122
6 changed files with 58 additions and 56 deletions

View File

@ -73,7 +73,7 @@ in
interactiveShellInit = let
zshrc = fileContents ./zshrc;
paths = with pkgs; [
sources = with pkgs; [
"${skim}/share/skim/completion.zsh"
"${oh-my-zsh}/share/oh-my-zsh/plugins/sudo/sudo.plugin.zsh"
"${oh-my-zsh}/share/oh-my-zsh/plugins/extract/extract.plugin.zsh"
@ -82,8 +82,28 @@ in
];
source = map
(source: "source " + source)
paths;
(source: "source ${source}")
sources;
functions = pkgs.stdenv.mkDerivation {
name = "zsh-functions";
src = ./functions;
ripgrep = "${pkgs.ripgrep}";
man = "${pkgs.man}";
installPhase = let
basename = "\${file##*/}";
in
''
mkdir $out
for file in $src/*; do
substituteAll $file $out/${basename}
chmod 755 $out/${basename}
done
'';
};
plugins = concatStringsSep "\n"
(
@ -98,8 +118,13 @@ in
''
${plugins}
fpath+=( ${functions} )
autoload -Uz ${functions}/*(:t)
${zshrc}
eval "$(${pkgs.direnv}/bin/direnv hook zsh)"
eval $(${pkgs.gitAndTools.hub}/bin/hub alias -s)
source ${pkgs.skim}/share/skim/key-bindings.zsh
'';
};

View File

@ -0,0 +1,8 @@
# colorful man pages
LESS_TERMCAP_md=$'\e[01;31m' \
LESS_TERMCAP_me=$'\e[0m' \
LESS_TERMCAP_se=$'\e[0m' \
LESS_TERMCAP_so=$'\e[01;44;33m' \
LESS_TERMCAP_ue=$'\e[0m' \
LESS_TERMCAP_us=$'\e[01;32m' \
@man@/bin/man "$@"

View File

@ -0,0 +1,2 @@
# mkdir & cd to it
mkdir -p "$1" && cd "$1"

View File

@ -0,0 +1,6 @@
# pipe rg into less with colors
if [[ -t 1 && -n $PAGER ]]; then
@ripgrep@/bin/rg -p $@ | $PAGER
else
@ripgrep@/bin/rg $@
fi

View File

@ -1,3 +1,4 @@
# tilde directories
hash -d \
nixos=/etc/nixos \
dl=~/Downloads \
@ -7,9 +8,6 @@ hash -d \
github=~git/github.com \
gitlab=~git/gitlab.com
# hub setup
eval $(hub alias -s)
# Zsh options
setopt extendedglob
setopt incappendhistory
@ -31,50 +29,32 @@ SAVEHIST=10000
HISTFILE=$HOME/.history
DIRSTACKSIZE=5
# user defined functions
if [[ -d $HOME/.zfunctions ]]; then
typeset -U fpath
fpath=($HOME/.zfunctions $fpath)
for file in $HOME/.zfunctions/*; do
autoload -Uz $file
done
fi
# source local config not synced to git repo
if [[ -f $HOME/.zshlocal ]]; then
. $HOME/.zshlocal
fi
# create local zshrc if it does not exist
[[ -f $HOME/.zshrc ]] \
|| printf "#" > $HOME/.zshrc
# history substring search keybinds
bindkey '^[OA' history-substring-search-up
bindkey '^[OB' history-substring-search-down
bindkey -M vicmd 'k' history-substring-search-up
bindkey -M vicmd 'j' history-substring-search-down
zle -N zle-line-init
# if in tmux launch skim in tmux pane
[[ ${+TMUX} == 1 ]] \
&& SKIM_TMUX=1
#load compinit
autoload -Uz compinit
typeset -i updated_at=$(date +'%j' -r ~/.zcompdump ||
stat -f '%Sm' -t '%j' ~/.zcompdump)
typeset -i updated_at=$(date +'%j' -r ~/.zcompdump \
|| stat -f '%Sm' -t '%j' ~/.zcompdump)
# save time if completion cache has been update recently
if [ $(date +'%j') != $updated_at ]; then
compinit
compinit
else
compinit -C
compinit -C
fi
# Case insens only when no case match; after all completions loaded
zstyle ':completion:*' matcher-list \
"" 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
"" 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
# Auto rehash for new binaries
zstyle ':completion:*' rehash true
@ -83,29 +63,9 @@ zstyle ':completion:*' rehash true
bindkey "jj" vi-cmd-mode
bindkey -v '^?' backward-delete-char
# remove duplicates from paths
typeset -U path
typeset -U fpath
# keep shell state frozen
ttyctl -f
# colorful man pages
man () {
LESS_TERMCAP_md=$'\e[01;31m' \
LESS_TERMCAP_me=$'\e[0m' \
LESS_TERMCAP_se=$'\e[0m' \
LESS_TERMCAP_so=$'\e[01;44;33m' \
LESS_TERMCAP_ue=$'\e[0m' \
LESS_TERMCAP_us=$'\e[01;32m' \
command man "$@"
}
# pipe rg into less with colors
rgl () {
rg --color=always $@ | less
}
# mkdir & cd to it
function mcd() {
mkdir -p "$1" && cd "$1";
}
# direnv setup
eval "$(direnv hook zsh)"

View File

@ -24,6 +24,7 @@ in
file = {
".ec2-keys".source = ../secrets/ec2;
".cargo/credentials".source = ../secrets/cargo;
".zshrc".text = "#";
};
};