From 401c511f8f08979c83ab71b659e2edb86751d2e4 Mon Sep 17 00:00:00 2001 From: = <=> Date: Fri, 29 Jan 2021 19:28:05 -0500 Subject: [PATCH] Add directory choosing --- mru | 20 ++++++++++++++++++++ prompt | 10 ++++++++++ 2 files changed, 30 insertions(+) diff --git a/mru b/mru index 752c5fc..7cc2aad 100755 --- a/mru +++ b/mru @@ -40,6 +40,15 @@ update() { rm_recent "$1" } +updatedirs() { + cache_name="$1" + if [ -z "$1" ]; then cache_name=home; fi + path="$(printf $cache_info | grep "^$cache_name" - | cut -d: -f2)" + if [ -z "$path" ]; then printf "invalid cache name: $1\n" 1>&2; exit; fi + + list "$1" | sed -n 's:\(.*\)/.*$:\1:p' | sort -u >$XDG_CACHE_HOME/mru/"$cache_name.dirs" +} + # This remove duplicates by deleting files in recent from the main file rm_recent() { file=$XDG_CACHE_HOME/mru/$1 @@ -66,6 +75,15 @@ list() { output "$1" | cut -f3 } +listdirs() { + cache_name="$1" + if [ -z "$1" ]; then cache_name=home; fi + path="$(printf $cache_info | grep "^$cache_name" - | cut -d: -f2)" + if [ -z "$path" ]; then printf "invalid cache name: $1\n" 1>&2; exit; fi + + cat $XDG_CACHE_HOME/mru/"$cache_name.dirs" +} + insert() { if [ -z "$1" ]; then printf "No path given\n" 1>&2; exit; fi cache_name=$2 @@ -94,7 +112,9 @@ insert() { case "$1" in init) init "$2";; update) update $2;; + updatedirs) updatedirs "$2";; output) output "$2";; list) list "$2";; + listdirs) listdirs "$2";; insert) insert "$2" "$3";; esac diff --git a/prompt b/prompt index a3688b4..e0bdfe4 100755 --- a/prompt +++ b/prompt @@ -54,6 +54,7 @@ action() { Command Command to clipboard Choose + Choosedir Select VPN Disable VPN Enable VPN @@ -77,6 +78,7 @@ action() { 'Enable Bar') tmux set -g status on;; 'Command') cmd;; 'Choose') chooser;; + 'Choosedir') choosedir;; 'Command to clipboard') cmd_clip;; 'Username') username;; 'Password') password;; @@ -332,6 +334,14 @@ chooser() { $c "$f" } +choosedir(){ + f=$(mru listdirs | dmenu -i -l 20 -p 'choose dir') + if [ -z "$f" ]; then exit; fi + c=$(dmenu_path | dmenu -i -p 'operation') + if [ -z $c ]; then exit; fi + $c "$f" +} + vpn() { ls }