VERSION=2.0.7
-# Environment variables
-
# Define argument functions
function usage() {
echo "Usage: /usr/bin/charsel [OPTION]... [CHARFILE]...
A simple terminal character selector
+ -a include hidden shortcodes
+ -b disable color support
+ -c check charfile validity
+ -d show readme
-h show this message
- -l show installed charfiles
-L show installed charfiles without the message
- -d show readme
+ -l show installed charfiles
+ -n dont copy character to clipboard, avoids Xclip dependency
-v print version
- -c check charfile validity
- -a include hidden shortcodes
Exit status:
0 okay,
}
# Look for arguments
-if [ $# -eq 0 ]; then
- usage
- exit 3
-fi
-while getopts ":aLlchdv" arg
+while getopts ":abcdhlLnv" arg
do
case ${arg} in
+ a)
+ SHOWALL="true"
+ ;;
+ b)
+ COLOR="bw"
+ ;;
+ c)
+ validity
+ exit 0
+ ;;
+ d)
+ readme
+ exit 0
+ ;;
h)
usage
exit 0
list
exit 0
;;
- d)
- readme
- exit 0
- ;;
+ n)
+ COPY="no"
+ ;;
v)
echo "charsel" $VERSION
exit 0
;;
- c)
- validity
- exit 0
- ;;
- a)
- SHOWALL="true"
- ;;
?)
echo "Invalid option"
usage
done
shift $((OPTIND-1))
+if [ $# -eq 0 ]; then
+ echo "Please enter a valid charfile, or use charsel -h for help."
+ charsel -l
+ exit 3
+fi
# Redefine charfile and check file validity
CHARFILE="$CHARDIR/charfiles/$1"
existence
validity
# Dependency check
-if [[ -x xclip ]]
+if [[ ! $COPY == "no" ]]
then
- echo "Please install xclip."
+ if [[ -x xclip ]]
+ then
+ echo "Please install xclip."
+ exit 4
+ fi
+fi
+
+if [[ $(echo $LANG | grep UTF-8) -ne 0 ]]
+then
+ echo "Please enable unicode support"
exit 4
fi
bold=$(tput bold)
normal=$(tput sgr0)
+if [[ $COLOR == bw ]]
+then
+ magenta=$(tput setaf 7)
+else
+ magenta=$(tput setaf 5)
+fi
+
+white=$(tput setaf 7)
+
# Main program
while true
do
# Format output
echo "*---------*---------------*"
- echo "| ${bold}CHARSEL${normal} |" $1
+ echo "| ${bold}${magenta}CHARSEL${white}${normal} |" $1
echo "*---------*---------------*"
echo ""
fi
# Copy output to clipboard
- echo -n $OUTPUT | xclip -selection clipboard
+ if [[ ! $COPY == "no" ]]
+ then
+ echo -n $OUTPUT | xclip -selection clipboard
+ fi
clear
fi