alias setclip="xclip -selection c"
alias getclip="xclip -selection -c -o"
alias copy="history 2 | head -n1 | sed 's/^ *[0-9]* *//' | setclip"
alias quote="getclip | sed 's/^/> /' | setclip"
of which copy copies the last command I typed to the clipboard, and quote adds quotes to whatever is in my clipboard
however, these don’t work when adding them to atuin dotfiles alias add ... as they do not get quoted properly (I think?) or dotfiles does not support pipes.
# initial state - no aliases set
alifeee@alifeeePC:~$ setclip
setclip: command not found
alifeee@alifeeePC:~$ getclip
getclip: command not found
alifeee@alifeeePC:~$ copy
Command 'copy' not found, did you mean:
command 'ropy' from deb libdisorder-tools (0.0.2+git20130809.8062ee1-4)
command 'mcopy' from deb mtools (4.0.33-1+really4.0.32-1build1)
command 'rcopy' from deb rdmacm-utils (39.0-1)
command 'fcopy' from deb fai-client (5.10.3ubuntu1)
command 'hcopy' from deb hfsutils (3.2.6-15build2)
command 'copyq' from deb copyq (6.0.1-1)
Try: sudo apt install <deb name>
alifeee@alifeeePC:~$ quote
''
# now add aliases - quotes disappear ?
alifeee@alifeeePC:~$ atuin dotfiles alias set setclip "xclip -selection c"
Aliasing 'setclip=xclip -selection c'.
alifeee@alifeeePC:~$ atuin dotfiles alias set getclip "xclip -selection c"
Aliasing 'getclip=xclip -selection c -o'.
alifeee@alifeeePC:~$ atuin dotfiles alias set copy "history 2 | head -n1 | sed 's/^ *[0-9]* *//' | setclip"
Aliasing 'copy=history 2 | head -n1 | sed 's/^ *[0-9]* *//' | setclip'.
alifeee@alifeeePC:~$ atuin dotfiles alias set quote "getclip | sed 's/^/> /' | setclip"
Aliasing 'quote=getclip | sed 's/^/> /' | setclip'.
alifeee@alifeeePC:~$ atuin dotfiles alias list
copy=history 2 | head -n1 | sed 's/^ *[0-9]* *//' | setclip
getclip=xclip -selection c
quote=getclip | sed 's/^/> /' | setclip
setclip=xclip -selection c
# new errors when launching terminal
alifeee@alifeeePC:~$ . .bashrc
bash: alias: note1.txt: not found
bash: alias: *// | setclip: not found
bash: / | setclip: Permission denied
# commands do not work (because of quoting issues) - they work fine if used raw in .bashrc
alifeee@alifeeePC:~$ echo "turtles :)" | setclip
alifeee@alifeeePC:~$ getclip
turtles :)
alifeee@alifeeePC:~$ copy
sed: -e expression #1, char 3: unterminated `s' command
alifeee@alifeeePC:~$ quote
''
atuin init bash was good to know to see the output file to debug
broken behaviour
using double quotes " as outer quotes
$ atuin dotfiles alias set getclip "xclip -selection c -o"
$ atuin dotfiles alias set setclip "xclip -selection c"
$ atuin dotfiles alias set copy "history 2 | head -n1 | sed 's/^ *[0-9]* *//' | setclip"
$ atuin dotfiles alias set quote "getclip | sed 's/^/> /' | setclip"
$ atuin init bash
...
#------------------------------------------------------------------------------
fi # (include guard) end of main content
alias copy='history 2 | head -n1 | sed 's/^ *[0-9]* *//' | setclip'
alias getclip='xclip -selection c -o'
alias quote='getclip | sed 's/^/> /' | setclip'
alias setclip='xclip -selection c'
fixed behaviour
using single quotes ' as outer quotes
$ atuin dotfiles alias set getclip 'xclip -selection c -o'
$ atuin dotfiles alias set setclip 'xclip -selection c'
$ atuin dotfiles alias set copy 'history 2 | head -n1 | sed "s/^ *[0-9]* *//" | setclip'
$ atuin dotfiles alias set quote 'getclip | sed "s/^/> /" | setclip'
$ atuin init bash
...
#------------------------------------------------------------------------------
fi # (include guard) end of main content
alias copy='history 2 | head -n1 | sed "s/^ *[0-9]* *//" | setclip'
alias getclip='xclip -selection c -o'
alias quote='getclip | sed "s/^/> /" | setclip'
alias setclip='xclip -selection c'
diff
$ atuin dotfiles alias set getclip “'xclip -selection c -o”‘
$ atuin dotfiles alias set setclip "’xclip -selection c“'
$ atuin dotfiles alias set copy ”‘history 2 | head -n1 | sed ’“s/^ [0-9] *//'” | setclip“'
$ atuin dotfiles alias set quote ”‘getclip | sed ’“s/^/> /'” | setclip“'
$ atuin init bash
… #------------------------------------------------------------------------------
fi # (include guard) end of main content
alias copy=‘history 2 | head -n1 | sed ’”s/^ [0-9] *//‘" | setclip’
alias getclip=‘xclip -selection c -o’
alias quote=‘getclip | sed ’“s/^/> /'” | setclip’
alias setclip=‘xclip -selection c’
so it looks like atuin dotfiles alias set uses single quotes to surround the content, so if you copy an alias that uses double quotes, there are quoting issues as nested single quotes may no longer next properly.
a fix for a user is to never use double quotes in the outer context.