Skip to content

Commit

Permalink
Allow user to pick directory with "-d dir"
Browse files Browse the repository at this point in the history
  • Loading branch information
kusalananda committed Mar 31, 2018
1 parent ee2449b commit df30cc4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
8 changes: 5 additions & 3 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Shell scripts
* shell: Creates a shell for testing things in.

Creates a "temporary interactive shell" with a temporary working
directory. The working directory is removed when the shell exits
(unless the -k flag is used). Useful for testing things in an
interactive environment other than your usual shell.
directory (unless the -d flag is used to specify an existing
directory) and clean environment. The working directory is removed
when the shell exits (unless the -k or -d flag was used). Useful
for testing things in an interactive environment other than your
usual shell.
5 changes: 0 additions & 5 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,3 @@ For "shell":

* Make it possible to pre-populate the temporary directory with the
contents of an existing directory.

* Allow for multiple concurrent "shell" sessions in the same
temporary directory, possibly by giving the user the ablity to
manually pick the working directory (which would not be deleted
when exiting the session).
21 changes: 15 additions & 6 deletions src/shell.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@
#
# Example invocations:
#
# $ shell # starts a new shell (uses $SHELL)
# $ shell bash # starts a new bash shell
# $ shell -k # starts a new shell (uses $SHELL), temporary directory
# # will not be deleted when exiting the session
# $ shell # Starts a new shell (uses $SHELL).
# $ shell bash # Starts a new bash shell.
# $ shell -k # Starts a new shell (uses $SHELL).
# # The temporary directory will not be deleted when
# # exiting the session.
# $ shell -d dir # Starts a new shell (uses $SHELL) with "dir"
# # as the working directory. The directory will not be
# # deleted when exiting the session.

_get_solaris_shells ()
{
Expand Down Expand Up @@ -96,8 +100,10 @@ if [ "$_is_tmp_shell" = 'Yes' ]; then
exit 1
fi

while getopts 'k' opt; do
while getopts 'd:k' opt; do
case "$opt" in
d) tmpcwd=$OPTARG
keep=1 ;;
k) keep=1 ;;
*) echo 'error in command line parsing' >&2
exit 1
Expand All @@ -116,7 +122,10 @@ if [ -z "$realshell" ] || [ ! -x "$realshell" ]; then
exit 1
fi

tmpcwd="$( mktemp -d -t "shell-$shell.XXXXXXXX" )"
if [ -z "$tmpcwd" ]; then
tmpcwd="$( mktemp -d -t "shell-$shell.XXXXXXXX" )"
fi

if [ "$keep" -eq 1 ]; then
trap 'printf "Leaving %s in place\n" "$tmpcwd" >&2' EXIT
else
Expand Down

0 comments on commit df30cc4

Please sign in to comment.