From b1dffe01c0128ec956640e84dfb3166cd57f626e Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Sat, 29 Mar 2025 21:45:07 -0400 Subject: [PATCH] AutoYADM commit: 2025-03-29 21:45:07 --- .config/fish/functions/pb.fish | 56 +++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/.config/fish/functions/pb.fish b/.config/fish/functions/pb.fish index 3dea907c..07b8f021 100644 --- a/.config/fish/functions/pb.fish +++ b/.config/fish/functions/pb.fish @@ -22,6 +22,13 @@ function pb --description 'Upload a paste to sr.ht' set -l hash (string split ' ' $selection)[2] echo $hash end + function get_user + if set -q srht_user + echo "~$srht_user" + else + string split ' ' (hut meta show)[1][1] + end + end set -l cmd $argv[1] set -l args $argv[2..] switch $cmd @@ -37,32 +44,33 @@ function pb --description 'Upload a paste to sr.ht' echo "$url copied to clipboard." case copy - # set -l lines (string split \n (hut paste list) | string trim | string match -rv '^$') - # if test (count $lines) -le 1 - # echo 'No pastes found!' - # false - # return - # end - # for i in (seq 1 2 (count $lines)) - # set -l meta $lines[$i] - # set -l filename $lines[(math $i + 1)] - # set -l append "$filename: $meta" - # if not set -q list - # set --function list $append - # else - # set --function list $list $append - # end - # end - # set -l selection (printf '%s\n' $list | fzf) - # set -l hash (string split ' ' $selection)[2] - set -l hash (select_paste) - set -l srht_user (string split ' ' (hut meta show)[1])[1] - set -l url "https://paste.sr.ht/$srht_user/$hash" + set -l hash (select_paste; or 1) + if test hash = 1 + echo 'Error selecting a paste!' + return 1 + end + set -l url "https://paste.sr.ht/$(get_user)/$hash" string trim $url | wl-copy echo "$url copied to clipboard." + case delete + set -l hash (select_paste; or 1) + if test hash = 1 + echo 'Error selecting a paste!' + return 1 + end + hut paste delete $hash + echo $hash 'deleted successfully!' + case show + set -l hash (select_paste; or 1) + if test hash = 1 + echo 'Error selecting a paste!' + return 1 + end + hut paste show $hash + case id + select_paste; or return 1 case '*' - echo 'Unhandled case!' - false - return + echo 'Unknown arguments!' + return 1 end end