]> git.armaanb.net Git - charsel.git/blob - src/charsel
removed obnoxious license message, added nato charfile, fixed shebang
[charsel.git] / src / charsel
1 #!/usr/bin/env bash
2 # Merge both global and local charfiles
3 CHARDIR=~/.cache/charsel
4 mkdir $CHARDIR/
5 cp -R /usr/share/charsel/* $CHARDIR/
6 cp -R ~/.local/share/charsel/* $CHARDIR/
7
8 # Check if user provided an input
9 if [ $1 = "list" ]; then
10   echo "The following charfiles are installed"
11   ls $CHARDIR/charfiles
12   exit
13 elif [[ $1 = "help" || $1 = "-h" || $1 = "--help" || $# -ne 1 ]]; then
14   cat /usr/share/doc/charsel/README.md
15   exit
16 else
17
18 # Clear screen
19 clear
20
21 # Define charfile path
22 CHARFILE=$CHARDIR/charfiles/$1
23
24 # Define length of shortcut
25 LENGTH=$(cat $CHARFILE | cut -f 1 -d ',' -s | wc -L | cut -b 1)
26
27 # MOTD
28 cat $CHARDIR/motd
29
30 # Main program
31 while :
32 do
33   # Put charfile into table, showing only the shortcuts below the divider in the charfile
34   cat $CHARFILE | grep -A 100 - | tail -n +2 | column -t  --output-separator ' | ' --separator ','
35
36   # Automatically enter input
37   read -N $LENGTH INPUT
38   
39   # Navigate to the right characther
40   OUTPUT=$(grep $INPUT $CHARFILE | cut -f 2 -d ',' -s)
41
42   # Clear screen
43   clear
44
45   # Copy output to clipboard
46   echo $OUTPUT | xclip -selection clipboard
47 done
48
49 fi