From dd4f6f8b253268275c848d58cb034099edbae7f7 Mon Sep 17 00:00:00 2001 From: ffact <114359275+ffact@users.noreply.github.com> Date: Tue, 1 Oct 2024 06:10:49 +0000 Subject: [PATCH 1/6] Multiline fix __pet_new.fish --- functions/__pet_new.fish | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions/__pet_new.fish b/functions/__pet_new.fish index 5c8ff85..ff7bd90 100644 --- a/functions/__pet_new.fish +++ b/functions/__pet_new.fish @@ -1,9 +1,9 @@ function __pet_new --description 'Saves a command as a snippet in pet' # Use the current contents of the command line - set -l cmd (commandline) + set -l cmd (commandline | string split0) # If the command line is empty, let's search history - if test -z "$cmd" + if test -z (commandline) # Copying parts of fzf.fish's _fzf_search_history here, since we can't # directly re-use it if test -z "$fish_private_mode" From bb6ee47d0bdf8048ea60633ed22097358deb68e6 Mon Sep 17 00:00:00 2001 From: ffact <114359275+ffact@users.noreply.github.com> Date: Tue, 1 Oct 2024 07:47:13 +0000 Subject: [PATCH 2/6] Multiline fix for __pet_preview.fish --- functions/__pet_preview.fish | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/functions/__pet_preview.fish b/functions/__pet_preview.fish index 186ede1..4fa4284 100644 --- a/functions/__pet_preview.fish +++ b/functions/__pet_preview.fish @@ -1,4 +1,5 @@ function __pet_preview --description "Takes a snippet formatted by `pet search` and turns it into a preview pane for fzf." + set -l tags (echo (echo $argv | sed 's/\\\\n/\n/g')[-1] | sed 's/[^#]*#/#/') # Description set_color blue --bold echo $argv | sed 's/^\[// ; s/\]: .*//' @@ -6,14 +7,16 @@ function __pet_preview --description "Takes a snippet formatted by `pet search` echo "" # Code (syntax-highlighted for fish) echo $argv | \ - sed 's/.*]: // ; s/#.*//' | # extract code + sed 's/\\\\n/\n/g' | # replace pet newlines with normal ones + sed '0,/\[[^]]*\]:/s///' | # delete bracketed description + sed "s/$tags//g" | # find and delete tags sed 's/<\([^ =]\+\)\([^ ]*\)>/{$\U\1}/g' | # replace pet placeholders with variable names fish_indent --ansi - # Tags, if present + # Tags, if present if string match -e -q "#" "$argv" echo "" # to be able to set tags with background color, loop over them individually - for tag in (echo $argv | sed 's/[^#]*#/#/' | string split " ") + for tag in $tags set_color magenta # -b white echo -n "$tag" set_color normal From a7d52243bdaf140db596208d6d7a275b973b0a66 Mon Sep 17 00:00:00 2001 From: ffact <114359275+ffact@users.noreply.github.com> Date: Tue, 1 Oct 2024 07:50:48 +0000 Subject: [PATCH 3/6] forgot brackets --- functions/__pet_new.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/__pet_new.fish b/functions/__pet_new.fish index ff7bd90..fb88bc7 100644 --- a/functions/__pet_new.fish +++ b/functions/__pet_new.fish @@ -3,7 +3,7 @@ function __pet_new --description 'Saves a command as a snippet in pet' set -l cmd (commandline | string split0) # If the command line is empty, let's search history - if test -z (commandline) + if test -z "(commandline)" # Copying parts of fzf.fish's _fzf_search_history here, since we can't # directly re-use it if test -z "$fish_private_mode" From 61ac1995c85a39d45773abc1315d6f49af193c21 Mon Sep 17 00:00:00 2001 From: ffact <114359275+ffact@users.noreply.github.com> Date: Tue, 1 Oct 2024 12:06:01 +0000 Subject: [PATCH 4/6] Correct two errors in __pet_new.fish --- functions/__pet_new.fish | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/functions/__pet_new.fish b/functions/__pet_new.fish index fb88bc7..e27acb3 100644 --- a/functions/__pet_new.fish +++ b/functions/__pet_new.fish @@ -3,7 +3,7 @@ function __pet_new --description 'Saves a command as a snippet in pet' set -l cmd (commandline | string split0) # If the command line is empty, let's search history - if test -z "(commandline)" + if test -z (string join "" (commandline -o)) # Copying parts of fzf.fish's _fzf_search_history here, since we can't # directly re-use it if test -z "$fish_private_mode" @@ -16,8 +16,7 @@ function __pet_new --description 'Saves a command as a snippet in pet' set --export FZF_DEFAULT_OPTS '--cycle --layout=reverse --border --height=90% --preview-window=wrap --marker="*"' end set --local --export SHELL (command --search fish) - - set cmd (builtin history --null --show-time="%m-%d %H:%M:%S │ " | \ + set cmd (builtin history --null --show-time="%m-%d %H:%M:%S │ " | fzf --read0 \ --print0 \ --ansi \ @@ -26,9 +25,10 @@ function __pet_new --description 'Saves a command as a snippet in pet' --query=(commandline) \ --preview="echo -- {4..} | fish_indent --ansi" \ --preview-window="bottom:3:wrap" \ - $fzf_history_opts | \ + $fzf_history_opts | # remove timestamps from commands selected - string replace --regex '^\d\d-\d\d \d\d:\d\d:\d\d │ ' '') + string replace --regex '^\d\d-\d\d \d\d:\d\d:\d\d │ ' '' | + string split0) end if test -n "$cmd" From c2965046346dd4ea2f567b4030ce0701e5718a2a Mon Sep 17 00:00:00 2001 From: ffact <114359275+ffact@users.noreply.github.com> Date: Tue, 1 Oct 2024 23:27:36 +0000 Subject: [PATCH 5/6] Add an option terminator Update __pet_new.fish --- functions/__pet_new.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/__pet_new.fish b/functions/__pet_new.fish index e27acb3..8651bb5 100644 --- a/functions/__pet_new.fish +++ b/functions/__pet_new.fish @@ -3,7 +3,7 @@ function __pet_new --description 'Saves a command as a snippet in pet' set -l cmd (commandline | string split0) # If the command line is empty, let's search history - if test -z (string join "" (commandline -o)) + if test -z (string join "" -- (commandline -o)) # Copying parts of fzf.fish's _fzf_search_history here, since we can't # directly re-use it if test -z "$fish_private_mode" From 0fcc0c04636da0642ee15023ffdb4c82a73a0ab7 Mon Sep 17 00:00:00 2001 From: ffact <114359275+ffact@users.noreply.github.com> Date: Tue, 1 Oct 2024 23:39:08 +0000 Subject: [PATCH 6/6] Print the prompt from a new line __pet_new.fish --- functions/__pet_new.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/__pet_new.fish b/functions/__pet_new.fish index 8651bb5..a7acb02 100644 --- a/functions/__pet_new.fish +++ b/functions/__pet_new.fish @@ -32,7 +32,7 @@ function __pet_new --description 'Saves a command as a snippet in pet' end if test -n "$cmd" - echo "* Save a new pet snippet:" + echo -e "\n* Save a new pet snippet:" pet new --tag -- "$cmd" else commandline --function repaint