diff --git a/commands/dorothy b/commands/dorothy index 83b427017..29d35b831 100755 --- a/commands/dorothy +++ b/commands/dorothy @@ -114,6 +114,7 @@ function dorothy_() ( dorothy install [--clean] [--skip-install] + [--user=] Installs Dorothy interactively, with configuration for dotfile modifications. @@ -901,6 +902,8 @@ function dorothy_() ( } function ensure_user_configured { + local user="${1-}" + # sanity check if ! [[ $action =~ ^(install|update)$ ]]; then return 29 # ESPIPE 29 Illegal seek @@ -915,27 +918,46 @@ function dorothy_() ( fi # prepare - local question='' user='' where='' cli='' repo_git='' repo_url='' repo_name repo_description local_ip + local question='' where='' cli='' repo_git='' repo_url='' repo_name repo_description local_ip repo_name='dotfiles' repo_description="My user configuration for the Dorothy dotfile ecosystem: $dorothy_homepage" - # check where they want to store the user config - if is-interactive; then - where="$( - choose-option --required --label \ - --question="Where do you want to store your Dorothy user configuration?" \ - -- \ - github \ - 'Use a GitHub repository for your user configuration.' \ - gitlab \ - 'Use a GitLab repository for your user configuration.' \ - custom \ - 'Manually specify a repository URL for your user configration.' \ - 'local' \ - "Don't use a repository for your user configuration, just store it locally for now." - )" - else - where='local' + # handle github and gitlab prefixes, local value, custom urls, and default github usernames + if test -n "$user"; then + if [[ $user =~ ^(gh|github): ]]; then + where='github' + user="${user#*:}" + elif [[ $user =~ ^(gitlab|gl): ]]; then + where='github' + user="${user#*:}" + elif [[ $user =~ ^(local|none)$ ]]; then + where='local' + user='' + elif [[ $user == *:* ]]; then + where='custom' + else + user='github' + where='' + fi + fi + if test -z "$where"; then + if is-interactive; then + where="$( + choose-option --required --label \ + --question="Where do you want to store your Dorothy user configuration?" \ + -- \ + github \ + 'Use a GitHub repository for your user configuration.' \ + gitlab \ + 'Use a GitLab repository for your user configuration.' \ + custom \ + 'Manually specify a repository URL for your user configration.' \ + 'local' \ + "Don't use a repository for your user configuration, just store it locally for now." + )" + else + where='local' + fi fi if test "$where" = 'github' && __command_exists gh; then cli='gh' @@ -944,15 +966,17 @@ function dorothy_() ( fi if test "$where" = 'github' -o "$where" = 'gitlab'; then # prepare username default, and clear generic usernames - user="$(get-profile username || :)" - if test -n "$user" && is-generic -- "$user"; then - user='' + if test -z "$user"; then + user="$(get-profile username || :)" + if test -n "$user" && is-generic -- "$user"; then + user='' + fi + user="$( + ask --required --confirm \ + --question="Enter your $where username." \ + --default="$user" + )" fi - user="$( - ask --required --confirm \ - --question="Enter your $where username." \ - --default="$user" - )" # check what they want to call the repository repo_name="$( @@ -1360,7 +1384,7 @@ function dorothy_() ( function act_install { # process arguments - local item option_clean='no' option_skip_install='no' + local item option_clean='no' option_skip_install='no' option_user='' while test "$#" -ne 0; do item="$1" shift @@ -1368,6 +1392,7 @@ function dorothy_() ( '--clean' | '--clean=yes') option_clean='yes' ;; '--no-clean' | '--clean=no') option_clean='no' ;; '--skip-install') option_skip_install='yes' ;; + '--user='*) option_user="${item#*=}" ;; '--'*) help "An unrecognised flag was provided: $item" ;; *) help "An unrecognised argument was provided: $item" ;; esac @@ -1384,7 +1409,7 @@ function dorothy_() ( if test "$option_skip_install" = 'no'; then ensure_minimal_dependencies ensure_machine_configured - ensure_user_configured + ensure_user_configured "$option_user" fi ensure_shell_configured --clean="$option_clean" diff --git a/commands/ssh-helper b/commands/ssh-helper index 45b26a094..5449ffd89 100755 --- a/commands/ssh-helper +++ b/commands/ssh-helper @@ -187,7 +187,7 @@ function ssh_helper() ( --find='AddKeysToAgent .+' --replace='AddKeysToAgent yes' # trim the identity segment - sd -f mis '# .+?# [[:space:]]*' '' "$HOME/.ssh/config" + sd --flags mis '# .+?# [[:space:]]*' '' "$HOME/.ssh/config" # and add it back in if desired if test -n "$SSH_IDENTITY_AGENT"; then