You are not logged in.

#1 2010-01-06 15:50:14

caption
Member
Registered: 2009-11-25
Posts: 1

quick dmenu selection buffer manager

I hear you guys like dmenu, so I thought you might find this useful. This will give you a menu of buffers to pick from and pop them onto the primary x selection and also into the gnu screen buffer. I think it works mostly, but I'm sure someone can break it given half a chance. I'm horrible at bash scripting, so forgive my unstylish code.

#!/bin/bash
CLIPDIR=$HOME/.clipboard
SCREEN_EXCHANGE=$HOME/.screen-exchange
DMENU_PROMPT='Buffers: '
DMENU="dmenu -l 10 -p $DMENU_PROMPT -b -fn $DMENU_FONT -nf $DMENU_NF -nb $DMENU_NB -sb $DMENU_SB -sf $DMENU_SF"
SHOWCLIPS=20
TITLELEN=30

picker()
{
  ARGV=("$@")
  pick=`(for ((i=0; i<${#ARGV[@]}; i++)) ; do \
    [[ x${ARGV[$i]} != x""  ]] && \
    echo -e ${ARGV[$i]}'|||'$(cat "$CLIPDIR/${ARGV[$i]}"|cut -c 1-$TITLELEN); done) |$DMENU`
  if [ x"$pick" != x"" ]
  then
    cat "$CLIPDIR/${pick%%|||*}" | xsel -i -p
    xsel --keep
    cat "$CLIPDIR/${pick%%|||*}" > $SCREEN_EXCHANGE
    screen -X eval "readbuf"
  fi
}

picker $(IFS=`printf '\n\t'` ; n=0 \
  ls -1 --color=never -t $CLIPDIR | \
    while read -r filename ; do \
    [[ $n -lt $SHOWCLIPS ]] || break ; let n++ ; \
        [[ -f $CLIPDIR/$filename ]] && echo "${filename}"; done)
exit 0

Here's the script I use to store clips:

#!/bin/bash
CLIPDIR=$HOME/.clipboard
SCREEN_EXCHANGE=$HOME/.screen-exchange
TITLELEN=20

if [ ! -e $CLIPDIR ]
then
  mkdir -p $CLIPDIR
fi

CLIP=$(xsel -o)
CLIPFILE=$(date +%s)\.$(hostname)
if ! grep -q "$CLIP" $CLIPDIR/*
then
    echo -n $CLIP > "$CLIPDIR/$CLIPFILE"
fi

xsel --keep

Offline

Board footer

Powered by FluxBB