简体   繁体   中英

AutoLS for fish shell

I have an auto-ls script in my conf.d directory

function __autols_hook --description "Auto ls" --on-event fish_prompt
  if test "$__autols_last" != (pwd)
    if test "$HOME" = (pwd)
    else
      clear; ls;
      # Show git information, and if it's not a git repo, throw error
      # into /dev/null. Simples
      git status 2>/dev/null
    end
  end
  set  -g __autols_last (pwd)
end

This works very well. However, I'd also like this to trigger when I hit enter, in the same pwd, but with no command.

I can't find a way to check if the enter key was pressed but no command

Change the binding for the [enter] key:

bind \cm 'set -l cmd (commandline); test -z "$cmd"; and set -g _empty_command yes; or set -g _empty_command no; commandline -f execute'

Now you can test $_empty_command in your fish_prompt event function. Note that [ctrl-j] also invokes the execute command so you should probably also bind \\cj to the same code. But that's optional unless you have an unusual terminal config.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM