Skip to content

Commit

Permalink
Create a TILDE_REPLACER that is sed-safe
Browse files Browse the repository at this point in the history
  • Loading branch information
27medkamal committed May 8, 2024
1 parent d4041f8 commit 315b88c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bin/t
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if [[ $RESULT == *":"* ]]; then
else
# RESULT is a path

DIR_FULL=$(echo "$RESULT" | sed -e "s|^~/|$HOME/|")
DIR_FULL=$(echo "$RESULT" | sed -e "$TILDE_REPLACER")
DIR_WITH_TILDE=$(echo "$RESULT" | sed -e "$HOME_REPLACER") # in case it came from a direct usage of `t <path>`

# Quit if directory does not exists
Expand All @@ -65,7 +65,7 @@ if [[ -n "$TMP_SESSION_NAME" ]]; then
fi

# Attach to session
# Escape tilde which if appears by itself, tmux will interpret as a marked target
# Escape tilde which if it appears by itself, tmux will interpret as a marked target
# https://github.com/tmux/tmux/blob/master/cmd-find.c#L1024C51-L1024C57
SESSION=$(echo "$SESSION" | sed 's/^~$/\\~/')
if [ -z "$TMUX" ]; then
Expand Down
2 changes: 2 additions & 0 deletions src/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ session_name() {
}

HOME_REPLACER="" # default to a noop
TILDE_REPLACER="" # default to a noop
echo "$HOME" | grep -E "^[a-zA-Z0-9\-_/.@]+$" &>/dev/null # chars safe to use in sed
HOME_SED_SAFE=$?
if [ $HOME_SED_SAFE -eq 0 ]; then # $HOME should be safe to use in sed
HOME_REPLACER="s|^$HOME|~|"
TILDE_REPLACER="s|^~|$HOME|"
fi

__fzfcmd() {
Expand Down

0 comments on commit 315b88c

Please sign in to comment.