1
0
Fork 0
mirror of synced 2024-12-22 06:31:07 -05:00

Support specifying a command after yadm enter

This commit is contained in:
Tim Byrne 2019-12-08 14:39:03 -06:00
parent 96bce8dbac
commit 32baf81b56
No known key found for this signature in database
GPG key ID: 14DB4FC2465A4B12
3 changed files with 33 additions and 9 deletions

View file

@ -58,8 +58,9 @@ def test_enter(runner, yadm_y, paths, shell, success):
'csh',
'zsh',
])
@pytest.mark.parametrize('cmd', [False, True], ids=['no-cmd', 'cmd'])
@pytest.mark.usefixtures('ds1_copy')
def test_enter_shell_ops(runner, yadm_y, paths, shell, opts, path):
def test_enter_shell_ops(runner, yadm_y, paths, shell, opts, path, cmd):
"""Enter tests for specific shell options"""
# Create custom shell to detect options passed
@ -67,11 +68,24 @@ def test_enter_shell_ops(runner, yadm_y, paths, shell, opts, path):
custom_shell.write('#!/bin/sh\necho OPTS=$*\necho PROMPT=$PROMPT')
custom_shell.chmod(0o775)
test_cmd = ['test1', 'test2', 'test3']
enter_cmd = ['enter']
if cmd:
enter_cmd += test_cmd
env = os.environ.copy()
env['SHELL'] = custom_shell
run = runner(command=yadm_y('enter'), env=env)
run = runner(command=yadm_y(*enter_cmd), env=env)
assert run.success
assert run.err == ''
assert f'OPTS={opts}' in run.out
assert f'PROMPT=yadm shell ({paths.repo}) {path} >' in run.out
if cmd:
assert '-c ' + ' '.join(test_cmd) in run.out
assert 'Entering yadm repo' not in run.out
assert 'Leaving yadm repo' not in run.out
else:
assert 'Entering yadm repo' in run.out
assert 'Leaving yadm repo' in run.out

12
yadm
View file

@ -900,6 +900,7 @@ function encrypt() {
}
function enter() {
command="$*"
require_shell
require_repo
@ -913,12 +914,17 @@ function enter() {
shell_path="%~"
fi
echo "Entering yadm repo"
shell_cmd=()
if [ -n "$command" ]; then
shell_cmd=('-c' "$*")
fi
[ "${#shell_cmd[@]}" -eq 0 ] && echo "Entering yadm repo"
yadm_prompt="yadm shell ($YADM_REPO) $shell_path > "
PROMPT="$yadm_prompt" PS1="$yadm_prompt" "$SHELL" $shell_opts
PROMPT="$yadm_prompt" PS1="$yadm_prompt" "$SHELL" $shell_opts "${shell_cmd[@]}"
echo "Leaving yadm repo"
[ "${#shell_cmd[@]}" -eq 0 ] && echo "Leaving yadm repo"
}
function git_command() {

12
yadm.1
View file

@ -47,7 +47,7 @@ list
.BR yadm " encrypt
.BR yadm " enter
.BR yadm " enter [ command ]
.BR yadm " decrypt
.RB [ -l ]
@ -187,10 +187,14 @@ See the ENCRYPTION section for more details.
Run a sub-shell with all Git variables set. Exit the sub-shell the same way you
leave your normal shell (usually with the "exit" command). This sub-shell can
be used to easily interact with your yadm repository using "git" commands. This
could be useful if you are using a tool which uses Git directly.
could be useful if you are using a tool which uses Git directly, such as tig,
vim-fugitive, git-cola, etc.
For example, Emacs Tramp and Magit can manage files by using this
configuration:
Optionally, you can provide a command after "enter", and instead of invoking
your shell, that command will be run with all of the Git variables exposed to
the command's environment.
Emacs Tramp and Magit can manage files by using this configuration:
.RS
(add-to-list 'tramp-methods