diff --git a/config/commands/defaults.sh b/config/commands/defaults.sh index b4e9f45b3..3c6a0d11a 100644 --- a/config/commands/defaults.sh +++ b/config/commands/defaults.sh @@ -1,12 +1,12 @@ _print() { - local total_lines=$(awk 'END {print NR}' $CURRENT_FILE) - echo "[File: $(realpath $CURRENT_FILE) ($total_lines lines total)]" + local total_lines=$(awk 'END {print NR}' "$CURRENT_FILE") + echo "[File: $(realpath "$CURRENT_FILE") ($total_lines lines total)]" lines_above=$(jq -n "$CURRENT_LINE - $WINDOW/2" | jq '[0, .] | max | floor') lines_below=$(jq -n "$total_lines - $CURRENT_LINE - $WINDOW/2" | jq '[0, .] | max | round') if [ $lines_above -gt 0 ]; then echo "($lines_above more lines above)" fi - cat $CURRENT_FILE | grep -n $ | head -n $(jq -n "[$CURRENT_LINE + $WINDOW/2, $WINDOW/2] | max | floor") | tail -n $(jq -n "$WINDOW") + cat "$CURRENT_FILE" | grep -n $ | head -n $(jq -n "[$CURRENT_LINE + $WINDOW/2, $WINDOW/2] | max | floor") | tail -n $(jq -n "$WINDOW") if [ $lines_below -gt 0 ]; then echo "($lines_below more lines below)" fi @@ -18,7 +18,7 @@ _constrain_line() { echo "No file open. Use the open command first." return fi - local max_line=$(awk 'END {print NR}' $CURRENT_FILE) + local max_line=$(awk 'END {print NR}' "$CURRENT_FILE") local half_window=$(jq -n "$WINDOW/2" | jq 'floor') export CURRENT_LINE=$(jq -n "[$CURRENT_LINE, $max_line - $half_window] | min") export CURRENT_LINE=$(jq -n "[$CURRENT_LINE, $half_window] | max") @@ -68,7 +68,7 @@ open() { fi if [ -f "$1" ]; then - export CURRENT_FILE=$(realpath $1) + export CURRENT_FILE=$(realpath "$1") export CURRENT_LINE=$line_number _constrain_line _print @@ -108,7 +108,7 @@ goto() { echo "Error: must be a number" return fi - local max_line=$(awk 'END {print NR}' $CURRENT_FILE) + local max_line=$(awk 'END {print NR}' "$CURRENT_FILE") if [ $1 -gt $max_line ] then echo "Error: must be less than or equal to $max_line"