@ 260802.2

200502.1 · 5e761f4eb3ddb1a900df7f99dde6dbe8b5eb0b58

fix x11 copy & paste, particularly with neovim

It appears that copying with xclip and pasting into gmail/gdocs results in newlines getting stripped. But apparently using xsel works. So switch everything over to xsel, including neovim. I could have achieved this by just uninstalling xclip (and neovim would then pickup xsel automatically), but pass depends on xclip, so we still need it. Ah well.

We also add `xcp`, which will just do the right thing in terms of copying from stdin based on which tool is installed.

See also: https://github.com/neovim/neovim/issues/5853

reading declarations

.config/nvim/include/options.vim

@@ -18,6 +18,25 @@ set hidden " instead of needing to use the '+' or '*' registers explicitly. set clipboard+=unnamedplus +" Prefer xsel over xclip. With xclip, pasting into gmail/gdocs results in+" stripping all newlines. But with xsel, it works correctly.+" See: https://github.com/neovim/neovim/issues/5853+if executable('xsel')+  " This is copied directly from runtime/autoload/provider/clipboard.vim.+  let g:clipboard = {+        \   'name': 'myxsel',+        \   'copy': {+        \      '+': 'xsel --nodetach --input --clipboard',+        \      '*': 'xsel --nodetach --input --primary',+        \    },+        \   'paste': {+        \      '+': 'xsel --output --clipboard',+        \      '*': 'xsel --output --primary',+        \   },+        \   'cache_enabled': 1,+        \ }+endif+ " There's no need to do syntax highlighting past this many columns. The default " of 3000 is a bit and degrades performance. set synmaxcol=200

bin/arch-install

@@ -126,6 +126,7 @@ xpkgs() {     nitrogen \     numlockx \     xclip \+    xsel \     xdotool \     trayer \     freerdp \

bin/clipme

@@ -11,4 +11,4 @@ else     exit 1 fi -echo -n "$toclip" | xclip -selection clipboard+echo -n "$toclip" | xcp

bin/gist

@@ -3,5 +3,5 @@ # Uploads a gist and copies to the resulting URL to the clipboard. # (Instead of the primary X selection, which requires using the mouse. Bah.) url=$(/usr/bin/gist "$@")-echo "$url" | xclip -selection clipboard+echo "$url" | xcp echo "$url"

bin/hub-select-pr

@@ -1,5 +1,5 @@ #!/bin/sh  url="$(grep "/$1 " | awk '{print $1}')"-echo "$url" | xclip -selection clipboard+echo "$url" | xcp echo "$url"

bin/place

@@ -23,7 +23,7 @@ bat_width=115 # Determine the width of the pager based on the width of the system tray and # battery indicator. If it's a laptop, include the battery indicator. Otherwise, # leave it out.-if [ -f "$HOME/.laptop" ]; then+if is-laptop; then   pager_width=$((mwidth - bat_width - tray_width)) else   pager_width=$((mwidth - tray_width))@@ -46,7 +46,7 @@ killall trayer         --SetDockType true &)  # If this is a laptop, kill the battery notifier and restart it too.-if [ -f "$HOME/.laptop" ]; then+if is-laptop; then   # shellcheck disable=SC2009   ps aux | grep -v grep | grep batrem | awk '{print $2}' | xargs -r kill   (batrem -s -i 10 | \

bin/screenshot

@@ -8,4 +8,9 @@ fi file="$1" sleep 3 echo "select a window!"-exec scrot -s "$file"+scrot -s "$file"++sound=/usr/share/sounds/freedesktop/stereo/screen-capture.oga+if [ -r "$sound" ]; then+  ogg123 "$sound"+fi

bin/toggle-tap-to-click

@@ -1,6 +1,6 @@ #!/bin/sh -if [ ! -f "$HOME/.laptop" ]; then+if ! is-laptop; then   exit 1 fi case "$(myhostname)" in

bin/urldecode-copy

@@ -2,4 +2,4 @@  x=$(python2 -c "import urllib; print urllib.unquote('$1'),") echo $x-printf "%s" $x | xclip -selection clipboard+printf "%s" $x | xcp

bin/urlencode-copy

@@ -3,4 +3,4 @@ # RFC 3986, please. x=$(python2 -c "import urllib; print urllib.quote('$1', safe='~'),") echo $x-printf "%s" $x | xclip -selection clipboard+printf "%s" $x | xcp

bin/xcp

new file mode 100755@@ -0,0 +1,19 @@+#!/bin/sh++# Simple script to copy to X11 clipboard. Uses xsel if available, and falls+# back to xclip. xsel is preferred because I found that copying using xclip+# and pasting into certain textareas (gmail, google docs) resulted in all+# newlines being stripped. But using xsel worked correctly.+#+# Similarly, we configure neovim to use xsel if available.+#+# See also: https://github.com/neovim/neovim/issues/5853++if cmd-exists xsel; then+  xsel -i --clipboard+elif cmd-exists xclip; then+  xclip -selection clipboard+else+  echo "neither xsel (preferred) nor xclip are installed" >&2+  exit 1+fi