Re: [dwm] [dclip] dmenu-based clipboard manager

From: bill lam <cbill.lam_AT_gmail.com>
Date: Wed, 31 Dec 2008 14:18:30 +0800

On further testing, it appeared that the xclip itself cannot handle
utf8. On replacing xclip with xsel, it now works without problem. What
problem did you encounter in using xsel?

I prefer \034 to \266 as delimiter, since the later is a 2 byte
sequence in utf8 encoding. I'm not sure if tr can handle that. Why
choose \034? Because awk uses it.

on ubuntu, sh is not bash; it is the old sh.

========================================================
#! /bin/bash

# dclip-1.0 || Delta 30dic08

file=$HOME/.dclip_cache
size=10

if [ "$1" == "copy" ]; then
    sel_clip=$(xsel -o)
    sel_file=$(echo -n "$sel_clip"|tr '\n' '\034')
fi
touch $file
if [ "$1" == "paste" ]; then
    shift
    sel_file=$(cat $file | dmenu ${1+"$@"})
    sel_clip=$(echo -n "$sel_file"|tr '\034' '\n')
fi
[ "$sel_clip" == "" ] && exit 1

sed "/^$sel_file$/d" -i $file
cut=$(head -n $(($size-1)) $file)
echo "$sel_file" > $file
echo -n "$cut" >> $file

echo -n "$sel_clip" | xsel -p -i
echo -n "$sel_clip" | xsel -b -i

exit 0
========================================================

-- 
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
唐詩232 孟浩然  春曉
    春眠不覺曉  處處聞啼鳥  夜來風雨聲  花落知多少
Received on Wed Dec 31 2008 - 06:18:30 UTC

This archive was generated by hypermail 2.2.0 : Wed Dec 31 2008 - 06:24:04 UTC