From 0f6aa0e49c7e0baf6741242f5d85f31b37e93979 Mon Sep 17 00:00:00 2001 From: Armaan Bhojwani <3fb650a9-b47e-4604-a282-1dd91953b2ee@anonaddy.me> Date: Wed, 11 Nov 2020 13:38:32 -0500 Subject: [PATCH] implement shellcheck suggestions --- charsel | 51 ++++++++++++++++++++--------------------------- shell-completions | 1 + 2 files changed, 23 insertions(+), 29 deletions(-) diff --git a/charsel b/charsel index 7938a1c..800b964 100755 --- 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 diff --git a/shell-completions b/shell-completions index 172eb4b..cb7c97c 100755 --- a/shell-completions +++ b/shell-completions @@ -1,3 +1,4 @@ +#!/usr/bin/env bash charfiles() { _script_commands=$(charsel -L) -- 2.39.2