Bump to version 0.4
[dotfiles-framework.git] / dotfiles.sh
index f499ee9b967e2b686ba55cc247dc82dd57c26266..5f0c5e5cb9cb8f4202fa42db8fcd4ff7926d65ca 100755 (executable)
@@ -3,7 +3,7 @@
 # Dotfiles management script.  For details, run
 #   $ dotfiles.sh --help
 #
-# Copyright (C) 2011-2012 W. Trevor King <wking@tremily.us>
+# Copyright (C) 2011-2015 W. Trevor King <wking@tremily.us>
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -18,7 +18,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-VERSION='0.2'
+VERSION='0.4'
 DOTFILES_DIR="${PWD}"
 TARGET=~
 CHECK_WGET_TYPE_AND_ENCODING='no'
@@ -26,17 +26,17 @@ CHECK_WGET_TYPE_AND_ENCODING='no'
 #####
 # External utilities
 
-DIFF=${DOTFILES_DIFF:-$(which diff)}
-GIT=${DOTFILES_GIT:-$(which git)}
-LN=${DOTFILES_LN:-$(which ln)}
-MV=${DOTFILES_MV:-$(which mv)}
-PATCH=${DOTFILES_PATCH:-$(which patch)}
-SED=${DOTFILES_SED:-$(which sed)}
-RM=${DOTFILES_RM:-$(which rm)}
-RSYNC=${DOTFILES_RSYNC:-$(which rsync)}
-TAR=${DOTFILES_TAR:-$(which tar)}
-TOUCH=${DOTFILES_TOUCH:-$(which touch)}
-WGET=${DOTFILES_WGET:-$(which wget)}
+DIFF=${DOTFILES_DIFF:-$(command -v diff)}
+GIT=${DOTFILES_GIT:-$(command -v git)}
+LN=${DOTFILES_LN:-$(command -v ln)}
+MV=${DOTFILES_MV:-$(command -v mv)}
+PATCH=${DOTFILES_PATCH:-$(command -v patch)}
+SED=${DOTFILES_SED:-$(command -v sed)}
+RM=${DOTFILES_RM:-$(command -v rm)}
+RSYNC=${DOTFILES_RSYNC:-$(command -v rsync)}
+TAR=${DOTFILES_TAR:-$(command -v tar)}
+TOUCH=${DOTFILES_TOUCH:-$(command -v touch)}
+WGET=${DOTFILES_WGET:-$(command -v wget)}
 
 #####
 # Compatibility checks
@@ -172,6 +172,8 @@ function get_repo_source()
                REPO_SOURCE_DATA['repo']="${REPO}"
                if [ -d "${REPO}/.git" ]; then
                        REPO_SOURCE_DATA['transfer']='git'
+                       REPO_SOURCE_DATA['url']=$(
+                               git --git-dir "${REPO}/.git/" config remote.origin.url)
                else
                        echo "ERROR: no source location found for ${REPO}" >&2
                        return 1
@@ -334,6 +336,49 @@ function clone()
        fi
 }
 
+###
+# list command
+
+COMMANDS+=('list')
+
+function list_help()
+{
+       echo 'List current dotfiles repositories.'
+       if [ "${1}" = '--one-line' ]; then return; fi
+
+       cat <<-EOF
+
+               usage: $0 ${COMMAND} [REPO]
+
+               List information for 'REPO' in a form simular to the 'clone'
+               command's arguments.  If 'REPO' is not give, all repositories will
+               be listed.  Examples:
+
+                 $0 list public
+                 public wget http://example.com/public-dotfiles.tar.gz
+                 $0 list
+                 public wget http://example.com/public-dotfiles.tar.gz
+                 private git ssh://example.com/~/private-dotfiles.git
+       EOF
+}
+
+function list()
+{
+       # multi-repo case handled in main() by run_on_all_repos()
+       REPO=$(nonempty_option 'list' 'REPO' "${1}") || return 1
+       maxargs 'list' 1 "${@}" || return 1
+       if [ "${BASH_MAJOR}" -ge 4 ]; then
+               get_repo_source "${REPO}" || return 1
+               TRANSFER=$(nonempty_option 'list' 'TRANSFER' "${REPO_SOURCE_DATA['transfer']}") || return 1
+               URL=$(nonempty_option 'list' 'URL' "${REPO_SOURCE_DATA['url']}") || return 1
+       else
+               echo "WARNING: Bash version < 4.0, cannot use assuming all repos use git transfer" >&2
+               TRANSFER='git'
+               URL=$(git --git-dir "${REPO}/.git/" config remote.origin.url)
+       fi
+       echo "${REPO} ${TRANSFER} ${URL}"
+}
+
 ###
 # fetch command