aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2023-12-22 15:42:36 +0100
committerFederico Angelilli <code@fedang.net>2023-12-22 15:42:36 +0100
commit84b8b4f217f256458ba49332052e8e6d54c9b352 (patch)
tree1b000ed3b6e3f6f19f1ccf64bf1996987f2e99ba
parentd5a3f0aa24e27e5da37237581f42e8136592e6a2 (diff)
Add --plain option for cmd_list
-rwxr-xr-xcrypt.sh49
1 files changed, 36 insertions, 13 deletions
diff --git a/crypt.sh b/crypt.sh
index fbd0d94..e3d7928 100755
--- a/crypt.sh
+++ b/crypt.sh
@@ -530,20 +530,43 @@ _cmd_list_fmt() {
}
cmd_list() {
+ local opts plain=0
+ opts="$($GETOPT -o p -l plain -n "$PROGRAM" -- "$@")"
+ local err=$?
+ eval set -- "$opts"
+ while true; do
+ case $1 in
+ -p|--plain) plain=1; shift ;;
+ --) shift; break ;;
+ esac
+ done
+
local path="$CRYPT_PATH/${1#$CRYPT_PATH}"
- local header="Crypt ($(cd $CRYPT_PATH; dirs +0))"
-
- if [ -n "$1" ]; then
- local color="" reset=""
- # DIR ENTRY 2
- color=$(_color ${entries_color[2]})
- reset=$(_color reset)
- header="$color$1$reset"
- fi
- echo "$header"
- tree -f --noreport -l "$path" | tail -n +2 | while IFS='' read -r line; do _cmd_list_fmt "$line"; done | \
- column -t -s$'\t' | sed 's/\v/\t\t/' # Make pretty columns
+ if [ $plain -eq 0 ]; then
+ local header="Crypt ($(cd $CRYPT_PATH; dirs +0))"
+
+ if [ -n "$1" ]; then
+ local color="" reset=""
+ # DIR ENTRY 2
+ color=$(_color ${entries_color[2]})
+ reset=$(_color reset)
+ header="$color$1$reset"
+ fi
+
+ echo "$header"
+ tree -f --noreport -l "$path" | tail -n +2 | while IFS='' read -r line; do _cmd_list_fmt "$line"; done | \
+ column -t -s$'\t' | sed 's/\v/\t\t/' # Make pretty columns
+ else
+ local tmp=$(find "$path" -type f -iname '*.gpg' | sed -e "s~^$path\/*~~" | sort | \
+ while IFS='' read -r line; do find_info "$line"; echo "${line%.gpg} $file_entry ${line%$file_glob.gpg}"; done)
+
+ local reps=$(echo "$tmp" | uniq -D -f 2)
+
+ # XXX: Highly inefficient...
+ echo "$tmp" | comm -23 - <(echo "$reps") | awk '{print $3" "$2}'
+ echo "$reps" | awk '{print $1" "$2}'
+ fi
}
cmd_git() {
@@ -650,7 +673,7 @@ cmd_help() {
$PROGRAM edit file
Edit the file using the entry's associated edit_action
- $PROGRAM list
+ $PROGRAM list [--plain]
List the crypt structure, associating each file to its entry name
$PROGRAM info