Hi Ray, I left a message on GTalk, but in case someone else is interested too:
2012/12/14 Ray <i...@maskray.me>: > Hi all, > > I'm a new fish user escaping from the zsh camp :) > > autojump is a productivity boost tool to chdir quickly > (https://github.com/joelthelion/autojump/wiki). > > j proj -> ~/to/long/dont/read/projects > > fasd absorbs autojump's idea and makes it convenient to reference file in a > similar manner on the command line. > > v often-accessed-file -> vim > ~/a/very/long/path/containing/an/often-accessed-file > o may-be-a-web-page -> xdg-open > ~/i/am/a/haskell/enthusiast/may-be-a-web-page > > I know that the chdir feature (initiated by autojump) can be worked around > by fish_prompt, however, > it seems difficult to emulate the file-reference feature (v > often-accessed-file) without some hooks. > Instead of hacking fish_prompt, you can bind a function to the event with the same name: function save_pwd --on-event fish_prompt ... end > As far as I know, fish does not have such preexec hook (zsh's preexec). > Have you considered adding such hooks or implement this functionality in > the core (it's very slow for fasd to use many awk scripts and others). Since you are already abusing the fish_prompt event, you can emulate preexec by peeking at $history[1] in a function bound to the fish_prompt event, which always contain the last executed command. The trigger for fish_prompt is roughly equivalent to that of precmd in zsh, and I think the difference between precmd and preexec doesn't make much difference here. Judging by zshmisc(1): preexec Executed just after a command has been read and is about to be exe‐ cuted. If the history mechanism is active (and the line was not discarded from the history buffer), the string that the user typed is passed as the first argument, otherwise it is an empty string. The actual command that will be executed (including expanded aliases) is passed in two different forms: the second argument is a single-line, size-limited version of the command (with things like function bodies elided); the third argument contains the full text that is being executed. $history[1] seems pretty close. However, I think preexec can be made much better if individual tokens (instead of whole command lines) are passed to the hook function, so that after defining foo like (supposing a "preexec" event is implemented in fish): function foo --on-event preexec ... end Typing a command "echo a b c" results in foo gets called with 3 arguments, 'echo', 'a' and 'b' instead of 'echo a b' bundled together. Whether tokens are expanded before being passed still needs to be considered - typing "echo a{b,c}" might call foo with 'echo' and 'a{b,c}', or 'echo', 'ab' and 'ac'. I'm not sure which is more useful. One last little point - I think preexec is a pretty bad name. There is an exec builtin, and preexec might lead one to believe that it is called before exec is executed. (precmd is even worse; fish_prompt is way better that precmd.) I wish fish can use better names for similar functionalities. -- Regards, Cheer Xiao ------------------------------------------------------------------------------ LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial Remotely access PCs and mobile devices and provide instant support Improve your efficiency, and focus on delivering more value-add services Discover what IT Professionals Know. Rescue delivers http://p.sf.net/sfu/logmein_12329d2d _______________________________________________ Fish-users mailing list Fish-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/fish-users