3 # (C) Copyright Armaan Bhojwani, 2020
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <https://www.gnu.org/licenses/>.
18 # Merge both global and local charfiles
20 CHARDIR=~/.cache/charsel
22 if [[ ! -d $CHARDIR ]]
25 elif [[ ! "$(ls -A $CHARDIR)" ]]
27 cp -rf /usr/share/charsel/- $CHARDIR/
28 cp -rf $HOME/.local/share/charsel/- $CHARDIR/
31 # Check for user inputs
36 echo "The following charfiles are installed"
39 elif [[ $1 == "help" \
44 cat /usr/share/doc/charsel/README.md
48 # Define charfile path
49 CHARFILE=$CHARDIR/charfiles/$1
51 # Check if given charfile exists
52 if [[ ! -f $CHARFILE ]]
54 echo "Please enter a valid charfile."
59 # Define length of shortcode
60 LENGTH=$(cat $CHARFILE \
61 | cut -f 1 -d ',' -s \
71 echo "*---------*---------------*"
72 echo "| CHARSEL | " $1
73 echo "*---------*---------------*"
77 | sed -e '/^[ \t]*#/d' \
80 | column -t -N input,output --output-separator ' | ' --separator ','
83 echo "*-------------------------*"
84 echo "| previous shorcode:" $INPUT
85 echo "| previous output: " $OUTPUT
86 echo "*-------------------------*"
89 read -p "| input shortcode: " -N $LENGTH INPUT
91 # This can definately be simplifed, but it works fine
92 # Finds line number of shortcode
93 LINENUMBER=$(cut -f 1 -d ',' -s $CHARFILE \
97 # Outputs charachter selected above
98 OUTPUT=$(cut -f 2 -d ',' -s $CHARFILE \
102 # Check to see if the shortcode actually exists
103 if [[ $(cut -f 1 -d ',' -s $CHARFILE \
104 | grep -wnc $INPUT) == "0" ]]
109 # Copy output to clipboard
110 echo $OUTPUT | xclip -selection clipboard