Skip to content

Commit

Permalink
[Fix] short pwd bash compatible (#229)
Browse files Browse the repository at this point in the history
* Fix to can be used with bash

* Fix SC2207

---------

Co-authored-by: Gabriel Trabanco Llano <gtrabanco@users.noreply.github.com>
  • Loading branch information
gtrabanco and gtrabanco authored Jul 17, 2024
1 parent 662d14d commit c4ad13b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
23 changes: 21 additions & 2 deletions scripts/core/short_pwd
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,27 @@
##? short_pwd
#? v1.0.0

join_str() {
local -r IFS=$1
shift
echo -n "${*}"
}

if [[ "$PWD" == "$HOME" ]]; then
echo "~"
else
echo ${${${:-/${(j:/:)${(M)${(s:/:)${(D)PWD:h}}#(|.)[^.]}}/${PWD:t}}//\/~/\~}/\/\//\/}
exit
fi

dirs=($(echo "${PWD//$HOME/"~"}" | tr '/' '\n'))
lastpos=$((${#dirs[@]} - 1))
process_dirs=()
for d in ${dirs[@]}; do
process_dirs+=("${d:0:2}")
done
process_dirs[$lastpos]="${dirs[$lastpos]}"

join_str '/' "${process_dirs[@]}"

# if [[ $SHELL == *"zsh" ]]; then
# echo ${${${:-/${(j:/:)${(M)${(s:/:)${(D)PWD:h}}#(|.)[^.]}}/${PWD:t}}//\/~/\~}/\/\//\/}
# fi
3 changes: 2 additions & 1 deletion shell/init-sloth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,9 @@ fi
if command -v gem > /dev/null 2> /dev/null || command -vp gem > /dev/null 2>&1; then
gem_bin="$(command -v gem || command -vp gem)"
gem_paths="$("$gem_bin" env gempath 2> /dev/null)"
#shellcheck disable=SC2207
path+=("${GEM_HOME}/bin")

#shellcheck disable=SC2207
[[ -n "$gem_paths" ]] && path+=($(echo "$gem_paths" | command -p tr ':' "\n" | command -p xargs -I _ echo _"/bin"))
fi

Expand Down

0 comments on commit c4ad13b

Please sign in to comment.