Skip to content

Commit

Permalink
edit: default is now --no-wait, if you want --wait, provide --wait
Browse files Browse the repository at this point in the history
  • Loading branch information
balupton committed Nov 21, 2023
1 parent 73d8c53 commit 939cf32
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion commands.beta/edit-dns
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function edit_dns() (
print_line 'ProtonVPN enforces its own DNS'
elif command-exists dnscrypt-proxy; then
print_line 'Editing DNS configuration of dnscrypt-proxy'
edit -- "${HOMEBREW_PREFIX:-"/usr/local"}/etc/dnscrypt-proxy.toml"
edit --wait -- "${HOMEBREW_PREFIX:-"/usr/local"}/etc/dnscrypt-proxy.toml"
else
print_line 'DNS editing only supported for dnscrypt-proxy'
fi
Expand Down
2 changes: 1 addition & 1 deletion commands.beta/edit-hosts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function edit_hosts() (
# =====================================
# Action

edit --sudo -- /etc/hosts
edit --wait --sudo -- /etc/hosts
)

# fire if invoked standalone
Expand Down
8 changes: 4 additions & 4 deletions commands.beta/setup-server
Original file line number Diff line number Diff line change
Expand Up @@ -284,31 +284,31 @@ function setup_server() (

# samba
if service-helper --exists 'smbd'; then
edit --sudo '/etc/samba/smb.conf'
edit --wait --sudo -- '/etc/samba/smb.conf'
testparm --suppress-prompt >/dev/null # test samba config
fi

# plex
if test -n "$PLEX_HOME"; then
temp="$PLEX_HOME/Preferences.xml"
if test -f "$temp"; then
edit --sudo "$temp"
edit --wait --sudo -- "$temp"
fi
fi

# syncthing
if test -n "$SYNCTHING_HOME"; then
temp="$SYNCTHING_HOME/config.xml"
if test -f "$temp"; then
edit --sudo "$temp"
edit --wait --sudo -- "$temp"
fi
fi

# transmission
if test -n "$TRANSMISSION_HOME"; then
temp="$TRANSMISSION_HOME/settings.json"
if test -f "$temp"; then
edit --sudo "$temp"
edit --wait --sudo -- "$temp"
fi
fi
}
Expand Down
8 changes: 4 additions & 4 deletions commands/config-edit
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function config_edit() (
rg --fixed-strings --regexp="$1" "$option_file"
}
function default_file_editer {
edit -- "$option_file"
edit --wait -- "$option_file"
}
function default_file_applier {
local needle="${1:-"$2"}" replace="$2"
Expand All @@ -120,7 +120,7 @@ function config_edit() (
rg --fixed-strings --regexp="$1" --line-regexp '/etc/fuse.conf'
}
function default_fuse_editer {
edit --sudo -- '/etc/fuse.conf'
edit --wait --sudo -- '/etc/fuse.conf'
}
function default_fuse_applier {
local needle="${1:-"$2"}" replace="$2"
Expand All @@ -138,7 +138,7 @@ function config_edit() (
rg --fixed-strings --regexp="$1" '/etc/fstab'
}
function default_fstab_editer {
edit --sudo -- '/etc/fstab'
edit --wait --sudo -- '/etc/fstab'
if is-linux; then
sudo-helper -- systemctl daemon-reload
fi
Expand Down Expand Up @@ -174,7 +174,7 @@ function config_edit() (
rg --fixed-strings --regexp="$1" --line-regexp '/etc/hosts.conf'
}
function default_hosts_editer {
edit --sudo -- '/etc/hosts'
edit --wait --sudo -- '/etc/hosts'
}
function default_hosts_applier {
local needle="${1:-"$2"}" replace="$2"
Expand Down
2 changes: 1 addition & 1 deletion commands/dorothy
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ function dorothy() (
EOF
)"
if test ! -f "$HOME/.strongbox_keyring" && confirm --ppid=$$ -- "$question"; then
edit "$HOME/.strongbox_keyring"
edit --wait -- "$HOME/.strongbox_keyring"
fi
fi

Expand Down
12 changes: 10 additions & 2 deletions commands/edit
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ function edit_() (
--[no-]prompt
If enabled (the default), support editors that require additional arguments to edit the file.
--[no-]wait
If disabled (the default), edit the file but skip waiting for the editor to close the file.
--only-editor
If enabled, only output the editor command, and not any arguments.
Enforces --dry.
Expand All @@ -42,7 +45,7 @@ function edit_() (
}

# process
local item dry='no' prompt='yes' only_editor='no' sudo='no' terminal='' gui='' args=()
local item dry='no' prompt='yes' wait='no' only_editor='no' sudo='no' terminal='' gui='' args=()
while test "$#" -ne 0; do
item="$1"
shift
Expand All @@ -54,6 +57,9 @@ function edit_() (
'--no-prompt'* | '--prompt'*)
prompt="$(get-flag-value prompt --missing="$prompt" -- "$item" | echo-affirmative --stdin)"
;;
'--no-wait'* | '--wait'*)
wait="$(get-flag-value wait --missing="$wait" -- "$item" | echo-affirmative --stdin)"
;;
'--no-only-editor'* | '--only-editor'*)
only_editor="$(get-flag-value only-editor --missing="$only_editor" -- "$item" | echo-affirmative --stdin)"
;;
Expand Down Expand Up @@ -134,7 +140,9 @@ function edit_() (
# editors that require prompts
if [[ $command =~ code|atom|subl ]]; then
if test "$prompt" = 'yes'; then
array+=('-w') # wait
if test "$wait" = 'yes'; then
array+=('-w') # wait
fi
if [[ $command =~ code ]]; then
array+=('-n') # new window
fi
Expand Down
2 changes: 1 addition & 1 deletion commands/gpg-helper
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ function gpg_helper() (

# review
if confirm --negative --ppid=$$ -- "Review configuration?"; then
edit -- "$GNUPGHOME/" "$GNUPGHOME/"*".conf"
edit --wait -- "$GNUPGHOME/" "$GNUPGHOME/"*".conf"
fi

# restart
Expand Down
2 changes: 1 addition & 1 deletion commands/service-helper
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ function fs_own() (
function do_edit {
local plist
plist="$(do_find "$1")"
edit --sudo -- "$plist"
edit --wait --sudo -- "$plist"
}
function do_find {
local id="$1"
Expand Down
2 changes: 1 addition & 1 deletion commands/setup-git
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ function setup_git() (

# Editor
local editor
editor="$(edit --dry --prompt || :)"
editor="$(edit --dry || :)"
if test -n "$editor"; then
echo-style --h2="Git Configuration: Editor: $editor"
git config --global core.editor "$editor"
Expand Down

0 comments on commit 939cf32

Please sign in to comment.