Skip to content

Commit

Permalink
add confirmation prompts for url schemes (#302)
Browse files Browse the repository at this point in the history
* add confirmation prompts for url schemes

This commit adds a confirmation prompt before following urls with
with certain schemes.
Wether or not a scheme requires confirmation can be configured in the
new `[url-promps]` section.

* Use other instead of default

* Use other instead of default

Co-authored-by: makeworld <makeworld@protonmail.com>
  • Loading branch information
emily-is-my-username and makew0rld authored Apr 26, 2022
1 parent 32b2182 commit 00541a4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ func Init() error {
viper.SetDefault("keybindings.shift_numbers", "")
viper.SetDefault("keybindings.bind_url_handler_open", "Ctrl-U")
viper.SetDefault("url-handlers.other", "default")
viper.SetDefault("url-prompts.other", false)
viper.SetDefault("cache.max_size", 0)
viper.SetDefault("cache.max_pages", 20)
viper.SetDefault("cache.timeout", 1800)
Expand Down
12 changes: 12 additions & 0 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,18 @@ underline = true
# application on your computer for opening this kind of URI.
other = 'default'
[url-prompts]
# Specify whether a confirmation prompt should be shown before following URL schemes.
# The special key 'other' matches all schemes that don't match any other key.
#
# Example: prompt on every non-gemini URL
# other = true
# gemini = false
#
# Example: only prompt on HTTP(S)
# other = false
# http = true
# https = true
# [[mediatype-handlers]] section
# ---------------------------------
Expand Down
12 changes: 12 additions & 0 deletions default-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,18 @@ underline = true
# application on your computer for opening this kind of URI.
other = 'default'

[url-prompts]
# Specify whether a confirmation prompt should be shown before following URL schemes.
# The special key 'other' matches all schemes that don't match any other key.
#
# Example: prompt on every non-gemini URL
# other = true
# gemini = false
#
# Example: only prompt on HTTP(S)
# other = false
# http = true
# https = true

# [[mediatype-handlers]] section
# ---------------------------------
Expand Down
9 changes: 9 additions & 0 deletions display/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,15 @@ func handleURL(t *tab, u string, numRedirects int) (string, bool) {
return ret("", false)
}

// check if a prompt is needed to handle this url
prompt := viper.GetBool("url-prompts.other")
if viper.IsSet("url-prompts." + parsed.Scheme) {
prompt = viper.GetBool("url-prompts." + parsed.Scheme)
}
if prompt && !(YesNo("Follow URL?\n" + u)) {
return ret("", false)
}

proxy := strings.TrimSpace(viper.GetString("proxies." + parsed.Scheme))
usingProxy := false

Expand Down

0 comments on commit 00541a4

Please sign in to comment.