Skip to content

Commit

Permalink
Merge pull request #62 from cgrinds/osx-get_running_shell
Browse files Browse the repository at this point in the history
Detect fish on OSX when login shell is bash
  • Loading branch information
jamesob committed Apr 3, 2016
2 parents 4cab6dd + 13bcf28 commit 719ac2a
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions desk
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ get_callables() {

get_running_shell() {
# Echo the name of the parent shell via procfs, if we have it available.
# Otherwise, try to use ps with bash's parent pid.
if [ -e /proc ]; then
# Get cmdline procfile of the process running this script.
local CMDLINE_FILE="/proc/$(grep PPid /proc/$$/status | cut -f2)/cmdline"
Expand All @@ -282,12 +283,17 @@ get_running_shell() {
# Strip out any verion that may be attached to the shell executable.
# Strip leading dash for login shells.
local CMDLINE_SHELL=$(sed -r -e 's/\x0.*//' -e 's/^-//' "$CMDLINE_FILE")

if [ ! -z "$CMDLINE_SHELL" ]; then
basename "$CMDLINE_SHELL"
exit
fi
fi
else
# Strip leading dash for login shells.
# If the parent process is a login shell, guess bash.
local CMDLINE_SHELL=$(ps -o pid,args -p $PPID | tail -1 | cut -d' ' -f2 \
| sed -e 's/login/bash/' -e 's/^-//')
fi

if [ ! -z "$CMDLINE_SHELL" ]; then
basename "$CMDLINE_SHELL"
exit
fi

# Fall back to $SHELL otherwise.
Expand Down

0 comments on commit 719ac2a

Please sign in to comment.