From 1c3e8de039b144a4fa195c88c9d56a7010a25370 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Sat, 1 Sep 2018 16:15:25 +0200 Subject: [PATCH] add ability to define the default profile using an environment variable --- README.md | 13 ++++++++++--- dotdrop/dotdrop.py | 8 ++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3b6d5b7..1ff925d 100644 --- a/README.md +++ b/README.md @@ -200,6 +200,9 @@ For more options see `dotdrop.sh --help`. For easy deployment the default profile used by dotdrop reflects the hostname of the host on which it runs. +The default profile used can be changed by defining +the `DOTDROP_PROFILE` environment variable. + ## Install dotfiles Simply run @@ -207,8 +210,9 @@ Simply run $ dotdrop.sh install ``` -Use the `--profile` switch to specify a profile if not using -the host's hostname. +Use the `--profile` switch to specify a different profile than +the host's hostname or define it through the `DOTDROP_PROFILE` +environment variable. ## Compare dotfiles @@ -256,9 +260,12 @@ $ dotdrop.sh list ``` Dotdrop allows to choose which profile to use -with the *--profile* switch if you use something +with the `--profile` switch if you use something else than the default (the hostname). +The default profile can be changed by defining the +`DOTDROP_PROFILE` environment variable. + ## List dotfiles The following command lists the different dotfiles diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index 2ea010e..a5ff0ed 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -24,7 +24,10 @@ from dotdrop.utils import * CUR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) LOG = Logger() -HOSTNAME = socket.gethostname() +ENV_PROFILE = 'DOTDROP_PROFILE' +PROFILE = socket.gethostname() +if ENV_PROFILE in os.environ: + PROFILE = os.environ[ENV_PROFILE] TILD = '~' TRANS_SUFFIX = 'trans' @@ -64,7 +67,7 @@ Options: -v --version Show version. -h --help Show this screen. -""".format(BANNER, HOSTNAME) +""".format(BANNER, PROFILE) ########################################################### # entry point @@ -322,6 +325,7 @@ def main(): """entry point""" ret = True args = docopt(USAGE, version=VERSION) + try: conf = Cfg(os.path.expanduser(args['--cfg'])) except ValueError as e: