Skip to content

Commit

Permalink
Added support for files whose paths have a space in the name
Browse files Browse the repository at this point in the history
  • Loading branch information
pdemro committed Sep 9, 2024
1 parent 27f543e commit b2c7165
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions config/commands/defaults.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -108,7 +108,7 @@ goto() {
echo "Error: <line> 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: <line> must be less than or equal to $max_line"
Expand Down

0 comments on commit b2c7165

Please sign in to comment.