-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrice-code.sh
executable file
·36 lines (29 loc) · 1023 Bytes
/
rice-code.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
#!/bin/bash
FILE_PATH=$1
ICONS_DIR=$HOME/.rice-code/icons
if [[ "$FILE_PATH" != "." ]]; then
DIRECTORY_NAME=$(basename "$FILE_PATH")
else
DIRECTORY_NAME=$(basename $(realpath "$FILE_PATH"))
fi
LANGUAGE_JSON=$($HOME/.rice-code/get_language "$FILE_PATH")
LANGUAGE=$(echo "$LANGUAGE_JSON" | jq -r 'to_entries | max_by(.value) | .key')
ICON="$ICONS_DIR/$LANGUAGE.png"
# Look for an existing icon in other results if the first one doesn't exist
if [[ ! -f "$ICON" ]]; then
for lang in $(echo "$LANGUAGE_JSON" | jq -r 'to_entries | sort_by(.value) | reverse | .[].key'); do
ICON="$ICONS_DIR/$lang.png"
if [[ -f "$ICON" ]]; then
break
fi
done
fi
# Display the icon if it exists, otherwise display the directory name
if [[ -f "$ICON" ]]; then
jp2a --colors --size=40x20 "$ICON"
else
figlet -f ~/.local/share/fonts/figlet-fonts/3d.flf "$DIRECTORY_NAME" | lolcat
fi
echo "Happy $DIRECTORY_NAME-ing!" | lolcat -p 1
# Open file in Visual Studio Code
code "$FILE_PATH"