diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d94362b12..0de9296ce 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -46,6 +46,7 @@ Interactive improvements - :kbd:`Control-C` during command input no longer prints ``^C`` and a new prompt but merely clears the command line. This restores the behavior from version 2.2. To revert to the old behavior use ``bind \cc __fish_cancel_commandline`` (:issue:`10213`). - Command-specific tab completions may now offer results whose first character is a period. For example, it is now possible to tab-complete ``git add`` for files with leading periods. The default file completions hide these files, unless the token itself has a leading period (:issue:`3707`). - The :kbd:`Control-R` history search now uses glob syntax (:issue:`10131`). +- When the cursor is on a command that resolves to a script, :kbd:`Alt-O` will now open that script in your editor. - :kbd:`Alt-E` now passes the cursor position to the external editor also if the editor aliases a supported editor (via ``complete --wraps``). - Option completion now uses fuzzy subsequence filtering as well. This means that ``--fb`` may be completed to ``--foobar`` if there is no better match. diff --git a/README.rst b/README.rst index 51a8b0b2d..9d6b5d1e1 100644 --- a/README.rst +++ b/README.rst @@ -91,7 +91,7 @@ Running fish requires: - curses or ncurses (preinstalled on most \*nix systems) - some common \*nix system utilities (currently ``mktemp``), in addition to the basic POSIX utilities (``cat``, ``cut``, ``dirname``, - ``ls``, ``mkdir``, ``mkfifo``, ``rm``, ``sort``, ``tee``, ``tr``, + ``file``, ``ls``, ``mkdir``, ``mkfifo``, ``rm``, ``sort``, ``tee``, ``tr``, ``uname`` and ``sed`` at least, but the full coreutils plus ``find`` and ``awk`` is preferred) - The gettext library, if compiled with diff --git a/doc_src/interactive.rst b/doc_src/interactive.rst index 97cfeed62..ac8b43b6d 100644 --- a/doc_src/interactive.rst +++ b/doc_src/interactive.rst @@ -331,7 +331,7 @@ Some bindings are common across Emacs and vi mode, because they aren't text edit - :kbd:`Alt`\ +\ :kbd:`L` lists the contents of the current directory, unless the cursor is over a directory argument, in which case the contents of that directory will be listed. -- :kbd:`Alt`\ +\ :kbd:`O` opens the file at the cursor in a pager. +- :kbd:`Alt`\ +\ :kbd:`O` opens the file at the cursor in a pager. If the cursor is in command position and the command is a script, it will instead open that script in your editor. The editor is chosen from the first available of the ``$VISUAL`` or ``$EDITOR`` variables. - :kbd:`Alt`\ +\ :kbd:`P` adds the string ``&| less;`` to the end of the job under the cursor. The result is that the output of the command will be paged. diff --git a/share/functions/__fish_anyeditor.fish b/share/functions/__fish_anyeditor.fish new file mode 100644 index 000000000..2f80fe256 --- /dev/null +++ b/share/functions/__fish_anyeditor.fish @@ -0,0 +1,16 @@ +function __fish_anyeditor --description "Print a editor to use, or an error message" + set -l editor + if set -q VISUAL + echo $VISUAL | read -at editor + else if set -q EDITOR + echo $EDITOR | read -at editor + else + echo >&2 + echo >&2 (_ 'External editor requested but $VISUAL or $EDITOR not set.') + echo >&2 (_ 'Please set VISUAL or EDITOR to your preferred editor.') + commandline -f repaint + return 1 + end + string join \n $editor + return 0 +end diff --git a/share/functions/__fish_edit_command_if_at_cursor.fish b/share/functions/__fish_edit_command_if_at_cursor.fish new file mode 100644 index 000000000..37c1af424 --- /dev/null +++ b/share/functions/__fish_edit_command_if_at_cursor.fish @@ -0,0 +1,25 @@ +function __fish_edit_command_if_at_cursor --description 'If cursor is at the command token, edit the command source file' + set -l tokens (commandline -xpc) + set -l command + if not set -q tokens[1] + set command (commandline -xp)[1] + else if test (count $tokens) = 1 && test -z "$(commandline -t)" + set command $tokens[1] + end + + set -q command[1] + or return 1 + set -l command_path (command -v -- $command) + or return 1 + test -w $command_path + or return 1 + string match -q 'text/*' (file --brief --mime-type -L -- $command_path) + or return 1 + + set -l editor (__fish_anyeditor) + or return 0 # We already printed a warning, so tell the caller to finish. + __fish_disable_bracketed_paste + $editor $command_path + __fish_enable_bracketed_paste + return 0 +end diff --git a/share/functions/__fish_preview_current_file.fish b/share/functions/__fish_preview_current_file.fish index f2f3751fd..984667909 100644 --- a/share/functions/__fish_preview_current_file.fish +++ b/share/functions/__fish_preview_current_file.fish @@ -1,4 +1,9 @@ function __fish_preview_current_file --description "Open the file at the cursor in a pager" + if __fish_edit_command_if_at_cursor + return 0 + end + + set -l pager (__fish_anypager) or set pager cat diff --git a/share/functions/edit_command_buffer.fish b/share/functions/edit_command_buffer.fish index 13e05005e..b5a4a3203 100644 --- a/share/functions/edit_command_buffer.fish +++ b/share/functions/edit_command_buffer.fish @@ -15,19 +15,8 @@ function edit_command_buffer --description 'Edit the command buffer in an extern or return 1 end - # Edit the command line with the users preferred editor or vim or emacs. - set -l editor - if set -q VISUAL - echo $VISUAL | read -at editor - else if set -q EDITOR - echo $EDITOR | read -at editor - else - echo - echo (_ 'External editor requested but $VISUAL or $EDITOR not set.') - echo (_ 'Please set VISUAL or EDITOR to your preferred editor.') - commandline -f repaint - return 1 - end + set -l editor (__fish_anyeditor) + or return 1 commandline -b >$f set -l offset (commandline --cursor)