summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2025-01-16 11:29:00 -0500
committerBen Sima <ben@bsima.me>2025-02-07 13:14:08 -0500
commit15a35828209c08cd263bf1317505ffddfe53a5c5 (patch)
tree6e75f0dc29a7a00ecff67ea6ed70e0f17f2ad02d
parent1bb0ee40e2ec38b035a94c382cf15b8ff2e2a65d (diff)
print perms in explicit table with -v
because i always forget how to read these, idk why
-rwxr-xr-xperms26
1 files changed, 24 insertions, 2 deletions
diff --git a/perms b/perms
index d806173..d38548b 100755
--- a/perms
+++ b/perms
@@ -1,3 +1,25 @@
#!/usr/bin/env bash
-echo $(realpath $1)
-stat --printf "octal: %a\nhuman: %A\nowner: %U (%u)\ngroup: %G (%g)\n" "$@"
+
+if [[ $1 == "-v" ]]; then
+ export verbose=1
+ shift
+fi
+file="$1"
+echo $(realpath "$file")
+
+if [[ -n "$verbose" ]]; then
+ perm=$(stat --printf "%a" "$file")
+ declare -A permMap=( [0]="no perms" [1]="execute" [2]="write" [3]="write, execute"
+ [4]="read" [5]="read, execute" [6]="read, write" [7]="read, write, execute" )
+
+ owner="${permMap[${perm:0:1}]}"
+ group="${permMap[${perm:1:1}]}"
+ other="other:\t\t\t${permMap[${perm:2:1}]}"
+else
+ owner=""
+ group=""
+ other=""
+fi
+
+
+stat --printf "octal: %a\nhuman: %A\nowner: %U (%u)\t$owner\ngroup: %G (%g)\t$group\n$other" "$file"