]> git.armaanb.net Git - charsel.git/blob - src/charsel
6713b599d56b097afc7931b652aa97c0a132f1eb
[charsel.git] / src / charsel
1 # Copyright 2020 Armaan Bhojwani
2
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
7
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12
13 # You should have received a copy of the GNU General Public License
14 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
15
16 #!/usr/bin/env sh
17 # Merge both global and local charfiles
18 CHARDIR=~/.cache/charsel
19 mkdir $CHARDIR/
20 cp -R /usr/share/charsel/* $CHARDIR/
21 cp -R ~/.local/share/charsel/* $CHARDIR/
22
23 # Check if user provided an input
24 if [ $1 = "list" ]; then
25   echo "The following charfiles are installed"
26   ls $CHARDIR/charfiles
27   exit
28 elif [[ $1 = "help" || $1 = "-h" || $1 = "--help" || $# -ne 1 ]]; then
29   cat /usr/share/doc/charsel/README.md
30   exit
31 else
32
33 # Clear screen
34 clear
35
36 # Define charfile path
37 CHARFILE=$CHARDIR/charfiles/$1
38
39 # Define length of shortcut
40 LENGTH=$(cat $CHARFILE | cut -f 1 -d ',' -s | wc -L | cut -b 1)
41
42 # MOTD
43 cat $CHARDIR/motd
44
45 # Main program
46 while :
47 do
48   # Put charfile into table, showing only the shortcuts below the divider in the charfile
49   cat $CHARFILE | grep -A 100 - | tail -n +2 | column -t  --output-separator ' | ' --separator ','
50
51   # Automatically enter input
52   read -N $LENGTH INPUT
53   
54   # Navigate to the right characther
55   OUTPUT=$(grep $INPUT $CHARFILE | cut -f 2 -d ',' -s)
56
57   # Clear screen
58   clear
59
60   # Copy output to clipboard
61   echo $OUTPUT | xclip -selection clipboard
62 done
63
64 fi