Skip to content

Commit

Permalink
fixup! fish: Add 'machinectl shell' wrapper
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
  • Loading branch information
nathanchance committed Dec 24, 2024
1 parent 7d13763 commit ac8ffc5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
13 changes: 4 additions & 9 deletions fish/functions/mchsh.fish
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,8 @@ function mchsh -d "Wrapper around 'machinectl shell'"
set mchsh_args -l
end

# If the current working directory starts with '/home', it needs to be
# translated into a path that the container can use.
if string match -qr ^$HOME $PWD
set container_folder (string replace $HOME /run/host$HOME $PWD)
else
set container_folder $PWD
end

machinectl shell -q $user_host $SHELL -C "cd $container_folder" $mchsh_args
# Use fish's --init-commands to drop into the current working directory,
# instead of $HOME, which is not really useful if working on the host and
# wanting to drop into the guest to work.
machinectl shell -q $user_host $SHELL -C 'cd '(nspawn_adjust_path $PWD) $mchsh_args
end
11 changes: 11 additions & 0 deletions fish/functions/nspawn_adjust_path.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env fish
# SPDX-License-Identifier: MIT
# Copyright (C) 2024 Nathan Chancellor

function nspawn_adjust_path -d "Translate $HOME paths into /run/host$HOME paths"
if string match -qr ^$HOME $argv[1]
set prefix /run/host
end

printf '%s%s\n' $prefix $argv[1]
end

0 comments on commit ac8ffc5

Please sign in to comment.