This commit is contained in:
Kovid Goyal
2022-06-28 11:42:37 +05:30
19 changed files with 60 additions and 54 deletions

View File

@@ -274,8 +274,8 @@ Edit files in new kitty windows even over SSH
edit-in-kitty myfile.txt edit-in-kitty myfile.txt
edit-in-kitty --type tab --title "Editing My File" myfile.txt edit-in-kitty --type tab --title "Editing My File" myfile.txt
# open file.txt at line 75 (works with vim, emacs, nano, micro) # open myfile.txt at line 75 (works with vim, neovim, emacs, nano, micro)
edit-in-kitty +75 file.txt edit-in-kitty +75 myfile.txt
The :command:`edit-in-kitty` command allows you to seamlessly edit files The :command:`edit-in-kitty` command allows you to seamlessly edit files
in your default :opt:`editor` in new kitty windows. This works even over in your default :opt:`editor` in new kitty windows. This works even over

0
kittens/diff/collect.py Executable file → Normal file
View File

0
kittens/diff/main.py Executable file → Normal file
View File

0
kittens/diff/options/definition.py Executable file → Normal file
View File

0
kittens/diff/options/utils.py Executable file → Normal file
View File

0
kittens/icat/main.py Executable file → Normal file
View File

View File

@@ -181,15 +181,15 @@ the same as for the :ac:`toggle_marker` action (see :doc:`/marks`).
--os-window-class --os-window-class
Set the *WM_CLASS* property on X11 and the application id property on Wayland Set the :italic:`WM_CLASS` property on X11 and the application id property on
for the newly created OS window when using :option:`--type=os-window Wayland for the newly created OS window when using :option:`--type=os-window
<launch --type>`. Defaults to whatever is used by the parent kitty process, <launch --type>`. Defaults to whatever is used by the parent kitty process,
which in turn defaults to :code:`kitty`. which in turn defaults to :code:`kitty`.
--os-window-name --os-window-name
Set the *WM_NAME* property on X11 for the newly created OS Window when using Set the :italic:`WM_NAME` property on X11 for the newly created OS Window when
:option:`--type=os-window <launch --type>`. Defaults to using :option:`--type=os-window <launch --type>`. Defaults to
:option:`--os-window-class <launch --os-window-class>`. :option:`--os-window-class <launch --os-window-class>`.
@@ -220,8 +220,8 @@ effect if :option:`--logo` is specified. See :opt:`window_logo_position`.
type=list type=list
Change colors in the newly launched window. You can either specify a path to a Change colors in the newly launched window. You can either specify a path to a
:file:`.conf` file with the same syntax as :file:`kitty.conf` to read the colors :file:`.conf` file with the same syntax as :file:`kitty.conf` to read the colors
from, or specify them individually, for example: ``--color background=white`` from, or specify them individually, for example: :code:`--color background=white
``--color foreground=red`` --color foreground=red`.
--watcher -w --watcher -w

View File

@@ -87,7 +87,7 @@ For numeric fields: :code:`id`, :code:`pid`, :code:`num` and :code:`recent`, the
a number, not a regular expression. a number, not a regular expression.
The field :code:`num` refers to the window position in the current tab, starting from zero and counting clockwise (this The field :code:`num` refers to the window position in the current tab, starting from zero and counting clockwise (this
is the same as the order in which the windows are reported by the :italic:`ls` command). is the same as the order in which the windows are reported by the :ref:`kitty @ ls <at_ls>` command).
The window id of the current window is available as the :envvar:`KITTY_WINDOW_ID` environment variable. The window id of the current window is available as the :envvar:`KITTY_WINDOW_ID` environment variable.
@@ -95,7 +95,7 @@ The field :code:`recent` refers to recently active windows in the currently acti
active window, one being the previously active window and so on. active window, one being the previously active window and so on.
When using the :code:`env` field to match on environment variables, you can specify only the environment variable name When using the :code:`env` field to match on environment variables, you can specify only the environment variable name
or a name and value, for example, :italic:`env:MY_ENV_VAR=2`. or a name and value, for example, :code:`env:MY_ENV_VAR=2`.
The field :code:`state` matches on the state of the window. Supported states are: The field :code:`state` matches on the state of the window. Supported states are:
:code:`active`, :code:`focused`, :code:`needs_attention`, :code:`parent_active` and :code:`parent_focused`. :code:`active`, :code:`focused`, :code:`needs_attention`, :code:`parent_active` and :code:`parent_focused`.
@@ -128,7 +128,7 @@ The :code:`recent` number matches recently active tabs in the currently active O
active tab, one the previously active tab and so on. active tab, one the previously active tab and so on.
When using the :code:`env` field to match on environment variables, you can specify only the environment variable name When using the :code:`env` field to match on environment variables, you can specify only the environment variable name
or a name and value, for example, :italic:`env:MY_ENV_VAR=2`. Tabs containing any window with the specified environment or a name and value, for example, :code:`env:MY_ENV_VAR=2`. Tabs containing any window with the specified environment
variables are matched. variables are matched.
The field :code:`state` matches on the state of the tab. Supported states are: The field :code:`state` matches on the state of the tab. Supported states are:

