########################################################################
-VERSION=2.0.1
+VERSION=2.0.4
# 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
- -v print version
- -c check charfile validity
- --all include hidden shortcodes
+ -h show this message
+ -l show installed charfiles
+ -d show readme
+ -v print version
+ -c check charfile validity
+ -a include hidden shortcodes
Exit status:
- 0 okay,
- 1 charfile does not exist,
- 2 charfile syntax error,
- 3 usage error/invalid option,
- 4 other error"
+ 0 okay,
+ 1 charfile does not exist,
+ 2 charfile syntax error,
+ 3 usage error/invalid option,
+ 4 other error"
}
CHARDIR=$HOME/.cache/charsel
}
# Look for arguments
-while getopts ":lchdv" arg
+if [ $# -eq 0 ]; then
+ usage
+ exit 3
+fi
+while getopts ":alchdv" arg
do
case ${arg} in
h)
validity
exit 0
;;
+ a)
+ SHOWALL="true"
+ ;;
?)
echo "Invalid option"
usage
exit 3
;;
- :)
- break
- ;;
esac
done
shift $((OPTIND-1))
clear
+# Define text formatting
+bold=$(tput bold)
+normal=$(tput sgr0)
+
# Main program
while true
do
# Format output
echo "*---------*---------------*"
- echo "| CHARSEL |" $1
+ echo "| ${bold}CHARSEL${normal} |" $1
echo "*---------*---------------*"
echo ""
- if [[ $2 == "--all" ]]
+ if [[ $SHOWALL == true ]]
then
cat $CHARFILE | sed -e '/^[ \t]*#/d' | tail -n +2 \
- | column -t -N input,output --output-separator ' | ' --separator ','
+ | column -t -N "input","output" --output-separator ' | ' --separator ','
else
cat $CHARFILE | sed -e '/^[ \t]*#/d' | grep -A 100 - | tail -n +2 \
- | column -t -N input,output --output-separator ' | ' --separator ','
+ | column -t -N "input","output" --output-separator ' | ' --separator ','
fi
echo ""
echo "*-------------------------*"
# User input
- read -p "| input shortcode: " -N $LENGTH INPUT
+ read -p "| ${bold}input shortcode: ${normal} " -N $LENGTH INPUT
if [[ $INPUT == ";"* ]] # Semicolon exits
then