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