scripts

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

commit 3fca4f50b5fb25b8dfebd34d46a6a607b49eab0d
parent 115ff9a06870d51702918cd926199e2271bf4f92
Author: Sebastiano Tronto <sebastiano.tronto@gmail.com>
Date:   Sun, 15 May 2022 13:22:04 +0200

Some fixes

Diffstat:
MTODO | 2+-
Msel | 65++++++++++++++++++++++++++++++++++-------------------------------
Msfeed-browser | 18+++++++++++++-----
3 files changed, 48 insertions(+), 37 deletions(-)

diff --git a/TODO b/TODO @@ -1,4 +1,4 @@ -* dmenu-bookmarks: add option for different directory +* sel: fix globbing filenames with spaces; once done, remove "addall" * mblaze-extras: maybe remove script and just use aliases? diff --git a/sel b/sel @@ -1,10 +1,11 @@ #!/bin/sh # Allow bulk operations on a list of selected files. -# Usage: sel [command] +# Usage: sel [-m menu] [command] # If no command is specified, shows the list of selected files # Commands: -# add [files|dirs|all]: add files to selection +# add [files...]: add files to selection +# addall: add all files in the current folder to selection # clear: clear selection # cp: copy to current dir, possbily after editing filenames # edit: open selection in editor @@ -12,44 +13,44 @@ # open: open files using open-file # rm: remove selected files and clear selection -# Requires: dmenu (or similar), trashrm (optional), open-file (for open only) +# Requires: dmenu (or similar), trash (optional), open-file (for open only) -# TODO: add possibility of specifying file. -# TODO 2: The usage of paste(1) is a bit of a hack, and for example it does +# TODO: The usage of paste(1) is a bit of a hack, and for example it does # not work if filenames contain tab characters. Fix this. -# Bug (probably not fixing this, use virename): moving moving a file to + +# Another TODO: add by filename does not work when globbing filenames with +# space. E.g. sel add "a file.txt" works, but sel add *.txt does not. +# Why does this happen? + +# Bug (probably not fixing this, use virename): moving a file to # itself gives an error and rm is not run. file="$XDG_DATA_HOME/selectedfiles" -menu=${MENU:-dmenu} +menu="" # default uses dmenu-filepicker default editor=${EDITOR:-vi} -rm=trashrm # replace with rm -r if you don't use trashrm +rm="trash rm" # replace with rm -r if you don't use trash -add() { - if [ -z "$2" ]; then - dmenu-filepicker >> "$file" - else - case "$2" in - files) - ls | while read f; do - [ -f "$f" ] && echo "$PWD/$f" >> "$file" - done - ;; - dirs) - ls | while read f; do - [ -d "$f" ] && echo "$PWD/$f" >> "$file" - done - ;; - all) - ls | while read f; do - echo "$PWD/$f" >> "$file" - done - ;; - *) - echo "$2: not a valid option" +while getopts "m:" opt; do + case "$opt" in + m) + menu="$OPTARG" ;; esac +done +shift `expr $OPTIND - 1` + +add() { + shift 1 + if [ -z "$1" ]; then + if [ -n "$menu" ]; then + dmenu-filepicker -m "$menu" >> "$file" + else + dmenu-filepicker >> "$file" + fi + else + for i in "$@"; do realpath "$i" >> "$file"; done fi + sort -u -o "$file" "$file" } clear() { @@ -91,7 +92,9 @@ else case "$1" in add) add $@ - sort -u -o "$file" "$file" + ;; + addall) + add * ;; clear) clear diff --git a/sfeed-browser b/sfeed-browser @@ -11,15 +11,23 @@ # them before displaying the choice of feeds. Contact me if you are interested # in using it. +# Usage: sfeed-browser [-m menu] # Requires: sfeed, dmenu-file-picker (or similar), open-url (or similar) filepicker="dmenu-filepicker" # Try "nnn -p -" -menu=${MENU:-dmenu} -menuopts="-l 35 -i" +menu="dmenu -l 35 -i" urlopener=open-url -sfd="box/sfeed" +sfd="$HOME/box/sfeed" showlast=10 +while getopts "m:" opt; do + case "$opt" in + m) + menu="$OPTARG" + ;; + esac +done + # Might add more stuff later fixurl() { sed 's/old\.reddit\.com/reddit\.com/' @@ -47,7 +55,7 @@ feedmenu() { while read line; do feedname=$(echo "$line" | sed 's/.*\///') sfeed_plain "$sfd/files/$feedname" | head -$showlast - done | $menu $menuopts + done | $menu } openfeeds() { @@ -57,6 +65,6 @@ openfeeds() { done | xargs $urlopener } -$filepicker "$sfd/urls" | dirtofeedpaths > "$sfd/last" +$filepicker "$@" "$sfd/urls" | dirtofeedpaths > "$sfd/last" pathstosfeedrc < "$sfd/last" > "$sfd/sfeedrc" sfeed_update "$sfd/sfeedrc" && feedmenu < "$sfd/last" | openfeeds