feat: expanded fish configuration
Refactored fish configuration values into separate directory Created fish init shell code for nh and zoxide Reverted removal of cd=z alias since it works now
This commit is contained in:
parent
dbba4a63e0
commit
28506968d7
5 changed files with 258 additions and 4 deletions
|
@ -1,6 +1,6 @@
|
||||||
{pkgs}: {
|
{pkgs}: {
|
||||||
#cd = "z";
|
cd = "z";
|
||||||
#cdi = "zi";
|
cdi = "zi";
|
||||||
ls = "${pkgs.eza}/bin/exa";
|
ls = "${pkgs.eza}/bin/exa";
|
||||||
cat = "${pkgs.bat}/bin/bat";
|
cat = "${pkgs.bat}/bin/bat";
|
||||||
ll = "ls -l";
|
ll = "ls -l";
|
||||||
|
|
|
@ -9,7 +9,7 @@ in
|
||||||
with lib; {
|
with lib; {
|
||||||
imports = [
|
imports = [
|
||||||
./zsh.nix
|
./zsh.nix
|
||||||
./fish.nix
|
./fish
|
||||||
./zoxide.nix
|
./zoxide.nix
|
||||||
./direnv.nix
|
./direnv.nix
|
||||||
./starship
|
./starship
|
||||||
|
|
|
@ -13,7 +13,11 @@ in
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
programs.fish = {
|
programs.fish = {
|
||||||
enable = true;
|
enable = true;
|
||||||
shellAliases = import ./aliases {inherit pkgs;};
|
shellInit = ''
|
||||||
|
${builtins.readFile ./init/zoxide.fish}
|
||||||
|
${builtins.readFile ./init/nh.fish}
|
||||||
|
'';
|
||||||
|
shellAliases = import ../aliases {inherit pkgs;};
|
||||||
plugins = [
|
plugins = [
|
||||||
{
|
{
|
||||||
name = "z";
|
name = "z";
|
145
home-manager/stvnliu/shells/fish/init/nh.fish
Normal file
145
home-manager/stvnliu/shells/fish/init/nh.fish
Normal file
|
@ -0,0 +1,145 @@
|
||||||
|
# Print an optspec for argparse to handle cmd's options that are independent of any subcommand.
|
||||||
|
function __fish_nh_global_optspecs
|
||||||
|
string join \n v/verbose h/help V/version
|
||||||
|
end
|
||||||
|
|
||||||
|
function __fish_nh_needs_command
|
||||||
|
# Figure out if the current invocation already has a command.
|
||||||
|
set -l cmd (commandline -opc)
|
||||||
|
set -e cmd[1]
|
||||||
|
argparse -s (__fish_nh_global_optspecs) -- $cmd 2>/dev/null
|
||||||
|
or return
|
||||||
|
if set -q argv[1]
|
||||||
|
# Also print the command, so this can be used to figure out what it is.
|
||||||
|
echo $argv[1]
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
function __fish_nh_using_subcommand
|
||||||
|
set -l cmd (__fish_nh_needs_command)
|
||||||
|
test -z "$cmd"
|
||||||
|
and return 1
|
||||||
|
contains -- $cmd[1] $argv
|
||||||
|
end
|
||||||
|
|
||||||
|
complete -c nh -n "__fish_nh_needs_command" -s v -l verbose -d 'Show debug logs'
|
||||||
|
complete -c nh -n "__fish_nh_needs_command" -s h -l help -d 'Print help'
|
||||||
|
complete -c nh -n "__fish_nh_needs_command" -s V -l version -d 'Print version'
|
||||||
|
complete -c nh -n "__fish_nh_needs_command" -f -a "os" -d 'NixOS functionality'
|
||||||
|
complete -c nh -n "__fish_nh_needs_command" -f -a "home" -d 'Home-manager functionality'
|
||||||
|
complete -c nh -n "__fish_nh_needs_command" -f -a "search" -d 'Searches packages by querying search.nixos.org'
|
||||||
|
complete -c nh -n "__fish_nh_needs_command" -f -a "clean" -d 'Enhanced nix cleanup'
|
||||||
|
complete -c nh -n "__fish_nh_needs_command" -f -a "completions" -d 'Generate shell completion files into stdout'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and not __fish_seen_subcommand_from switch boot test build info" -s v -l verbose -d 'Show debug logs'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and not __fish_seen_subcommand_from switch boot test build info" -s h -l help -d 'Print help (see more with \'--help\')'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and not __fish_seen_subcommand_from switch boot test build info" -f -a "switch" -d 'Build and activate the new configuration, and make it the boot default'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and not __fish_seen_subcommand_from switch boot test build info" -f -a "boot" -d 'Build the new configuration and make it the boot default'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and not __fish_seen_subcommand_from switch boot test build info" -f -a "test" -d 'Build and activate the new configuration'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and not __fish_seen_subcommand_from switch boot test build info" -f -a "build" -d 'Build the new configuration'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and not __fish_seen_subcommand_from switch boot test build info" -f -a "info" -d 'Show an overview of the system\'s info'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from switch" -s D -l diff-provider -d 'Closure diff provider' -r
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from switch" -s H -l hostname -d 'Output to choose from the flakeref. Hostname is used by default' -r
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from switch" -s s -l specialisation -d 'Name of the specialisation' -r
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from switch" -s n -l dry -d 'Only print actions, without performing them'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from switch" -s a -l ask -d 'Ask for confirmation'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from switch" -s u -l update -d 'Update flake inputs before building specified configuration'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from switch" -l no-nom -d 'Don\'t use nix-output-monitor for the build process'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from switch" -s S -l no-specialisation -d 'Don\'t use specialisations'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from switch" -s v -l verbose -d 'Show debug logs'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from switch" -s h -l help -d 'Print help (see more with \'--help\')'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from boot" -s D -l diff-provider -d 'Closure diff provider' -r
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from boot" -s H -l hostname -d 'Output to choose from the flakeref. Hostname is used by default' -r
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from boot" -s s -l specialisation -d 'Name of the specialisation' -r
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from boot" -s n -l dry -d 'Only print actions, without performing them'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from boot" -s a -l ask -d 'Ask for confirmation'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from boot" -s u -l update -d 'Update flake inputs before building specified configuration'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from boot" -l no-nom -d 'Don\'t use nix-output-monitor for the build process'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from boot" -s S -l no-specialisation -d 'Don\'t use specialisations'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from boot" -s v -l verbose -d 'Show debug logs'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from boot" -s h -l help -d 'Print help (see more with \'--help\')'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from test" -s D -l diff-provider -d 'Closure diff provider' -r
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from test" -s H -l hostname -d 'Output to choose from the flakeref. Hostname is used by default' -r
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from test" -s s -l specialisation -d 'Name of the specialisation' -r
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from test" -s n -l dry -d 'Only print actions, without performing them'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from test" -s a -l ask -d 'Ask for confirmation'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from test" -s u -l update -d 'Update flake inputs before building specified configuration'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from test" -l no-nom -d 'Don\'t use nix-output-monitor for the build process'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from test" -s S -l no-specialisation -d 'Don\'t use specialisations'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from test" -s v -l verbose -d 'Show debug logs'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from test" -s h -l help -d 'Print help (see more with \'--help\')'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from build" -s D -l diff-provider -d 'Closure diff provider' -r
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from build" -s H -l hostname -d 'Output to choose from the flakeref. Hostname is used by default' -r
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from build" -s s -l specialisation -d 'Name of the specialisation' -r
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from build" -s n -l dry -d 'Only print actions, without performing them'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from build" -s a -l ask -d 'Ask for confirmation'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from build" -s u -l update -d 'Update flake inputs before building specified configuration'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from build" -l no-nom -d 'Don\'t use nix-output-monitor for the build process'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from build" -s S -l no-specialisation -d 'Don\'t use specialisations'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from build" -s v -l verbose -d 'Show debug logs'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from build" -s h -l help -d 'Print help (see more with \'--help\')'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from info" -s v -l verbose -d 'Show debug logs'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand os; and __fish_seen_subcommand_from info" -s h -l help -d 'Print help'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand home; and not __fish_seen_subcommand_from switch build info" -s v -l verbose -d 'Show debug logs'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand home; and not __fish_seen_subcommand_from switch build info" -s h -l help -d 'Print help'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand home; and not __fish_seen_subcommand_from switch build info" -f -a "switch" -d 'Build and activate a home-manager configuration'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand home; and not __fish_seen_subcommand_from switch build info" -f -a "build" -d 'Build a home-manager configuration'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand home; and not __fish_seen_subcommand_from switch build info" -f -a "info" -d 'Show an overview of the installation'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand home; and __fish_seen_subcommand_from switch" -s D -l diff-provider -d 'Closure diff provider' -r
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand home; and __fish_seen_subcommand_from switch" -s c -l configuration -d 'Name of the flake homeConfigurations attribute, like username@hostname' -r
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand home; and __fish_seen_subcommand_from switch" -s b -l backup-extension -d 'Move existing files by backing up with the extension' -r
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand home; and __fish_seen_subcommand_from switch" -s n -l dry -d 'Only print actions, without performing them'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand home; and __fish_seen_subcommand_from switch" -s a -l ask -d 'Ask for confirmation'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand home; and __fish_seen_subcommand_from switch" -s u -l update -d 'Update flake inputs before building specified configuration'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand home; and __fish_seen_subcommand_from switch" -l no-nom -d 'Don\'t use nix-output-monitor for the build process'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand home; and __fish_seen_subcommand_from switch" -s v -l verbose -d 'Show debug logs'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand home; and __fish_seen_subcommand_from switch" -s h -l help -d 'Print help (see more with \'--help\')'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand home; and __fish_seen_subcommand_from build" -s D -l diff-provider -d 'Closure diff provider' -r
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand home; and __fish_seen_subcommand_from build" -s c -l configuration -d 'Name of the flake homeConfigurations attribute, like username@hostname' -r
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand home; and __fish_seen_subcommand_from build" -s b -l backup-extension -d 'Move existing files by backing up with the extension' -r
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand home; and __fish_seen_subcommand_from build" -s n -l dry -d 'Only print actions, without performing them'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand home; and __fish_seen_subcommand_from build" -s a -l ask -d 'Ask for confirmation'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand home; and __fish_seen_subcommand_from build" -s u -l update -d 'Update flake inputs before building specified configuration'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand home; and __fish_seen_subcommand_from build" -l no-nom -d 'Don\'t use nix-output-monitor for the build process'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand home; and __fish_seen_subcommand_from build" -s v -l verbose -d 'Show debug logs'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand home; and __fish_seen_subcommand_from build" -s h -l help -d 'Print help (see more with \'--help\')'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand home; and __fish_seen_subcommand_from info" -s v -l verbose -d 'Show debug logs'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand home; and __fish_seen_subcommand_from info" -s h -l help -d 'Print help'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand search" -s l -l limit -d 'Number of search results to display' -r
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand search" -s c -l channel -d 'Name of the channel to query (e.g nixos-23.11, nixos-unstable)' -r
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand search" -s f -l flake -d 'Flake to read what nixpkgs channels to search for' -r -f -a "(__fish_complete_directories)"
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand search" -s v -l verbose -d 'Show debug logs'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand search" -s h -l help -d 'Print help'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and not __fish_seen_subcommand_from all user profile" -s v -l verbose -d 'Show debug logs'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and not __fish_seen_subcommand_from all user profile" -s h -l help -d 'Print help'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and not __fish_seen_subcommand_from all user profile" -f -a "all" -d 'Cleans root profiles and calls a store gc'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and not __fish_seen_subcommand_from all user profile" -f -a "user" -d 'Cleans the current user\'s profiles and calls a store gc'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and not __fish_seen_subcommand_from all user profile" -f -a "profile" -d 'Cleans a specific profile'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and __fish_seen_subcommand_from all" -s k -l keep -d 'At least keep this number of generations' -r
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and __fish_seen_subcommand_from all" -s K -l keep-since -d 'At least keep gcroots and generations in this time range since now' -r
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and __fish_seen_subcommand_from all" -s n -l dry -d 'Only print actions, without performing them'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and __fish_seen_subcommand_from all" -s a -l ask -d 'Ask for confimation'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and __fish_seen_subcommand_from all" -l nogc -d 'Don\'t run nix store --gc'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and __fish_seen_subcommand_from all" -l nogcroots -d 'Don\'t clean gcroots'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and __fish_seen_subcommand_from all" -s v -l verbose -d 'Show debug logs'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and __fish_seen_subcommand_from all" -s h -l help -d 'Print help'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and __fish_seen_subcommand_from user" -s k -l keep -d 'At least keep this number of generations' -r
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and __fish_seen_subcommand_from user" -s K -l keep-since -d 'At least keep gcroots and generations in this time range since now' -r
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and __fish_seen_subcommand_from user" -s n -l dry -d 'Only print actions, without performing them'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and __fish_seen_subcommand_from user" -s a -l ask -d 'Ask for confimation'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and __fish_seen_subcommand_from user" -l nogc -d 'Don\'t run nix store --gc'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and __fish_seen_subcommand_from user" -l nogcroots -d 'Don\'t clean gcroots'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and __fish_seen_subcommand_from user" -s v -l verbose -d 'Show debug logs'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and __fish_seen_subcommand_from user" -s h -l help -d 'Print help'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and __fish_seen_subcommand_from profile" -s k -l keep -d 'At least keep this number of generations' -r
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and __fish_seen_subcommand_from profile" -s K -l keep-since -d 'At least keep gcroots and generations in this time range since now' -r
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and __fish_seen_subcommand_from profile" -s n -l dry -d 'Only print actions, without performing them'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and __fish_seen_subcommand_from profile" -s a -l ask -d 'Ask for confimation'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and __fish_seen_subcommand_from profile" -l nogc -d 'Don\'t run nix store --gc'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and __fish_seen_subcommand_from profile" -l nogcroots -d 'Don\'t clean gcroots'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and __fish_seen_subcommand_from profile" -s v -l verbose -d 'Show debug logs'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand clean; and __fish_seen_subcommand_from profile" -s h -l help -d 'Print help'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand completions" -s s -l shell -d 'Name of the shell' -r -f -a "{bash\t'',elvish\t'',fish\t'',powershell\t'',zsh\t''}"
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand completions" -s v -l verbose -d 'Show debug logs'
|
||||||
|
complete -c nh -n "__fish_nh_using_subcommand completions" -s h -l help -d 'Print help'
|
105
home-manager/stvnliu/shells/fish/init/zoxide.fish
Normal file
105
home-manager/stvnliu/shells/fish/init/zoxide.fish
Normal file
|
@ -0,0 +1,105 @@
|
||||||
|
# =============================================================================
|
||||||
|
#
|
||||||
|
# Utility functions for zoxide.
|
||||||
|
#
|
||||||
|
|
||||||
|
# pwd based on the value of _ZO_RESOLVE_SYMLINKS.
|
||||||
|
function __zoxide_pwd
|
||||||
|
builtin pwd -L
|
||||||
|
end
|
||||||
|
|
||||||
|
# A copy of fish's internal cd function. This makes it possible to use
|
||||||
|
# `alias cd=z` without causing an infinite loop.
|
||||||
|
if ! builtin functions --query __zoxide_cd_internal
|
||||||
|
if builtin functions --query cd
|
||||||
|
builtin functions --copy cd __zoxide_cd_internal
|
||||||
|
else
|
||||||
|
alias __zoxide_cd_internal='builtin cd'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# cd + custom logic based on the value of _ZO_ECHO.
|
||||||
|
function __zoxide_cd
|
||||||
|
__zoxide_cd_internal $argv
|
||||||
|
end
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
#
|
||||||
|
# Hook configuration for zoxide.
|
||||||
|
#
|
||||||
|
|
||||||
|
# Initialize hook to add new entries to the database.
|
||||||
|
function __zoxide_hook --on-variable PWD
|
||||||
|
test -z "$fish_private_mode"
|
||||||
|
and command zoxide add -- (__zoxide_pwd)
|
||||||
|
end
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
#
|
||||||
|
# When using zoxide with --no-cmd, alias these internal functions as desired.
|
||||||
|
#
|
||||||
|
|
||||||
|
if test -z $__zoxide_z_prefix
|
||||||
|
set __zoxide_z_prefix 'z!'
|
||||||
|
end
|
||||||
|
set __zoxide_z_prefix_regex ^(string escape --style=regex $__zoxide_z_prefix)
|
||||||
|
|
||||||
|
# Jump to a directory using only keywords.
|
||||||
|
function __zoxide_z
|
||||||
|
set -l argc (count $argv)
|
||||||
|
if test $argc -eq 0
|
||||||
|
__zoxide_cd $HOME
|
||||||
|
else if test "$argv" = -
|
||||||
|
__zoxide_cd -
|
||||||
|
else if test $argc -eq 1 -a -d $argv[1]
|
||||||
|
__zoxide_cd $argv[1]
|
||||||
|
else if set -l result (string replace --regex $__zoxide_z_prefix_regex '' $argv[-1]); and test -n $result
|
||||||
|
__zoxide_cd $result
|
||||||
|
else
|
||||||
|
set -l result (command zoxide query --exclude (__zoxide_pwd) -- $argv)
|
||||||
|
and __zoxide_cd $result
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Completions.
|
||||||
|
function __zoxide_z_complete
|
||||||
|
set -l tokens (commandline --current-process --tokenize)
|
||||||
|
set -l curr_tokens (commandline --cut-at-cursor --current-process --tokenize)
|
||||||
|
|
||||||
|
if test (count $tokens) -le 2 -a (count $curr_tokens) -eq 1
|
||||||
|
# If there are < 2 arguments, use `cd` completions.
|
||||||
|
complete --do-complete "'' "(commandline --cut-at-cursor --current-token) | string match --regex '.*/$'
|
||||||
|
else if test (count $tokens) -eq (count $curr_tokens); and ! string match --quiet --regex $__zoxide_z_prefix_regex. $tokens[-1]
|
||||||
|
# If the last argument is empty and the one before doesn't start with
|
||||||
|
# $__zoxide_z_prefix, use interactive selection.
|
||||||
|
set -l query $tokens[2..-1]
|
||||||
|
set -l result (zoxide query --exclude (__zoxide_pwd) --interactive -- $query)
|
||||||
|
and echo $__zoxide_z_prefix$result
|
||||||
|
commandline --function repaint
|
||||||
|
end
|
||||||
|
end
|
||||||
|
complete --command __zoxide_z --no-files --arguments '(__zoxide_z_complete)'
|
||||||
|
|
||||||
|
# Jump to a directory using interactive search.
|
||||||
|
function __zoxide_zi
|
||||||
|
set -l result (command zoxide query --interactive -- $argv)
|
||||||
|
and __zoxide_cd $result
|
||||||
|
end
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
#
|
||||||
|
# Commands for zoxide. Disable these using --no-cmd.
|
||||||
|
#
|
||||||
|
|
||||||
|
abbr --erase z &>/dev/null
|
||||||
|
alias z=__zoxide_z
|
||||||
|
|
||||||
|
abbr --erase zi &>/dev/null
|
||||||
|
alias zi=__zoxide_zi
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
#
|
||||||
|
# To initialize zoxide, add this to your configuration (usually
|
||||||
|
# ~/.config/fish/config.fish):
|
||||||
|
#
|
||||||
|
# zoxide init fish | source
|
Loading…
Add table
Add a link
Reference in a new issue