# This function lets the user conveniently upload a paste to sr.ht, # and copy its url. You can also copy the url of a paste # you've already uploaded. function pb --description 'Upload a paste to sr.ht' function select_paste set -l lines (string split \n (hut paste list) | string trim | string match -rv '^$') if test (count $lines) -le 1 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] 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 case create set -l output (hut paste create $args) if not test $status = 0 echo 'Error creating paste!' false return end set -l url (string match -r 'https://paste\.sr\.ht/.+/[a-zA-Z0-9]+$' $output) echo $url | wl-copy echo "$url copied to clipboard." case copy 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 'Unknown arguments!' return 1 end end