Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: make fasder work with fish shell #32

Open
knodalyte opened this issue Jan 1, 2025 · 3 comments
Open

Feature request: make fasder work with fish shell #32

knodalyte opened this issue Jan 1, 2025 · 3 comments

Comments

@knodalyte
Copy link

Looks promising, if only I could use it with fish... But it looks like it has some zsh assumptions built in.

@dkmar
Copy link

dkmar commented Jan 13, 2025

I did a little much here and I've only used it for a few hours but it's working thus far.

Event Handler (i put it in$__fish_config_dir/functions/_fasd_update_freq.fish)

function _fasd_update --on-event fish_postexec
   # just split into tokens
   echo $argv[1] | read --tokenize --list -- tokens
   # early exit if there's only the leading command here
   if test (count $tokens) -le 1
      return
   end
   # get normalized, absolute path candidates for the rest of the tokens
   # and keep only those that are existing files or directories
   set -l candidates (path resolve -- $tokens[2..] | path filter -t file,dir)
   for fp in $candidates
      # only add if this path isn't to an executable
      if not type -q $fp
         fasder --add "$fp"
      end
   end
end

and then just source the file in your config.fish to load it:
source $__fish_config_dir/functions/_fasd_update_freq.fish

@knodalyte
Copy link
Author

Thank you, I have set it up and will check over the next few days and see how it works.

@dkmar
Copy link

dkmar commented Jan 15, 2025

ok I changed it to be a preexec hook which is what fasder does for zsh. I now realize that this is necessary for resolving paths in like cd ../.., cause you want to resolve the path according to your PWD before executing the cd

function _fasd_update --on-event fish_preexec
   # just split into tokens
   echo $argv[1] | read --tokenize --list -- tokens
   # early exit if there's only the leading command here
   if test (count $tokens) -le 1
      return
   end
   # get normalized, absolute path candidates for the rest of the tokens
   # and keep only those that are existing files or directories
   set -l candidates (path resolve -- $tokens[2..] | path filter -t file,dir)
   for fp in $candidates
      # only add if this path isn't to an executable
      if not type -q $fp
         fasder --add "$fp"
      end
   end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants