# CHARSEL
-A very simple bash script to make copying frequently used special characters to your clipboard easy.
+A simple bash script to make copying frequently used special characters to your clipboard easy.
It uses a plain-text file known as a "charfile" to define shortcuts to special characters that are easy to access on the keyboard.
* A terminal with UTF-8 encoding enabled
## Usage
-To start the program, run `charsel <charfile>`
-This will start the program with the specified charfile. There are a few installed by default, to see them, use `charsel list`.
+To start the program, run `charsel <charfile>`, this will start the program with the specified charfile. There are a few installed by default, to see them, use `charsel list`.
-Once you have started the program, simply type the shortcut listed on the left side of the table to copy the character on the right side of the table to your clipboard. If the charfile you used has multi-character shortcut keys, then you must hit enter after using a single letter shortcut. If the only shortcuts are single-letter, however, you can simply type the shortcut without clicking enter.
+Once you have started the program, simply type the shortcut listed on the left side of the table to copy the character on the right side of the table to your clipboard. Shortcodes the same length as the longest one will automatically be entered.
-The default charfiles all have hidden shortcuts for capital letters that are not shown on the table. Simply type a capital version of the shortcut key to access the capital version of the special character.
+Some of the default charfiles have hidden shortcuts for capital letters that are not shown on the table. Simply type a capital version of the shortcut key to access the capital version of the special character.
## Creating a charfile
Make a new file in `~/.local/share/charsel/` or `/usr/share/charsel` with the name that you would like to use to call the charfile in the command.
-Fill it in, using the provided examples as a template. Hidden shortcuts go above the '---', lines can be commented out using a '#' at the start of the line
+Fill it in, using the provided examples as a template. Hidden shortcuts go above the '-', lines can be commented out using a '#' at the start of the line
## License
Charfile is GNU GPLv3 licensed, see COPYING for more information
#!/usr/bin/env bash
+# (C) Copyright Armaan Bhojwani, 2020
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
# Merge both global and local charfiles
+
CHARDIR=~/.cache/charsel
if [[ ! -d $CHARDIR ]]
# Define charfile path
CHARFILE=$CHARDIR/charfiles/$1
+# Check if given charfile exists
if [[ ! -f $CHARFILE ]]
then
- echo "Please enter a valid charfile. You can list installed charfiles with \`charsel list\`"
+ echo "Please enter a valid charfile."
+ charsel list
exit 1
fi
-# Define length of shortcut
+# Define length of shortcode
LENGTH=$(cat $CHARFILE \
| cut -f 1 -d ',' -s \
| wc -L \
| cut -b 1)
-# Clear screen
clear
# Main program
read -p "| input shortcode: " -N $LENGTH INPUT
# This can definately be simplifed, but it works fine
+ # Finds line number of shortcode
LINENUMBER=$(cut -f 1 -d ',' -s $CHARFILE \
| grep -wn $INPUT \
| cut -d : -f 1)
-
+
+ # Outputs charachter selected above
OUTPUT=$(cut -f 2 -d ',' -s $CHARFILE \
| head -$LINENUMBER \
| tail +$LINENUMBER)
-
+
+ # Check to see if the shortcode actually exists
if [[ $(cut -f 1 -d ',' -s $CHARFILE \
| grep -wnc $INPUT) == "0" ]]
then
# Copy output to clipboard
echo $OUTPUT | xclip -selection clipboard
- # Clear screen
clear
done