Add clipboard flag to copy URL to clipboard instead of print.

This commit is contained in:
2026-03-11 16:21:14 +01:00
parent 9c0e6fc1bc
commit 213cd56afc
2 changed files with 95 additions and 15 deletions

53
yt-conv
View File

@@ -24,16 +24,57 @@ set -euo pipefail
# 3. This notice may not be removed or altered from any source
# distribution.
CLIP=0
if [ $# -ne 1 ]
then
>&2 echo "Usage: $0 <url>"
exit 1
elif [ "$1" = "-h" ]
then
echo "Usage: $0 <url>"
exit 0
fi
URL="$1"
for arg in "$@"
do
case "$arg" in
-c|--clip)
CLIP=1
;;
-h|--help)
echo "Usage: $0 [-c] <url>"
exit 0
;;
*)
URL="$arg"
;;
esac
done
if [ -z "${URL:-}" ]
then
>&2 echo "No URL provided"
exit 1
fi
YT_URL="${URL//https:\/\/*\//https:\/\/www.youtube.com\/}"
echo "$YT_URL"
if [ $CLIP -eq 0 ]
then
echo "$YT_URL"
else
if [ "$XDG_SESSION_TYPE" = "wayland" ]
then
if ! command -v wl-copy &> /dev/null
then
>&2 echo "wl-copy not found, cannot copy to clipboard"
exit 1
fi
echo "$YT_URL" | wl-copy
else
if ! command -v xclip &> /dev/null
then
>&2 echo "xclip not found, cannot copy to clipboard"
exit 1
fi
echo "$YT_URL" | xclip -sel clip
fi
fi