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 both 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
46 echo "The following charfiles are installed:"
49 elif [[ $1 == "help" \
54 cat /usr/share/doc/charsel/README.md
58 # Define charfile path
59 CHARFILE=$CHARDIR/charfiles/$1
61 # Check if given charfile exists
62 if [[ ! -f $CHARFILE ]]
64 echo "Please enter a valid charfile."
69 # Define length of shortcode
70 LENGTH=$(cat $CHARFILE \
71 | cut -f 1 -d ',' -s \
81 echo "*---------*---------------*"
83 echo "*---------*---------------*"
87 | sed -e '/^[ \t]*#/d' \
90 | column -t -N input,output --output-separator ' | ' --separator ','
93 echo "*-------------------------*"
94 echo "| previous shorcode:" $INPUT
95 echo "| previous output: " $OUTPUT
96 echo "*-------------------------*"
99 read -p "| input shortcode: " -N $LENGTH INPUT
101 # This can definately be simplifed, but it works fine
102 # Finds line number of shortcode
103 LINENUMBER=$(cut -f 1 -d ',' -s $CHARFILE \
107 # Outputs charachter selected above
108 OUTPUT=$(cut -f 2 -d ',' -s $CHARFILE \
109 | head -$LINENUMBER \
112 # Check to see if the shortcode actually exists
113 if [[ $(cut -f 1 -d ',' -s $CHARFILE \
114 | grep -wnc $INPUT) == "0" ]]
119 # Copy output to clipboard
121 | xclip -selection clipboard