Permalink
Browse files

Use `$PWD` instead of `$(pwd)`

This avoids spawning a sub-shell.
  • Loading branch information...
blueyed committed Sep 5, 2014
1 parent c8356e9 commit 17d4b66acd0da31dd4e90be3648f2f600bed9a02
Showing with 22 additions and 22 deletions.
  1. +3 −3 download-and-install
  2. +3 −3 lib/core/smartcd
  3. +2 −2 lib/core/smartcd_edit
  4. +3 −3 lib/core/smartcd_template
  5. +4 −4 lib/core/varstash
  6. +5 −5 t/smartcd.t
  7. +2 −2 t/varstash.t
View
@@ -144,13 +144,13 @@ if [[ -z $smartcd_previously_installed ]]; then
echo
echo "To get started, create a few scripts. Its easy! Try this:"
echo
echo " echo 'echo hello there from \$(pwd)' | smartcd edit enter"
echo " echo 'echo goodbye from \$(pwd)' | smartcd edit leave"
echo " echo 'echo hello there from \$PWD' | smartcd edit enter"
echo " echo 'echo goodbye from \$PWD' | smartcd edit leave"
echo
echo "Then simply leave the directory and come back. For a more practical"
echo "example, how about tweaking your PATH?"
echo
echo " echo \"autostash PATH=\$(pwd)/bin:\\\$PATH\" | smartcd edit enter"
echo " echo \"autostash PATH=\$PWD/bin:\\\$PATH\" | smartcd edit enter"
echo
echo "(side note: the quoting rules when editing in this fashion can be a bit"
echo "awkward, so feel free to run \`smartcd edit\` interactively too!"
View
@@ -184,7 +184,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"
_smartcd cd ..
_smartcd cd "$dir"
;;
@@ -449,7 +449,7 @@ function _smartcd() {
IFS="$_old_ifs"
if (( $rv != 0 )); then return $rv; fi
local whereto="$(pwd)"
local whereto="$PWD"
_smartcd_last_run_for="x$whereto"
# If zsh, turn autopushd off temporarily to avoid extra pushes
@@ -757,7 +757,7 @@ function _smartcd() {
}
function _smartcd_hook() {
local cwd="$(pwd)"
local cwd="$PWD"
# Skip this if we already ran smartcd for this directory
if [[ "x$cwd" != "$_smartcd_last_run_for" ]]; then
View
@@ -1,7 +1,7 @@
# wrapper function to preserve legacy usage
function smartcd_edit() {
local type="$1"
local dir="${2:-$(pwd)}"
local dir="${2:-$PWD}"
case $type in
bash_enter|bash_leave) local file=$type; type="${type#bash_}";;
@@ -169,7 +169,7 @@ function _smartcd_file_check() {
return
fi
else
dir="$(pwd)"
dir="$PWD"
fi
if [[ -n $system ]]; then
@@ -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"
smartcd_template edit "$name"
fi
else
@@ -137,7 +137,7 @@ EOF
local name="$1"
if [[ -n $name ]]; then
if [[ -f "$base/templates/$name" ]]; then
local current_dir=$(pwd)
local current_dir=$PWD
local mode= line=
while builtin read -r line; do
@@ -201,7 +201,7 @@ EOF
esac
done < "$base/templates/$name"
IFS="$_old_ifs"
_smartcd_exec "$contents" "$(pwd)"
_smartcd_exec "$contents" "$PWD"
else
echo "Template $name not found"
fi
View
@@ -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}"
local smartcd_dir="$(_smartcd_base)/scripts$working_dir"
local help_action="stashing a variable"
local help_dir=$smartcd_dir
@@ -211,7 +211,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}"
local smartcd_dir="$(_smartcd_base)/scripts$working_dir"
local help_action="autostashing a variable"
local help_dir=$smartcd_dir
@@ -241,7 +241,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}
local smartcd_dir="$(_smartcd_base)/scripts$working_dir"
local help_action="unstashing a variable"
local help_dir=$smartcd_dir
@@ -335,7 +335,7 @@ function autounstash() {
}
function _mangle_var() {
local mangle_var_where="${varstash_dir:-$(pwd)}"
local mangle_var_where="${varstash_dir:-$PWD}"
mangle_var_where=${mangle_var_where//[^A-Za-z0-9]/_}
local mangled_name=${1//[^A-Za-z0-9]/_}
echo "_tmp_${mangle_var_where}_${mangled_name}"
View
@@ -1,7 +1,7 @@
# Set up smartcd
mkdir -p tmphome
oldhome=$HOME
export HOME="$(pwd)/tmphome"
export HOME="$PWD/tmphome"
# Load testing library
source t/tap-functions
@@ -46,17 +46,17 @@ like "${output-_}" "this is a leaving test" "bash_leave executed successfully us
echo | smartcd edit enter "$dir"
echo | smartcd edit leave "$dir"
linkdest="$(pwd)/$dir/destination"
linkdest="$PWD/$dir/destination"
link="$dir/symlink"
mkdir -p "$linkdest"
ln -s destination "$link"
smartcd cd -P $link
is "_$(pwd)" "_$linkdest" "cd -P still works"
is "_$PWD" "_$linkdest" "cd -P still works"
smartcd cd ../..
spacedir="dir with a space"
mkdir -p "$spacedir"
smartcd_spacedir="$HOME/.smartcd/scripts$(pwd)/$spacedir"
smartcd_spacedir="$HOME/.smartcd/scripts$PWD/$spacedir"
mkdir -p "$smartcd_spacedir"
echo 'echo -n "1 "' > "$smartcd_spacedir/bash_enter"
echo 'echo 2' > "$smartcd_spacedir/bash_leave"
@@ -66,7 +66,7 @@ is "${output-_}" "1 2" "could enter and leave a directory with a space"
echo 'echo 4' > "$smartcd_spacedir/bash_leave"
spacedir2="dir with a space/subdir"
mkdir -p "$spacedir2"
smartcd_spacedir2="$HOME/.smartcd/scripts$(pwd)/$spacedir2"
smartcd_spacedir2="$HOME/.smartcd/scripts$PWD/$spacedir2"
mkdir -p "$smartcd_spacedir2"
echo 'echo -n "2 "' > "$smartcd_spacedir2/bash_enter"
echo 'echo -n "3 "' > "$smartcd_spacedir2/bash_leave"
View
@@ -109,12 +109,12 @@ is "_$(alast thing)" "_three four" "unstashed array"
oldhome=$HOME
stash HOME
mkdir -p tmphome
export HOME=$(pwd)/tmphome
export HOME=$PWD/tmphome
VARSTASH_AUTOCONFIG=1
oldshell=$SHELL
autostash SHELL
config_file="$HOME/.smartcd/scripts$(pwd)/bash_enter"
config_file="$HOME/.smartcd/scripts$PWD/bash_enter"
config_file_exists=$([[ -f $config_file ]] && echo "yes")
like "${config_file_exists-_}" "yes" "created smartcd file"

0 comments on commit 17d4b66

Please sign in to comment.