]> git.armaanb.net Git - charsel.git/blob - src/charsel
80909d3f2751f49aa0fb01836801cefb0238954a
[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=/tmp/charsel
19 cp -R /usr/share/charsel/* $CHARDIR/
20 cp -R ~/.local/share/charsel/* $CHARDIR/
21
22 # Check if user provided an input
23 if [ $1 = "list" ]; then
24   echo "The following charfiles are installed"
25   ls $CHARDIR/charfiles
26   exit
27 elif [[ $1 = "help" || $1 = "-h" || $1 = "--help" || $# -ne 1 ]]; then
28   cat /usr/share/doc/charsel/README.md
29   exit
30 else
31
32 # Clear screen
33 clear
34
35 # Define charfile path
36 CHARFILE=$CHARDIR/charfiles/$1
37
38 # Define length of shortcut
39 LENGTH=$(cat $CHARFILE | cut -f 1 -d ',' -s | wc -L | cut -b 1)
40
41 # MOTD
42 cat /tmp/charsel/motd
43
44 # Main program
45 while :
46 do
47   # Put charfile into table, showing only the shortcuts below the divider in the charfile
48   cat $CHARFILE | grep -A 100 - | tail -n +2 | column -t  --output-separator ' | ' --separator ','
49
50   # Automatically enter input
51   read -N $LENGTH INPUT
52   
53   # Navigate to the right characther
54   OUTPUT=$(grep $INPUT $CHARFILE | cut -f 2 -d ',' -s)
55
56   # Clear screen
57   clear
58
59   # Copy output to clipboard
60   echo $OUTPUT | xclip -selection clipboard
61 done
62
63 fi