diff --git a/default.nix b/default.nix index 76d0c49..6b64fb5 100644 --- a/default.nix +++ b/default.nix @@ -43,7 +43,7 @@ let ./modules/programs/nix-script.nix ./modules/programs/tmux.nix ./modules/programs/vim.nix - ./modules/programs/zsh.nix + ./modules/programs/zsh ]; }; diff --git a/modules/examples/lnl.nix b/modules/examples/lnl.nix index 0b21939..a5e46d8 100644 --- a/modules/examples/lnl.nix +++ b/modules/examples/lnl.nix @@ -51,7 +51,7 @@ services.nix-daemon.enable = true; services.nix-daemon.tempDir = "/nix/tmp"; - nix.distributedBuilds = true; + # nix.distributedBuilds = true; nix.extraOptions = "pre-build-hook = "; nix.binaryCachePublicKeys = [ "cache.daiderd.com-1:R8KOWZ8lDaLojqD+v9dzXAqGn29gEzPTTbr/GIpCTrI=" ]; @@ -152,6 +152,7 @@ programs.zsh.enable = true; programs.zsh.enableBashCompletion = true; + programs.zsh.enableFzfHistory = true; programs.zsh.variables.cfg = "$HOME/.nixpkgs/darwin-config.nix"; programs.zsh.variables.darwin = "$HOME/.nix-defexpr/darwin"; @@ -184,35 +185,6 @@ bindkey '^[[A' up-line-or-beginning-search zle -N down-line-or-beginning-search zle -N up-line-or-beginning-search - - __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 --toggle-sort=ctrl-r $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 ''; environment.variables.HOMEBREW_CASK_OPTS = "--appdir=/Applications/cask"; diff --git a/modules/programs/zsh.nix b/modules/programs/zsh/default.nix similarity index 84% rename from modules/programs/zsh.nix rename to 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