From c8ac1d49cebfc371d0a2125049f5f9ed7bd767b3 Mon Sep 17 00:00:00 2001 From: frostming Date: Thu, 19 Sep 2019 14:34:15 +0800 Subject: [PATCH] Make install work under venvs --- legit/cli.py | 18 +++++++++--------- legit/utils.py | 8 ++++++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/legit/cli.py b/legit/cli.py index 181a39a..51463bf 100644 --- a/legit/cli.py +++ b/legit/cli.py @@ -18,7 +18,7 @@ from .settings import legit_settings from .utils import ( black, format_help, git_version, order_manually, output_aliases, - status_log, verbose_echo + status_log, verbose_echo, program_path ) CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help']) @@ -265,18 +265,18 @@ def do_install(ctx, verbose, fake): """Installs legit git aliases.""" click.echo('The following git aliases will be installed:\n') aliases = cli.list_commands(ctx) + if git_version() >= (2, 23, 0): + click.echo( + 'As git 2.23.0 introduces a new command "git switch", alias "switch"' + ' will be skipped.\nUse "legit switch" instead.' + ) + aliases.remove('switch') output_aliases(aliases) - git_v = git_version() + program = program_path() if click.confirm('\n{}Install aliases above?'.format('FAKE ' if fake else ''), default=fake): for alias in aliases: - if alias == 'switch' and git_v >= (2, 23, 0): - click.echo( - 'As git 2.23.0 introduces a new command "git switch", alias "switch"' - ' will be skipped.\nUse shortname "git sw" or "legit switch" instead.' - ) - continue - cmd = '!legit ' + alias + cmd = '!{} {}'.format(program, alias) system_command = 'git config --global --replace-all alias.{0} "{1}"'.format(alias, cmd) verbose_echo(system_command, verbose, fake) if not fake: diff --git a/legit/utils.py b/legit/utils.py index 5b82345..ac0b9a5 100644 --- a/legit/utils.py +++ b/legit/utils.py @@ -1,6 +1,8 @@ import click from clint.textui import colored, columns import crayons +import os +import sys from .settings import legit_settings @@ -124,3 +126,9 @@ def git_version(): g = Git() return g.version_info + + +def program_path(): + result = os.path.abspath(sys.argv[0]) + result = result.replace(os.sep, '/').replace(' ', '\\ ') + return result