forked from matryer/xbar-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquickfolders.10m.sh
executable file
·47 lines (40 loc) · 1.8 KB
/
quickfolders.10m.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
# <xbar.title>QuickFolders</xbar.title>
# <xbar.version>v1.0</xbar.version>
# <xbar.author>Alex</xbar.author>
# <xbar.author.github>alexrockt</xbar.author.github>
# <xbar.desc>Quick access to folders, that have files with certain suffix in it. For more details look at https://blog.aruehe.io/quickfolders-a-bitbar-plugin/</xbar.desc>
# <xbar.image>https://raw.githubusercontent.com/alexrockt/misc/master/quickfolders-screenshot.png</xbar.image>
# <xbar.dependencies>bash</xbar.dependencies>
# <xbar.abouturl>https://blog.aruehe.io/quickfolders-a-bitbar-plugin/</xbar.abouturl>
PATH_TO_FOLDER=/path/to/a/folder
#FILETYPES TO NOTE ( e.g. pdf|doc) this will be put into grep for filtering
FILETYPES="pdf|doc"
#Regular expression, to filtering during the find operation. E.g. to exclude . files
REX=".*/\..*"
#This variable stores the result
ALLFOLDERS=$(find "${PATH_TO_FOLDER}" \( ! -regex "$REX" \) -type f | grep -E "($FILETYPES)" | sed -E 's|/[^/]+$||' | uniq | sort)
IFS='
'
echo "QuickFolders | color=green size=10"
echo "---"
LASTFOLDER=""
LASTSUBFOLDER=""
for l in $ALLFOLDERS
do
FOLDER=$(echo "$l" | awk -F/ '{print $(NF-1)}')
SUBFOLDER=$(echo "$l" | awk -F/ '{print $(NF)}')
# same folder as before, check if same subfolder
if [ "$LASTFOLDER" = "$FOLDER" ]; then
# new folder - print
if [ "$LASTSUBFOLDER" != "$SUBFOLDER" ]; then
printf "┗━━━%s | terminal=false refresh=true bash=/usr/bin/open param1='%s' size=10 color=green\n" "$SUBFOLDER" "$l"
LASTSUBFOLDER=$SUBFOLDER
fi
else
printf "%s | size=12 color=white\n" "$FOLDER"
printf "┗━━━%s | terminal=false refresh=true bash=/usr/bin/open param1='%s' size=10 color=green\n" "$SUBFOLDER" "$l"
LASTFOLDER=$FOLDER
LASTSUBFOLDER=$SUBFOLDER
fi
done