View File

@@ -24,7 +24,7 @@ class CloseTab(RemoteCommand):
desc = '''\ desc = '''\
Close an arbitrary set of tabs. The :code:`--match` option can be used to Close an arbitrary set of tabs. The :code:`--match` option can be used to
specify complex sets of tabs to close. For example, to close all non-focused specify complex sets of tabs to close. For example, to close all non-focused
tabs in the currently focused OS window, use: tabs in the currently focused OS window, use::
kitty @ close-tab --match "not state:focused and state:parent_focused" kitty @ close-tab --match "not state:focused and state:parent_focused"
''' '''

View File

@@ -51,8 +51,8 @@ class Launch(RemoteCommand):
desc = ( desc = (
'Prints out the id of the newly opened window. Any command line arguments' 'Prints out the id of the newly opened window. Any command line arguments'
' are assumed to be the command line used to run in the new window, if none' ' are assumed to be the command line used to run in the new window, if none'
' are provided, the default shell is run. For example:' ' are provided, the default shell is run. For example:\n'
' :code:`kitty @ launch --title=Email mutt`.' ':code:`kitty @ launch --title=Email mutt`'
) )
options_spec = MATCH_TAB_OPTION + '\n\n' + '''\ options_spec = MATCH_TAB_OPTION + '\n\n' + '''\
--no-response --no-response

View File

