Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions lib/core/smartcd
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ function smartcd() {
case $command in
-h|help|'') echo $usage;;
cd|pushd|popd) shift; _smartcd $command "$@"; return $?;;
reenter) local dir="$(pwd)"
reenter) local dir="$(pwd -P)"
_smartcd cd ..
_smartcd cd "$dir"
;;
Expand Down Expand Up @@ -411,7 +411,7 @@ function _smartcd() {
IFS="$_old_ifs"

if (( $rv != 0 )); then return $rv; fi
local whereto="$(pwd)"
local whereto="$(pwd -P)"
_smartcd_last_run_for="x$whereto"

# If zsh, turn autopushd off temporarily to avoid extra pushes
Expand Down Expand Up @@ -662,7 +662,7 @@ function _smartcd() {
}

function _smartcd_hook() {
local cwd="$(pwd)"
local cwd="$(pwd -P)"

# Skip this if we already ran smartcd for this directory
if [[ "x$cwd" != "$_smartcd_last_run_for" ]]; then
Expand Down Expand Up @@ -778,6 +778,20 @@ function _smartcd_file() {
echo "$this_file"
}

function _smartcd_bash_local_clobber() {
_smartcd_clobber=
if [[ -n $BASH_VERSION ]]; then
for opt in `echo $SHELLOPTS | sed -e 's/:/ /g'`; do
[[ "$opt" == "noclobber" ]] && _smartcd_clobber=
done
set +o noclobber
fi
}

function _smartcd_bash_restore_clobber() {
[[ -n "$BASH_VERSION" && -z "$_smartcd_clobber" ]] && set -o noclobber
}

# Autoload stubs
function _smartcd_file_check() {
_smartcd_load "smartcd_edit" && _smartcd_file_check "$@"
Expand Down
6 changes: 5 additions & 1 deletion lib/core/smartcd_config
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ function smartcd_config() {

echo

# Temporarily disable noclobber for zsh users
# Temporarily disable noclobber for bash, zsh users
_smartcd_bash_local_clobber
[[ -n $ZSH_VERSION ]] && setopt localoptions && setopt clobber

if [[ -f "$HOME/.smartcd_config" ]]; then
Expand All @@ -160,6 +161,9 @@ function smartcd_config() {
fi
fi

# Restore bash clobber option to previous value
_smartcd_bash_restore_clobber

if [[ -n $config_file_exists ]]; then

echo -n "Would you like to load your config file now? [Y/n] "
Expand Down
12 changes: 8 additions & 4 deletions lib/core/smartcd_edit
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function smartcd_edit() {
# Invoke the users editor (or vi) on the relevant file
local file="$1"
local dir="${2:-$(pwd)}"
local dir="${2:-$(pwd -P)}"

case $file in
bash_enter|bash_leave) local type=${file#bash_};;
Expand All @@ -22,7 +22,8 @@ function smartcd_edit() {
command mkdir -p "$smartcd_dir"
fi

# Temporarily disable noclobber for zsh users
# Temporarily disable noclobber for bash, zsh users
_smartcd_bash_local_clobber
[[ -n $ZSH_VERSION ]] && setopt localoptions && setopt clobber

# Edit the file if interactive, otherwise write standard input to it
Expand Down Expand Up @@ -91,6 +92,9 @@ EOF
# Delete any file that is left empty
command rm "$smartcd_dir/$file"
fi

# Restore bash clobber option to previous value
_smartcd_bash_restore_clobber
}

function smartcd_append() {
Expand All @@ -106,13 +110,13 @@ function _smartcd_file_check() {

if [[ -n $dir ]]; then
# canonicalize
dir=$(builtin cd $dir 2>/dev/null && command pwd)
dir=$(builtin cd $dir 2>/dev/null && command pwd -P)
if [[ -z $dir ]]; then
echo "$3 is not a valid directory"
return
fi
else
dir="$(pwd)"
dir="$(pwd -P)"
fi

local base=$(_smartcd_base)
Expand Down
4 changes: 2 additions & 2 deletions lib/core/smartcd_helper
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ function smartcd_helper() {
# and nothing has done the replacement yet
local params i
for i in "$@"; do
apush params "${i//__PATH__/${smartcd_working_dir:-$(command pwd)}}"
apush params "${i//__PATH__/${smartcd_working_dir:-$(command pwd -P)}}"
done
set -- "${params[@]}"
fi

if [[ -f "$HOME/.smartcd/helper/$type/script" ]]; then
_smartcd_exec_file "$HOME/.smartcd/helper/$type/script" "${smartcd_working_dir:-$(command pwd)}" "$@"
_smartcd_exec_file "$HOME/.smartcd/helper/$type/script" "${smartcd_working_dir:-$(command pwd -P)}" "$@"
else
echo "smartcd: helper $type not found"
fi
Expand Down
6 changes: 3 additions & 3 deletions lib/core/smartcd_template
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ EOF
if [[ -f "$base/templates/$name" ]]; then
echo "Template $name already exists, run \"smartcd template edit $name\" to modify it"
else
smartcd_template _init "$name" "$(pwd)"
smartcd_template _init "$name" "$(pwd -P)"
smartcd_template edit "$name"
fi
else
Expand Down Expand Up @@ -119,7 +119,7 @@ EOF
install|-i) local name="$1"; shift
if [[ -n $name ]]; then
if [[ -f "$base/templates/$name" ]]; then
local current_dir=$(pwd)
local current_dir=$(pwd -P)
local smartcd_dir="$base/scripts$current_dir"
command mkdir -p "$smartcd_dir"
local mode= line=
Expand Down Expand Up @@ -184,7 +184,7 @@ EOF
esac
done < "$base/templates/$name"
IFS="$_old_ifs"
_smartcd_exec "$contents" "$(pwd)"
_smartcd_exec "$contents" "$(pwd -P)"
else
echo "Template $name not found"
fi
Expand Down
8 changes: 4 additions & 4 deletions lib/core/varstash
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function stash() {
fi

if [[ -n $1 ]] && [[ -z $run_from_smartcd ]] && [[ -z $run_from_autostash ]]; then
local working_dir="${varstash_dir:-$(pwd)}"
local working_dir="${varstash_dir:-$(pwd -P)}"
local smartcd_dir="$(_smartcd_base)/scripts$working_dir"
local help_action="stashing a variable"
local help_dir=$smartcd_dir
Expand Down Expand Up @@ -209,7 +209,7 @@ function stash() {

function autostash() {
if [[ -n $1 ]] && [[ -z $run_from_smartcd ]]; then
local working_dir="${varstash_dir:-$(pwd)}"
local working_dir="${varstash_dir:-$(pwd -P)}"
local smartcd_dir="$(_smartcd_base)/scripts$working_dir"
local help_action="autostashing a variable"
local help_dir=$smartcd_dir
Expand Down Expand Up @@ -239,7 +239,7 @@ function autostash() {

function unstash() {
if [[ -n $1 ]] && [[ -z $run_from_smartcd ]] && [[ -z $run_from_autounstash ]]; then
local working_dir=${varstash_dir:-$(pwd)}
local working_dir=${varstash_dir:-$(pwd -P)}
local smartcd_dir="$(_smartcd_base)/scripts$working_dir"
local help_action="unstashing a variable"
local help_dir=$smartcd_dir
Expand Down Expand Up @@ -330,7 +330,7 @@ function autounstash() {
}

function _mangle_var() {
local mangle_var_where="${varstash_dir:-$(pwd)}"
local mangle_var_where="${varstash_dir:-$(pwd -P)}"
mangle_var_where=${mangle_var_where//[^A-Za-z0-9]/_}
echo "_tmp_${mangle_var_where}_$1"
}
Expand Down