From 929c10e01d1d277a441c2a1d08bfef46049b3455 Mon Sep 17 00:00:00 2001 From: Joe Schmitt Date: Tue, 11 Feb 2025 23:02:00 -0500 Subject: [PATCH] Fix paths with spaces not opening correctly in helix Fixes #3 --- bin/zide-edit | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bin/zide-edit b/bin/zide-edit index 7e913bb..33df204 100755 --- a/bin/zide-edit +++ b/bin/zide-edit @@ -55,7 +55,12 @@ 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 @@ -63,7 +68,7 @@ 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 key to enter NORMAL mode zellij action write-chars ":${cdCommand} ${path}" @@ -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 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 key fi