fork/home-manager
git clone https://git.julia.blue/fork/home-manager
84fa81c7
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . programs . fzf ; 8 9renderedColors = colors : 10concatStringsSep "," 11( mapAttrsToList ( name :value :" ${ name } : ${ value } " ) colors ); 12 13in { 14imports = [ 15( mkRemovedOptionModule [ "programs" "fzf" "historyWidgetCommand" ] 16"This option is no longer supported by fzf." ) 17]; 18 19options . programs . fzf = { 20enable = mkEnableOption "fzf - a command-line fuzzy finder" ; 21 22package = mkOption { 23type = types . package ; 24default = pkgs . fzf ; 25defaultText = literalExpression "pkgs.fzf" ; 26description = "Package providing the {command}`fzf` tool." ; 27}; 28 29defaultCommand = mkOption { 30type = types . nullOr types . str ; 31default = null ; 32example = "fd --type f" ; 33description = '' 34The command that gets executed as the default source for fzf 35when running. 36'' ; 37}; 38 39defaultOptions = mkOption { 40type = types . listOf types . str ; 41default = [ ]; 42example = [ "--height 40%" "--border" ]; 43description = '' 44Extra command line options given to fzf by default. 45'' ; 46}; 47 48fileWidgetCommand = mkOption { 49type = types . nullOr types . str ; 50default = null ; 51example = "fd --type f" ; 52description = '' 53The command that gets executed as the source for fzf for the 54CTRL-T keybinding. 55'' ; 56}; 57 58fileWidgetOptions = mkOption { 59type = types . listOf types . str ; 60default = [ ]; 61example = [ "--preview 'head {}'" ]; 62description = '' 63Command line options for the CTRL-T keybinding. 64'' ; 65}; 66 67changeDirWidgetCommand = mkOption { 68type = types . nullOr types . str ; 69default = null ; 70example = "fd --type d" ; 71description = '' 72The command that gets executed as the source for fzf for the 73ALT-C keybinding. 74'' ; 75}; 76 77changeDirWidgetOptions = mkOption { 78type = types . listOf types . str ; 79default = [ ]; 80example = [ "--preview 'tree -C {} | head -200'" ]; 81description = '' 82Command line options for the ALT-C keybinding. 83'' ; 84}; 85 86historyWidgetOptions = mkOption { 87type = types . listOf types . str ; 88default = [ ]; 89example = [ "--sort" "--exact" ]; 90description = '' 91Command line options for the CTRL-R keybinding. 92'' ; 93}; 94 95colors = mkOption { 96type = types . attrsOf types . str ; 97default = { }; 98example = literalExpression '' 99{ 100bg = "#1e1e1e"; 101"bg+" = "#1e1e1e"; 102fg = "#d4d4d4"; 103"fg+" = "#d4d4d4"; 104} 105'' ; 106description = '' 107Color scheme options added to `FZF_DEFAULT_OPTS`. See 108<https://github.com/junegunn/fzf/wiki/Color-schemes> 109for documentation. 110'' ; 111}; 112 113tmux = { 114enableShellIntegration = mkEnableOption '' 115setting `FZF_TMUX=1` which causes shell integration to use fzf-tmux 116'' ; 117 118shellIntegrationOptions = mkOption { 119type = types . listOf types . str ; 120default = [ ]; 121example = literalExpression ''[ "-d 40%" ]'' ; 122description = '' 123If {option}`programs.fzf.tmux.enableShellIntegration` is set to `true`, 124shell integration will use these options for fzf-tmux. 125See {command}`fzf-tmux --help` for available options. 126'' ; 127}; 128}; 129 130enableBashIntegration = mkOption { 131default = true ; 132type = types . bool ; 133description = '' 134Whether to enable Bash integration. 135'' ; 136}; 137 138enableZshIntegration = mkOption { 139default = true ; 140type = types . bool ; 141description = '' 142Whether to enable Zsh integration. 143'' ; 144}; 145 146enableFishIntegration = mkOption { 147default = true ; 148type = types . bool ; 149description = '' 150Whether to enable Fish integration. 151'' ; 152}; 153}; 154 155config = mkIf cfg . enable { 156home . packages = [ cfg . package ]; 157 158home . sessionVariables = mapAttrs ( n :v :toString v ) 159( filterAttrs ( n :v :v != [ ] && v != null ) { 160FZF_ALT_C_COMMAND = cfg . changeDirWidgetCommand ; 161FZF_ALT_C_OPTS = cfg . changeDirWidgetOptions ; 162FZF_CTRL_R_OPTS = cfg . historyWidgetOptions ; 163FZF_CTRL_T_COMMAND = cfg . fileWidgetCommand ; 164FZF_CTRL_T_OPTS = cfg . fileWidgetOptions ; 165FZF_DEFAULT_COMMAND = cfg . defaultCommand ; 166FZF_DEFAULT_OPTS = cfg . defaultOptions 167++ lib . optionals ( cfg . colors != { }) 168[ "--color ${ renderedColors cfg . colors } " ]; 169FZF_TMUX = if cfg . tmux . enableShellIntegration then "1" else null ; 170FZF_TMUX_OPTS = cfg . tmux . shellIntegrationOptions ; 171}); 172 173# Note, since fzf unconditionally binds C-r we use `mkOrder` to make the 174# initialization show up a bit earlier. This is to make initialization of 175# other history managers, like mcfly or atuin, take precedence. 176programs . bash . initExtra = mkIf cfg . enableBashIntegration ( mkOrder 200 '' 177if [[ :$SHELLOPTS: =~ :(vi|emacs): ]]; then 178. ${ cfg . package } /share/fzf/completion.bash 179. ${ cfg . package } /share/fzf/key-bindings.bash 180fi 181'' ); 182 183# Note, since fzf unconditionally binds C-r we use `mkOrder` to make the 184# initialization show up a bit earlier. This is to make initialization of 185# other history managers, like mcfly or atuin, take precedence. 186programs . zsh . initExtra = mkIf cfg . enableZshIntegration ( mkOrder 200 '' 187if [[ $options[zle] = on ]]; then 188. ${ cfg . package } /share/fzf/completion.zsh 189. ${ cfg . package } /share/fzf/key-bindings.zsh 190fi 191'' ); 192 193programs . fish . interactiveShellInit = mkIf cfg . enableFishIntegration 194( mkOrder 200 '' 195source ${ cfg . package } /share/fzf/key-bindings.fish && fzf_key_bindings 196'' ); 197}; 198}