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