diff --git a/contrib/completion/bash/devtools.in b/contrib/completion/bash/devtools.in index 78f0741..83264ce 100644 --- a/contrib/completion/bash/devtools.in +++ b/contrib/completion/bash/devtools.in @@ -325,6 +325,7 @@ _pkgctl_repo_switch_opts() { _pkgctl_repo_web_args=( + --print -h --help ) _pkgctl_repo_web_opts() { _filedir -d; } diff --git a/contrib/completion/zsh/_devtools.in b/contrib/completion/zsh/_devtools.in index 372f07b..b82ece4 100644 --- a/contrib/completion/zsh/_devtools.in +++ b/contrib/completion/zsh/_devtools.in @@ -134,6 +134,7 @@ _pkgctl_repo_create_args=( ) _pkgctl_repo_web_args=( + '--print[Print the url instead of opening it with xdg-open]' '(-h --help)'{-h,--help}'[Display usage]' '*:git_dir:_files -/' ) diff --git a/doc/man/pkgctl-repo-web.1.asciidoc b/doc/man/pkgctl-repo-web.1.asciidoc index 8769be7..ba7106a 100644 --- a/doc/man/pkgctl-repo-web.1.asciidoc +++ b/doc/man/pkgctl-repo-web.1.asciidoc @@ -18,6 +18,9 @@ no arguments, open the package cloned in the current working directory. Options ------- +*--print*:: + Print the url instead of opening it with xdg-open + *-h, --help*:: Show a help text diff --git a/src/lib/repo/web.sh b/src/lib/repo/web.sh index 45ea53b..ab3d8c7 100644 --- a/src/lib/repo/web.sh +++ b/src/lib/repo/web.sh @@ -23,6 +23,7 @@ pkgctl_repo_web_usage() { no arguments, open the package cloned in the current working directory. OPTIONS + --print Print the url instead of opening it with xdg-open -h, --help Show this help text EXAMPLES @@ -32,7 +33,8 @@ _EOF_ pkgctl_repo_web() { local pkgbases=() - local path giturl pkgbase + local path giturl pkgbase url + local mode=open # option checking while (( $# )); do @@ -41,6 +43,10 @@ pkgctl_repo_web() { pkgctl_repo_web_usage exit 0 ;; + --print) + mode=print + shift + ;; --) shift break @@ -56,7 +62,7 @@ pkgctl_repo_web() { done # Check if web mode has xdg-open - if ! command -v xdg-open &>/dev/null; then + if [[ ${mode} == open ]] && ! command -v xdg-open &>/dev/null; then die "The web command requires 'xdg-open'" fi @@ -78,7 +84,18 @@ pkgctl_repo_web() { fi for pkgbase in "${pkgbases[@]}"; do + pkgbase=$(basename "${pkgbase}") path=$(gitlab_project_name_to_path "${pkgbase}") - xdg-open "${GIT_PACKAGING_URL_HTTPS}/${path}" + url="${GIT_PACKAGING_URL_HTTPS}/${path}" + case ${mode} in + open) + xdg-open "${url}" + ;; + print) + printf "%s\n" "${url}" + ;; + *) + die "Unknown mode: ${mode}" + esac done }