summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
76db80f)
This is a major update, in big part thanks to TJ- on freenode.net .
Instead of if statements, arguments are determined with bash's getopts.
Some other changes were made throughout to improve the quality of code.
>cp charfiles/* /usr/share/charsel/charfiles/
>mkdir /usr/share/doc/charsel
>cp README.md /usr/share/doc/charsel/
>cp charfiles/* /usr/share/charsel/charfiles/
>mkdir /usr/share/doc/charsel
>cp README.md /usr/share/doc/charsel/
->cp usage /usr/share/doc/charsel/
>cp ./charsel /usr/bin/
uninstall:
>cp ./charsel /usr/bin/
uninstall:
>cp charfiles/* /usr/share/charsel/charfiles/
>mkdir /usr/share/doc/charsel
>cp README.md /usr/share/doc/charsel/
>cp charfiles/* /usr/share/charsel/charfiles/
>mkdir /usr/share/doc/charsel
>cp README.md /usr/share/doc/charsel/
->cp usage /usr/share/doc/charsel/
* A terminal with UTF-8 encoding enabled
## Usage
* A terminal with UTF-8 encoding enabled
## Usage
-For usage, use `charsel --help`
+For usage, use `charsel -h`
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. To quit, use ^C
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
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. To quit, use ^C
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.
+Make a new file in the `~/.local/share/charsel/charfiles/` or `/usr/share/charsel/charfiles/` directories 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
########################################################################
########################################################################
-# Merge global and local charfiles
+# Define argument functions
+function usage() {
+ echo "Usage: /usr/bin/charsel [OPTION]... [CHARFILE]...
+A simple terminal character selector
+ -h show this message
+ -l show installed charfiles
+ -d show readme
+ --all include hidden shortcodes
+
+Exit status:
+ 0 okay,
+ 1 invalid charfile
+ 2 usage error/invalid option"
+}
+
CHARDIR=$HOME/.cache/charsel
CHARDIR=$HOME/.cache/charsel
+function list() {
+ echo "The following charfiles are installed:"
+ ls $CHARDIR/charfiles
+}
-if [[ ! -d $CHARDIR ]]
-then
- mkdir $CHARDIR/
-elif [[ ! "$(ls -A $CHARDIR)" ]]
-then
- cp -rf /usr/share/charsel/- $CHARDIR/
- cp -rf $HOME/.local/share/charsel/- $CHARDIR/
-fi
+function readme() {
+ cat /usr/share/doc/charsel/README.md
+}
+
+function invalid_charfile() {
+ echo "The selected charfile is missing or invalid"
+ list
+ exit 1
+}
+
+# Look for arguments
+while getopts ":lhd" arg
+do
+ case ${arg} in
+ h)
+ usage
+ exit 0
+ ;;
+ l)
+ list
+ exit 0
+ ;;
+ d)
+ readme
+ exit 0
+ ;;
+ ?)
+ echo "Invalid option"
+ usage
+ exit 2
+ ;;
+ :)
+ break
+ ;;
+ esac
+done
+shift $((OPTIND-1))
-# Check for xclip
-if [[ ! -f "$(which xclip)" ]]
+# Check if Xclip is installed
+if [[ -x xclip ]]
then
echo "Please install xclip."
exit 1
fi
then
echo "Please install xclip."
exit 1
fi
-# Check for user inputs
-if [[ $1 == "-l" \
- || $1 == "--list" ]]
+# Merge global and local charfiles
+if [[ -d $CHARDIR ]]
- echo "The following charfiles are installed:"
- ls $CHARDIR/charfiles
- exit 0
-elif [[ $1 == "-h" \
- || $1 == "--help" ]]
+ rm -rf $CHARDIR/*
+else
+ mkdir $CHARDIR
+fi
+
+LOCALCHARDIR=$HOME/.local/share/charsel/charfiles
+if [[ ! -d $LOCALCHARDIR ]]
- cat /usr/share/doc/charsel/usage
- exit 0
-elif [[ $1 == "-d" \
- || $1 == "--doc" ]]
+ mkdir -p $LOCALCHARDIR
+fi
+
+localdirfiles=($LOCALCHARDIR/*)
+if [[ ! -z "${#localdirfiles[*]}" ]]
- cat /usr/share/doc/charsel/README.md
- exit 0
+ cp -rf $LOCALCHARDIR/../* $CHARDIR
-# Define charfile path
-CHARFILE=$CHARDIR/charfiles/$1
+globaldirfiles=($/usr/share/charfiles/)
+if [[ ! -z "${#globaldirfiles[*]}" ]]
+then
+ cp -rf /usr/share/charsel/* $CHARDIR
+fi
-# Check if given charfile exists
+# Check if charfile exists
+CHARFILE="$CHARDIR/charfiles/$1"
if [[ ! -f $CHARFILE ]]
then
if [[ ! -f $CHARFILE ]]
then
- echo "Please enter a valid charfile."
- charsel -l
- exit 1
fi
# Define length of shortcode
fi
# Define length of shortcode
if [[ $2 == "--all" ]]
then
if [[ $2 == "--all" ]]
then
- cat $CHARFILE \
- | sed -e '/^[ \t]*#/d' \
- | tail -n +2 \
+ cat $CHARFILE | sed -e '/^[ \t]*#/d' | tail -n +2 \
| column -t -N input,output --output-separator ' | ' --separator ','
else
| column -t -N input,output --output-separator ' | ' --separator ','
else
- cat $CHARFILE \
- | sed -e '/^[ \t]*#/d' \
- | grep -A 100 - \
- | tail -n +2 \
+ cat $CHARFILE | sed -e '/^[ \t]*#/d' | grep -A 100 - | tail -n +2 \
| column -t -N input,output --output-separator ' | ' --separator ','
fi
| column -t -N input,output --output-separator ' | ' --separator ','
fi
# This can definately be simplifed, but it works fine
# Finds line number of shortcode
# 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)
+ 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)
+ # Outputs character selected above
+ OUTPUT=$(cut -f 2 -d ',' -s $CHARFILE | head -$LINENUMBER | tail +$LINENUMBER)
# Check to see if the shortcode actually exists
# Check to see if the shortcode actually exists
- if [[ $(cut -f 1 -d ',' -s $CHARFILE \
- | grep -wnc $INPUT) == "0" ]]
+ if [[ $(cut -f 1 -d ',' -s $CHARFILE | grep -wnc $INPUT) == "0" ]]
then
OUTPUT=""
fi
# Copy output to clipboard
then
OUTPUT=""
fi
# Copy output to clipboard
- echo $OUTPUT \
- | xclip -selection clipboard
+ echo $OUTPUT | xclip -selection clipboard
+++ /dev/null
-Usage: /usr/bin/charsel [OPTION]... [CHARFILE]...
-A simple terminal charachter selector
- -h, --help show this message
- -l, --list show installed charfiles
- -d, --doc show readme
- --all include hidden shortcodes
-
-Exit status:
- 0 if OK,
- 1 if error