3 #######################################################################
5 # (C) Copyright Armaan Bhojwani, 2020
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <https://www.gnu.org/licenses/>.
20 ########################################################################
22 # Merge global and local charfiles
23 CHARDIR=$HOME/.cache/charsel
25 if [[ ! -d $CHARDIR ]]
28 elif [[ ! "$(ls -A $CHARDIR)" ]]
30 cp -rf /usr/share/charsel/- $CHARDIR/
31 cp -rf $HOME/.local/share/charsel/- $CHARDIR/
35 if [[ ! -f "$(which xclip)" ]]
37 echo "Please install xclip."
41 # Check for user inputs
45 echo "The following charfiles are installed:"
51 cat /usr/share/doc/charsel/usage
56 cat /usr/share/doc/charsel/README.md
60 # Define charfile path
61 CHARFILE=$CHARDIR/charfiles/$1
63 # Check if given charfile exists
64 if [[ ! -f $CHARFILE ]]
66 echo "Please enter a valid charfile."
71 # Define length of shortcode
72 LENGTH=$(cat $CHARFILE \
73 | cut -f 1 -d ',' -s \
83 echo "*---------*---------------*"
85 echo "*---------*---------------*"
88 if [[ $2 == "--all" ]]
91 | sed -e '/^[ \t]*#/d' \
93 | column -t -N input,output --output-separator ' | ' --separator ','
96 | sed -e '/^[ \t]*#/d' \
99 | column -t -N input,output --output-separator ' | ' --separator ','
103 echo "*-------------------------*"
104 echo "| previous shorcode:" $INPUT
105 echo "| previous output: " $OUTPUT
106 echo "*-------------------------*"
109 read -p "| input shortcode: " -N $LENGTH INPUT
111 # This can definately be simplifed, but it works fine
112 # Finds line number of shortcode
113 LINENUMBER=$(cut -f 1 -d ',' -s $CHARFILE \
117 # Outputs charachter selected above
118 OUTPUT=$(cut -f 2 -d ',' -s $CHARFILE \
119 | head -$LINENUMBER \
122 # Check to see if the shortcode actually exists
123 if [[ $(cut -f 1 -d ',' -s $CHARFILE \
124 | grep -wnc $INPUT) == "0" ]]
129 # Copy output to clipboard
131 | xclip -selection clipboard