Skip to content

Commit

Permalink
fix [dorothy edit] with vscode by adding support for [edit --only-edi…
Browse files Browse the repository at this point in the history
…tor]

also rename beta command [get-nonflags] to [echo-nonflags] but it was not suitable, so still beta
  • Loading branch information
balupton committed Aug 23, 2023
1 parent bcc3d3d commit ed3584f
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 61 deletions.
52 changes: 52 additions & 0 deletions commands.beta/echo-nonflags
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash

function echo_nonflags() (
source "$DOROTHY/sources/bash.bash"

function help {
cat <<-EOF >/dev/stderr
ABOUT:
Output all arguments that aren't flags.
USAGE:
echo-nonflags <...input>
echo-lines <...input> | echo-nonflags
EXAMPLE:
echo-nonflags code -a --b c
code
c
# exit status: 0
echo-lines code -a --b c | echo-nonflags
code
c
# exit status: 0
QUIRKS:
[edit --dry | echo-nonflags] will output [code -w -n] because of the following:
echo 'code -a --b c' | echo-nonflags
code -a --b c
# exit status: 0
EOF
return 22 # EINVAL 22 Invalid argument
}

function on_input {
if [[ $1 != -* ]]; then
print_line "$1"
fi
}
source "$DOROTHY/sources/stdinargs.bash"
)

# fire if invoked standalone
if test "$0" = "${BASH_SOURCE[0]}"; then
echo_nonflags "$@"
fi
58 changes: 0 additions & 58 deletions commands.beta/get-nonflags

This file was deleted.

2 changes: 1 addition & 1 deletion commands/dorothy
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ function dorothy() (

echo-segment --h1='Edit Dorothy'
ensure_permissions_configured
if test "$(edit --dry)" == 'code'; then
if test "$(edit --dry --only-editor)" == 'code'; then
code -- "$DOROTHY/.vscode/workspace.code-workspace"
else
edit -- "$DOROTHY"
Expand Down
17 changes: 15 additions & 2 deletions commands/edit
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ function edit() (
--[no-]prompt
If enabled (the default), support editors that require additional arguments to edit the file.
--only-editor
If enabled, only output the editor command, and not any arguments.
Enforces --dry.
--sudo
If enabled, the editor will be opened in sudo mode.
Expand All @@ -38,7 +42,7 @@ function edit() (
}

# process
local item dry='no' prompt='yes' sudo='no' terminal='' gui='' args=()
local item dry='no' prompt='yes' only_editor='no' sudo='no' terminal='' gui='' args=()
while test "$#" -ne 0; do
item="$1"
shift
Expand All @@ -50,6 +54,9 @@ function edit() (
'--no-prompt'* | '--prompt'*)
prompt="$(get-flag-value prompt --missing="$prompt" -- "$item" | echo-affirmative)"
;;
'--no-only-editor'* | '--only-editor'*)
only_editor="$(get-flag-value only-editor --missing="$only_editor" -- "$item" | echo-affirmative)"
;;
'--no-sudo'* | '--sudo'*)
sudo="$(get-flag-value sudo --missing="$sudo" -- "$item" | echo-affirmative)"
;;
Expand Down Expand Up @@ -165,7 +172,13 @@ function edit() (
return 42 # ENOPROTOOPT 42 Protocol not available
fi

# generate command
# only output the editor command
if test "$only_editor" != 'no'; then
print_line "${editor[0]}"
return
fi

# generate the entire command
local cmd=()
if test "$sudo" = 'yes'; then
cmd+=(
Expand Down

0 comments on commit ed3584f

Please sign in to comment.