Skip to content

Commit

Permalink
Fix paths with spaces not opening correctly in helix
Browse files Browse the repository at this point in the history
Fixes #3
  • Loading branch information
josephschmitt committed Feb 12, 2025
1 parent e5c63fc commit 929c10e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions bin/zide-edit
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,20 @@ while [[ $# -gt 0 ]]; do
done

paths=$@
path=${paths%% *}
# Ensure paths with special chars (like spaces) are properly escaped
escaped_paths=()
for path in "${paths[@]}"; do
escaped_paths+=("$(printf "%q" "$path")")
done
path=${escaped_paths[0]}

# Focus editor pane, must be the next pane after yazi
zellij action focus-next-pane

# If we're trying to open a single path and it's a directory, change the working dir to it in our
# editor. This ensures any other commands in our editor (such as :open, :mv, etc) have the correct
# cwd set.
if [ ! -f "${path}" ] && [ ${#paths[@]} -eq 1 ]; then
if [ ! -f "${path}" ] && [ ${#escaped_paths[@]} -eq 1 ]; then
cdCommand="$(getEditorCommand $ZIDE_ORIGINAL_EDITOR cd)"
zellij action write 27 # send <Escape> key to enter NORMAL mode
zellij action write-chars ":${cdCommand} ${path}"
Expand All @@ -78,8 +83,8 @@ if [ ! -f "${path}" ] && [ ${#paths[@]} -eq 1 ]; then
fi

# Open paths in the editor
if [[ -n "${paths}" ]]; then
if [[ -n "${escaped_paths}" ]]; then
zellij action write 27 # send <Escape> key to enter NORMAL mode
zellij action write-chars ":$(getEditorCommand $ZIDE_ORIGINAL_EDITOR ${command}) ${paths}"
zellij action write-chars ":$(getEditorCommand $ZIDE_ORIGINAL_EDITOR ${command}) ${escaped_paths}"
zellij action write 13 # send <Enter> key
fi

0 comments on commit 929c10e

Please sign in to comment.