Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions functions/__pet_new.fish
Original file line number Diff line number Diff line change
@@ -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 (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"
Expand All @@ -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 \
Expand All @@ -26,13 +25,14 @@ 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"
echo "* Save a new pet snippet:"
echo -e "\n* Save a new pet snippet:"
pet new --tag -- "$cmd"
else
commandline --function repaint
Expand Down
9 changes: 6 additions & 3 deletions functions/__pet_preview.fish
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
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/\]: .*//'
set_color normal
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
Expand Down