47 lines
1.7 KiB
Fish
47 lines
1.7 KiB
Fish
# 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'
|
|
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 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 srht_user (string split ' ' (hut meta show)[1])[1]
|
|
set -l url "https://paste.sr.ht/$srht_user/$hash"
|
|
string trim $url | wl-copy
|
|
echo "$url copied to clipboard."
|
|
case '*'
|
|
echo 'Unhandled case!'
|
|
false
|
|
return
|
|
end
|
|
end
|