scripts

Various scripts for UNIX-like systems
git clone https://git.tronto.net/scripts
Download | Log | Files | Refs | README

commit 8d65aa80aaa523eba71ac84d72bee269260508b9
parent f18383243b2da10f537b090e49100e1f96affd93
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Fri, 11 Feb 2022 17:54:22 +0100

Added clip, a primitive clipboard manager

Diffstat:
MMakefile | 1+
Aclip | 34++++++++++++++++++++++++++++++++++
2 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/Makefile b/Makefile @@ -4,6 +4,7 @@ SCRIPTS = addressgrep \ battery-checknow \ battery-status \ brightness \ + clip \ config-backup \ dmenu-bookmarks \ dmenu-dwm-sessionmanager \ diff --git a/clip b/clip @@ -0,0 +1,34 @@ +#!/bin/sh + +# A primitive clipboard manager. Saves the current selection to a temporary +# file and shows all saved selections in dmenu for the user to select one. +# It does not check for duplicates and it fails if there it can't +# create the temporary directory with the designated name. + +# Requires: xsel, dmenu + +# TODO: improve formatting in dmenu + +menu="dmenu" +menuopts="-l 25" + +dir="/tmp/clipdir" +mkdir -p "$dir" + +file="$(mktemp -p $dir $(date +%s).XXXXX)" +xsel > "$file" + +list="$(mktemp)" +ls $dir > $list; + +lines="$(mktemp)" +for f in $dir/*; do + nlines=$(expr 1 + "$(wc -l $f | awk '{print $1}')") + fclean=$(echo $f | sed "s|$dir\/||") + printf "$fclean ($nlines) | $(head -n 1 $f)\n" >> "$lines" +done + +selected=$(sort -r $lines | $menu $menuopts | awk '{print $1}') +if [ -n "$selected" ]; then + xsel -ib < "$dir/$selected" +fi