@@ -28,7 +28,7 @@ class NewWindow(RemoteCommand):
short_desc = 'Open new window' short_desc = 'Open new window'
desc = ( desc = (
'DEPRECATED: Use the launch command instead.\n\n' 'DEPRECATED: Use the :ref:`launch <at_launch>` command instead.\n\n'
'Open a new window in the specified tab. If you use the :option:`kitty @ new-window --match` option' 'Open a new window in the specified tab. If you use the :option:`kitty @ new-window --match` option'
' the first matching tab is used. Otherwise the currently active tab is used.' ' the first matching tab is used. Otherwise the currently active tab is used.'
' Prints out the id of the newly opened window' ' Prints out the id of the newly opened window'

View File

@@ -27,7 +27,7 @@ class ScrollWindow(RemoteCommand):
desc = ( desc = (
'Scroll the specified windows, if no window is specified, scroll the window this command is run inside.' 'Scroll the specified windows, if no window is specified, scroll the window this command is run inside.'
' :italic:`SCROLL_AMOUNT` can be either the keywords :code:`start` or :code:`end` or an' ' :italic:`SCROLL_AMOUNT` can be either the keywords :code:`start` or :code:`end` or an'
' argument of the form <number>[unit][+-]. For example, :code:`30` will scroll down 30 lines and :code:`2p-`' ' argument of the form :italic:`<number>[unit][+-]`. For example, :code:`30` will scroll down 30 lines and :code:`2p-`'
' will scroll up 2 pages. :code:`3u` will *unscroll* by 3 lines, which means that 3 lines will move from the' ' will scroll up 2 pages. :code:`3u` will *unscroll* by 3 lines, which means that 3 lines will move from the'
' scrollback buffer onto the top of the screen.' ' scrollback buffer onto the top of the screen.'
) )

View File

@@ -93,7 +93,7 @@ Do not send text to the active window, even if it is one of the matched windows.
--stdin --stdin
type=bool-set type=bool-set
Read the text to be sent from :italic:`stdin`. Note that in this case the text is sent as is, Read the text to be sent from :italic:`stdin`. Note that in this case the text is sent as is,
not interpreted for escapes. If stdin is a terminal, you can press :kbd:`Ctrl-D` to end reading. not interpreted for escapes. If stdin is a terminal, you can press :kbd:`Ctrl+D` to end reading.
--from-file --from-file

View File

@@ -672,7 +672,7 @@ def get_editor(opts: Optional[Options] = None, path_to_edit: str = '', line_numb
ans = shlex.split(opts.editor) ans = shlex.split(opts.editor)
if path_to_edit: if path_to_edit:
if line_number: if line_number:
eq = os.path.basename(ans[-1]).lower() eq = os.path.basename(ans[0]).lower()
if eq in ('code', 'code.exe'): if eq in ('code', 'code.exe'):
path_to_edit += f':{line_number}' path_to_edit += f':{line_number}'
ans.append('--goto') ans.append('--goto')

View File

@@ -1,7 +1,6 @@
function __ksi_completions function __ksi_completions
set --local ct (commandline --current-token) set --local ct (commandline --current-token)
set --local tokens (commandline --tokenize --cut-at-cursor --current-process) set --local tokens (commandline --tokenize --cut-at-cursor --current-process)
set tokens[1] "clone-in-kitty"
printf "%s\n" $tokens $ct | command kitty +complete fish2 printf "%s\n" $tokens $ct | command kitty +complete fish2
end end

View File

@@ -1,7 +1,6 @@
function __ksi_completions function __ksi_completions
set --local ct (commandline --current-token) set --local ct (commandline --current-token)
set --local tokens (commandline --tokenize --cut-at-cursor --current-process) set --local tokens (commandline --tokenize --cut-at-cursor --current-process)
set tokens[1] "edit-in-kitty"
printf "%s\n" $tokens $ct | command kitty +complete fish2 printf "%s\n" $tokens $ct | command kitty +complete fish2
end end

View File

@@ -165,7 +165,6 @@ function __ksi_transmit_data -d "Transmit data to kitty using chunked DCS escape
set chunk_num (math $chunk_num + 1) set chunk_num (math $chunk_num + 1)
end end
printf \eP@kitty-%s\|\e\\ "$argv[2]" printf \eP@kitty-%s\|\e\\ "$argv[2]"
end end
function clone-in-kitty -d "Clone the current fish session into a new kitty window" function clone-in-kitty -d "Clone the current fish session into a new kitty window"
@@ -187,8 +186,7 @@ function clone-in-kitty -d "Clone the current fish session into a new kitty wind
set --local b64_envs (string join0 -- $envs | base64) set --local b64_envs (string join0 -- $envs | base64)
set --local b64_cwd (printf "%s" "$PWD" | base64) set --local b64_cwd (printf "%s" "$PWD" | base64)
set --prepend data "shell=fish" "pid=$fish_pid" "cwd=$b64_cwd" "env=$b64_envs" set --prepend data "shell=fish" "pid=$fish_pid" "cwd=$b64_cwd" "env=$b64_envs"
set data (string join "," -- $data | tr -d "\t\n\r ") __ksi_transmit_data (string join "," -- $data | tr -d "\t\n\r ") "clone"
__ksi_transmit_data "$data" "clone"
end end
function edit-in-kitty -d "Edit the specified file in a new kitty overlay using your preferred editor, even over SSH" function edit-in-kitty -d "Edit the specified file in a new kitty overlay using your preferred editor, even over SSH"
@@ -217,62 +215,73 @@ function edit-in-kitty -d "Edit the specified file in a new kitty overlay using
return 1 return 1
end end
if test ! -f "$ed_filename" if test ! -f "$ed_filename"
builtin echo "$ed_filename is not a file" > /dev/stderr echo "$ed_filename is not a file" > /dev/stderr
return 1 return 1
end end
set --local stat_result (command stat -L --format '%d:%i:%s' "$ed_filename" 2> /dev/null) set --local stat_result (stat -L --format '%d:%i:%s' "$ed_filename" 2> /dev/null)
if test "$status" -ne "0" if test "$status" -ne 0
set stat_result (command stat -L -f '%d:%i:%z' "$ed_filename" 2> /dev/null) set stat_result (stat -L -f '%d:%i:%z' "$ed_filename" 2> /dev/null)
end end
if test -z "$stat_result" if test "$status" -ne 0 || test -z "$stat_result"
echo "Failed to stat the file: $ed_filename" > /dev/stderr echo "Failed to stat the file: $ed_filename" > /dev/stderr
return 1 return 1
end end
set --append data "file_inode=$stat_result" set --append data "file_inode=$stat_result"
set --local file_size (string match -rg '\d+:\d+:(\d+)' "$stat_result") set --local file_size (string match -rg '\d+:\d+:(\d+)' "$stat_result")
test "$file_size" -gt (math "8 * 1024 * 1024") && begin; echo "File is too large for performant editing"; return 1; end; if test "$file_size" -gt (math "8 * 1024 * 1024")
set --local file_data (command base64 < "$ed_filename") echo "File is too large for performant editing" > /dev/stderr
return 1
end
set --local file_data (base64 < "$ed_filename")
set --append data "file_data=$file_data" set --append data "file_data=$file_data"
__ksi_transmit_data (string join "," -- $data | tr -d "\t\n\r ") "edit" __ksi_transmit_data (string join "," -- $data | tr -d "\t\n\r ") "edit"
set --erase data
echo "Waiting for editing to be completed..." echo "Waiting for editing to be completed..."
set --global __ksi_waiting_for_edit "y" set --global __ksi_waiting_for_edit "y"
set --erase data
function __ksi_react_to_interrupt -s SIGINT function __ksi_react_to_interrupt --on-signal SIGINT
functions --erase __ksi_react_to_interrupt
if test "$__ksi_waiting_for_edit" = "y" if test "$__ksi_waiting_for_edit" = "y"
set --erase __ksi_waiting_for_edit set --erase __ksi_waiting_for_edit
__ksi_transmit_data "abort_signaled=interrupt" "edit" __ksi_transmit_data "abort_signaled=interrupt" "edit"
end end
end end
while true while true
set --local started "n" set --local started "n"
while true while true
command stty "-echo"; set --local line (command head -n1 < /dev/tty); stty "-echo"
set --local line (head -n1 < /dev/tty)
test -z "$line" && break test -z "$line" && break
if test "$started" = "y" if test "$started" = "y"
test "$line" = "UPDATE" && break; test "$line" = "UPDATE" && break
if test "$line" = "DONE" if test "$line" = "DONE"
set started "done"; break; set started "done"
break
end end
printf "%s\n" "$line" > /dev/stderr; printf "%s\n" "$line" > /dev/stderr
return 1; set --erase __ksi_waiting_for_edit
functions --erase __ksi_react_to_interrupt
return 1
else else
test "$line" = "KITTY_DATA_START" && set started "y" test "$line" = "KITTY_DATA_START" && set started "y"
end end
end end
test "$started" = "n" && continue; test "$started" = "n" && continue
set --local data "" set --local data ""
while true while true
command stty "-echo"; set --local line (command head -n1 < /dev/tty); stty "-echo"
set --local line (head -n1 < /dev/tty)
test -z "$line" && break test -z "$line" && break
test "$line" = "KITTY_DATA_END" && break; test "$line" = "KITTY_DATA_END" && break
set data "$data$line" set data "$data$line"
end end
if test -n "$data" -a "$started" != "done" if test -n "$data" -a "$started" != "done"
echo "Updating $ed_filename..." echo "Updating $ed_filename..."
printf "%s" "$data" | command base64 -d > "$ed_filename" printf "%s" "$data" | base64 -d > "$ed_filename"
end end
test "$started" = "done" && break; test "$started" = "done" && break
end end
set --erase __ksi_waiting_for_edit set --erase __ksi_waiting_for_edit
functions --erase __ksi_react_to_interrupt functions --erase __ksi_react_to_interrupt
end end

View File

@@ -202,11 +202,11 @@ prepare_for_exec() {
/*) ;; /*) ;;
*) *)
if ! command -v "$login_shell" > /dev/null 2> /dev/null; then if ! command -v "$login_shell" > /dev/null 2> /dev/null; then
for i in /opt/homebrew/bin /opt/homebrew/sbin /usr/local/bin /usr/bin /bin /usr/sbin /sbin for i in /opt/homebrew/bin /opt/homebrew/sbin /opt/local/bin /opt/local/sbin /usr/local/bin /usr/bin /bin /usr/sbin /sbin
do do
if [ -x "$i/$login_shell" ]; then if [ -x "$i/$login_shell" ]; then
login_shell="$i/$login_shell" login_shell="$i/$login_shell"
break; break
fi fi
done done
fi fi

View File

@@ -254,7 +254,7 @@ _ksi_deferred_init() {
# OpenSSH's sshd creates entries in utmp for every login so use those # OpenSSH's sshd creates entries in utmp for every login so use those
[[ "$(builtin command who -m 2> /dev/null)" =~ "\([a-fA-F.:0-9]+\)$" ]] && is_ssh_session="y" [[ "$(builtin command who -m 2> /dev/null)" =~ "\([a-fA-F.:0-9]+\)$" ]] && is_ssh_session="y"
fi fi
if [[ "$is_ssh_session" == "y" ]]; then if [[ "$is_ssh_session" == "y" ]]; then
# show the hostname via %m for SSH sessions # show the hostname via %m for SSH sessions
functions[_ksi_precmd]+=" functions[_ksi_precmd]+="
@@ -408,7 +408,7 @@ clone-in-kitty() {
while :; do while :; do
case "$1" in case "$1" in
"") break;; "") break;;
-h|--help) -h|--help)
builtin printf "%s\n\n%s\n" "Clone the current zsh session into a new kitty window." "For usage instructions see: https://sw.kovidgoyal.net/kitty/shell-integration/#clone-shell" builtin printf "%s\n\n%s\n" "Clone the current zsh session into a new kitty window." "For usage instructions see: https://sw.kovidgoyal.net/kitty/shell-integration/#clone-shell"
return return
;; ;;
@@ -428,7 +428,6 @@ clone-in-kitty() {
_ksi_transmit_data "$data" "clone" "save_history" _ksi_transmit_data "$data" "clone" "save_history"
} }
edit-in-kitty() { edit-in-kitty() {
builtin local data="" builtin local data=""
builtin local ed_filename="" builtin local ed_filename=""
@@ -437,7 +436,7 @@ edit-in-kitty() {
while :; do while :; do
case "$1" in case "$1" in
"") break;; "") break;;
-h|--help) -h|--help)
builtin printf "%s\n\n%s\n\n%s\n" "$usage" "Edit the specified file in a kitty overlay window. Works over SSH as well." "For usage instructions see: https://sw.kovidgoyal.net/kitty/shell-integration/#edit-file" builtin printf "%s\n\n%s\n\n%s\n" "$usage" "Edit the specified file in a kitty overlay window. Works over SSH as well." "For usage instructions see: https://sw.kovidgoyal.net/kitty/shell-integration/#edit-file"
return return
;; ;;
@@ -463,7 +462,7 @@ edit-in-kitty() {
[ "${stat_result[size]}" -gt $((8 * 1024 * 1024)) ] && { builtin echo "File is too large for performant editing"; return 1; } [ "${stat_result[size]}" -gt $((8 * 1024 * 1024)) ] && { builtin echo "File is too large for performant editing"; return 1; }
data="$data,file_inode=${stat_result[device]}:${stat_result[inode]}:${stat_result[size]}" data="$data,file_inode=${stat_result[device]}:${stat_result[inode]}:${stat_result[size]}"
data="$data,file_data=$(builtin command base64 < "$ed_filename")" data="$data,file_data=$(builtin command base64 < "$ed_filename")"
_ksi_transmit_data "$data" "edit" _ksi_transmit_data "$data" "edit"
data="" data=""
builtin echo "Waiting for editing to be completed..." builtin echo "Waiting for editing to be completed..."
builtin local started="n" builtin local started="n"