Skip to content

Commit

Permalink
Shell implementation of realpath
Browse files Browse the repository at this point in the history
as macOS doesn't ship with a realpath program.

Fixes issue from #281
  • Loading branch information
erikw committed Sep 23, 2022
1 parent 35ae2f4 commit 887ed21
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
18 changes: 17 additions & 1 deletion generate_rc.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
#!/usr/bin/env bash
# Generate default rc file.

export TMUX_POWERLINE_DIR_HOME="$(dirname $0)"
# macOS doesn't ship with realpath.
# Bash implementation from https://stackoverflow.com/a/18443300/265508
realpath() (
OURPWD=$PWD
cd "$(dirname "$1")"
LINK=$(readlink "$(basename "$1")")
while [ "$LINK" ]; do
cd "$(dirname "$LINK")"
LINK=$(readlink "$(basename "$1")")
done
REALPATH="$PWD/$(basename "$1")"
cd "$OURPWD"
echo "$REALPATH"
)

export TMUX_POWERLINE_DIR_HOME="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"

source "${TMUX_POWERLINE_DIR_HOME}/config/paths.sh"
source "${TMUX_POWERLINE_DIR_HOME}/config/defaults.sh"
source "${TMUX_POWERLINE_DIR_HOME}/config/shell.sh"
Expand Down
18 changes: 17 additions & 1 deletion mute_powerline.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
#!/usr/bin/env bash

export TMUX_POWERLINE_DIR_HOME="$(dirname $0)"
# macOS doesn't ship with realpath.
# Bash implementation from https://stackoverflow.com/a/18443300/265508
realpath() (
OURPWD=$PWD
cd "$(dirname "$1")"
LINK=$(readlink "$(basename "$1")")
while [ "$LINK" ]; do
cd "$(dirname "$LINK")"
LINK=$(readlink "$(basename "$1")")
done
REALPATH="$PWD/$(basename "$1")"
cd "$OURPWD"
echo "$REALPATH"
)

export TMUX_POWERLINE_DIR_HOME="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"

source "${TMUX_POWERLINE_DIR_HOME}/config/paths.sh"
source "${TMUX_POWERLINE_DIR_LIB}/muting.sh"
source "${TMUX_POWERLINE_DIR_LIB}/arg_processing.sh"
Expand Down
18 changes: 18 additions & 0 deletions powerline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

export TMUX_POWERLINE_DIR_HOME="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"

# macOS doesn't ship with realpath.
# Bash implementation from https://stackoverflow.com/a/18443300/265508
realpath() (
OURPWD=$PWD
cd "$(dirname "$1")"
LINK=$(readlink "$(basename "$1")")
while [ "$LINK" ]; do
cd "$(dirname "$LINK")"
LINK=$(readlink "$(basename "$1")")
done
REALPATH="$PWD/$(basename "$1")"
cd "$OURPWD"
echo "$REALPATH"
)

export TMUX_POWERLINE_DIR_HOME="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"


source "${TMUX_POWERLINE_DIR_HOME}/config/helpers.sh"
source "${TMUX_POWERLINE_DIR_HOME}/config/paths.sh"
source "${TMUX_POWERLINE_DIR_HOME}/config/shell.sh"
Expand Down

0 comments on commit 887ed21

Please sign in to comment.