diff --git a/.aliases b/.aliases index 4702f9a..bcb9d72 100644 --- a/.aliases +++ b/.aliases @@ -64,7 +64,28 @@ itks() { xdg-open "https://google.com/search?q=$1+site%3Aitk.samfundet.no" } -alias clip="wl-copy" +clip() { + input=$(cat) + + if [ -n "$WAYLAND_DISPLAY" ] && command -v wl-copy >/dev/null 2>&1; then + printf "%s" "$input" | wl-copy + return + fi + + if [ -n "$DISPLAY" ] && command -v xclip >/dev/null 2>&1; then + printf "%s" "$input" | xclip -selection clipboard + return + fi + + if [ -n "$TERM" ]; then + esc="$(printf "%s" "$input" | base64 | tr -d '\r\n')" + printf "\033]52;c;%s\a" "$esc" + return + fi + + echo "No clipboard method available" >&2 + return 1 +} dchmod () { find $2 -type d -exec chmod $1 {} +