summaryrefslogtreecommitdiff
path: root/modules/programs
diff options
context:
space:
mode:
authorDaiderd Jordan <daiderd@gmail.com>2017-01-30 23:04:29 +0100
committerDaiderd Jordan <daiderd@gmail.com>2017-01-30 23:04:29 +0100
commit8cdebe9fa917f9eee42c7276ea6cb654868818f0 (patch)
treef502224a085b4ca0230663ac8f09337464e4d072 /modules/programs
parent0c9710c375adc9c098f23a4a6d88f5c4292a75a0 (diff)
add fzf history keybindings for zsh
Diffstat (limited to 'modules/programs')
-rw-r--r--modules/programs/zsh/default.nix (renamed from modules/programs/zsh.nix)35
-rw-r--r--modules/programs/zsh/fzf-history.zsh28
2 files changed, 42 insertions, 21 deletions
diff --git a/modules/programs/zsh.nix b/modules/programs/zsh/default.nix
index 7f33bf4..688064b 100644
--- a/modules/programs/zsh.nix
+++ b/modules/programs/zsh/default.nix
@@ -26,9 +26,7 @@ in
programs.zsh.enable = mkOption {
type = types.bool;
default = false;
- description = ''
- Whether to configure zsh as an interactive shell.
- '';
+ description = "Whether to configure zsh as an interactive shell.";
};
programs.zsh.variables = mkOption {
@@ -47,49 +45,43 @@ in
programs.zsh.shellInit = mkOption {
type = types.lines;
default = "";
- description = ''
- Shell script code called during zsh shell initialisation.
- '';
+ description = "Shell script code called during zsh shell initialisation.";
};
programs.zsh.loginShellInit = mkOption {
type = types.lines;
default = "";
- description = ''
- Shell script code called during zsh login shell initialisation.
- '';
+ description = "Shell script code called during zsh login shell initialisation.";
};
programs.zsh.interactiveShellInit = mkOption {
type = types.lines;
default = "";
- description = ''
- Shell script code called during interactive zsh shell initialisation.
- '';
+ description = "Shell script code called during interactive zsh shell initialisation.";
};
programs.zsh.promptInit = mkOption {
type = types.lines;
default = "autoload -U promptinit && promptinit && prompt walters";
- description = ''
- Shell script code used to initialise the zsh prompt.
- '';
+ description = "Shell script code used to initialise the zsh prompt.";
};
programs.zsh.enableCompletion = mkOption {
type = types.bool;
default = true;
- description = ''
- Enable zsh completion for all interactive zsh shells.
- '';
+ description = "Enable zsh completion for all interactive zsh shells.";
};
programs.zsh.enableBashCompletion = mkOption {
type = types.bool;
default = true;
- description = ''
- Enable bash completion for all interactive zsh shells.
- '';
+ description = "Enable bash completion for all interactive zsh shells.";
+ };
+
+ programs.zsh.enableFzfHistory = mkOption {
+ type = types.bool;
+ default = true;
+ description = "Enable fzf keybinding for Ctrl-r history search.";
};
};
@@ -144,6 +136,7 @@ in
# This file is read for interactive shells.
bindkey -e
+ ${optionalString cfg.enableFzfHistory "source ${./fzf-history.zsh}"}
# Only execute this file once per shell.
if [ -n "$__ETC_ZSHRC_SOURCED" -o -n "$NOSYSZSHRC" ]; then return; fi
diff --git a/modules/programs/zsh/fzf-history.zsh b/modules/programs/zsh/fzf-history.zsh
new file mode 100644
index 0000000..ba69095
--- /dev/null
+++ b/modules/programs/zsh/fzf-history.zsh
@@ -0,0 +1,28 @@
+__fzf_use_tmux__() {
+ [ -n "$TMUX_PANE" ] && [ "${FZF_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ]
+}
+
+__fzfcmd() {
+ __fzf_use_tmux__ &&
+ echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf"
+}
+
+# CTRL-R - Paste the selected command from history into the command line
+fzf-history-widget() {
+ local selected num
+ setopt localoptions noglobsubst pipefail 2> /dev/null
+ selected=( $(fc -l 1 |
+ FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} $FZF_DEFAULT_OPTS +s --tac -n2..,.. --tiebreak=index --bind=ctrl-r:toggle-sort $FZF_CTRL_R_OPTS --query=${(q)LBUFFER} +m" $(__fzfcmd)) )
+ local ret=$?
+ if [ -n "$selected" ]; then
+ num=$selected[1]
+ if [ -n "$num" ]; then
+ zle vi-fetch-history -n $num
+ fi
+ fi
+ zle redisplay
+ typeset -f zle-line-init >/dev/null && zle zle-line-init
+ return $ret
+}
+zle -N fzf-history-widget
+bindkey '^R' fzf-history-widget