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