]> git.armaanb.net Git - charsel.git/commitdiff
implement shellcheck suggestions
authorArmaan Bhojwani <3fb650a9-b47e-4604-a282-1dd91953b2ee@anonaddy.me>
Wed, 11 Nov 2020 18:38:32 +0000 (13:38 -0500)
committerArmaan Bhojwani <3fb650a9-b47e-4604-a282-1dd91953b2ee@anonaddy.me>
Wed, 11 Nov 2020 18:38:32 +0000 (13:38 -0500)
charsel
shell-completions

diff --git a/charsel b/charsel
index 7938a1c251847e106e55ddad6a63fb33b6b75242..800b964b55d63d71183b439088c9c2d051a705f5 100755 (executable)
--- a/charsel
+++ b/charsel
@@ -47,7 +47,7 @@ Exit status:
 function version_check(){
   NEW_VERSION=$(curl -s https://codeberg.org/armaan/charsel/raw/branch/master/charsel \
     | grep VERSION= | tail -c +9)
-  if [[ $VERSION != $NEW_VERSION ]]
+  if [[ $VERSION != "$NEW_VERSION" ]]
   then
     echo "an update is available"
   else
@@ -58,7 +58,7 @@ function version_check(){
 
 CHARDIR=$HOME/.cache/charsel
 function list() {
-  ls $CHARDIR/charfiles
+  ls "$CHARDIR"/charfiles
 }
 
 function readme() {
@@ -74,27 +74,27 @@ function missing_charfile() {
 # Merge global and local charfiles
 if [[ -d $CHARDIR ]]
 then
-  rm -rf $CHARDIR/*
+  rm -rf "${CHARDIR:?}"/*
 else
-  mkdir $CHARDIR
+  mkdir "$CHARDIR"
 fi
 
 LOCALCHARDIR=$HOME/.local/share/charsel/charfiles
 if [[ ! -d $LOCALCHARDIR ]]
 then
-  mkdir -p $LOCALCHARDIR
+  mkdir -p "$LOCALCHARDIR"
 fi
 
-localdirfiles=($LOCALCHARDIR/*)
-if [[ ! -z "${#localdirfiles[*]}" ]]
+localdirfiles="$LOCALCHARDIR"/*
+if [[ -n "${#localdirfiles[*]}" ]]
 then
-  cp -rf $LOCALCHARDIR/../* $CHARDIR
+  cp -rf "$LOCALCHARDIR"/../* "$CHARDIR"
 fi
 
 globaldirfiles=($/usr/share/charfiles/)
-if [[ ! -z "${#globaldirfiles[*]}" ]]
+if [[ -n "${#globaldirfiles[*]}" ]]
 then
-  cp -rf /usr/share/charsel/* $CHARDIR
+  cp -rf /usr/share/charsel/* "$CHARDIR"
 fi
 
 # Check if charfile exists
@@ -108,7 +108,7 @@ function existence() {
 
 # VERY basic syntax check
 function validity() {
-  if [[ $(grep , $CHARFILE && grep - $CHARFILE) ]]
+  if [[ $(grep , "$CHARFILE" && grep - "$CHARFILE") ]]
   then
     echo "valid charfile"
   else
@@ -189,15 +189,8 @@ then
   fi
 fi
 
-if [[ $(echo $LANG | grep UTF-8) -ne 0 ]]
-then
-  echo "Please enable unicode support"
-  exit 4
-fi
-
 # Define length of shortcode
-LENGTH=$(cat $CHARFILE \
-  | cut -f 1 -d ',' -s \
+LENGTH=$(cut "$CHARFILE" -f 1 -d ',' -s \
   | wc -L \
   | cut -b 1)
 
@@ -221,27 +214,27 @@ while true
 do
   # Format output
   echo "*---------*---------------*"
-  echo "| ${bold}${magenta}CHARSEL${white}${normal} |" $1
+  echo "| ${bold}${magenta}CHARSEL${white}${normal} |" "$1"
   echo "*---------*---------------*"
   echo ""
 
   if [[ $SHOWALL == true ]]
   then
-    cat $CHARFILE | sed -e '/^[ \t]*#/d' | tail -n +2 \
+    sed "$CHARFILE" -e '/^[ \t]*#/d' | tail -n +2 \
       | column -t -N "input","output" --output-separator ' | ' --separator ','
   else
-    cat $CHARFILE | sed -e '/^[ \t]*#/d' | grep -A 100 - | tail -n +2 \
+    sed "$CHARFILE" -e '/^[ \t]*#/d' | grep -A 100 - | tail -n +2 \
       | column -t -N "input","output" --output-separator ' | ' --separator ','
   fi
 
   echo ""
   echo "*-------------------------*"
-  echo "| previous shorcode:" $INPUT
-  echo "| previous output:  " $OUTPUT
+  echo "| previous shorcode:" "$INPUT"
+  echo "| previous output:  " "$OUTPUT"
   echo "*-------------------------*"
 
   # User input
-  read -p "| ${bold}input shortcode: ${normal}  " -N $LENGTH INPUT
+  read -p "| ${bold}input shortcode: ${normal}  " -N "$LENGTH" INPUT
 
   if [[ $INPUT == ";"* ]] # Semicolon exts
   then
@@ -253,13 +246,13 @@ do
     clear
   else
     # 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 character selected above
-    OUTPUT=$(cut -f 2 -d ',' -s $CHARFILE | head -$LINENUMBER | tail +$LINENUMBER)
+    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" ]]
+    if [[ $(cut -f 1 -d ',' -s "$CHARFILE" | grep -wnc "$INPUT") == "0" ]]
     then
       OUTPUT=""
     fi
@@ -267,7 +260,7 @@ do
     # Copy output to clipboard
     if [[ ! $COPY == "no" ]]
     then
-      echo -n $OUTPUT | xclip -selection clipboard
+      echo -n "$OUTPUT" | xclip -selection clipboard
     fi
 
     clear
index 172eb4ba5cfbee892a51247e0785aa7b6b4464d1..cb7c97c949b6f1df9049041aa5c559d05c6d20d3 100755 (executable)
@@ -1,3 +1,4 @@
+#!/usr/bin/env bash
 charfiles()
 {
   _script_commands=$(charsel -L)