Zsh alias always sets $PWD to home

I want to alias a command that creates a new tmux session in the folder I'm currently in, and sets the folder name (hyphenated) as the session name. If the session already exists, tmux attaches to it:

alias tses="tmux new -As $(basename $PWD | tr . -)"

When I run the command in my shell like so: tmux new -As $(basename $PWD | tr . -) it works as expected. But when I run the alias tses, it always sets the name of my home folder as the session name.

Why is that and how can I fix it to work as expected?

Upvotes: 0

Views: 698

Answers (1)

So apparently, the double quotes cause zsh to evaluate the command (and thus $PWD) when .zshrc is loaded. Putting it in single quotes:

alias tses='tmux new -As $(basename $PWD | tr . -)'

solved it. See also: Get the `pwd` in an `alias`?.

Upvotes: 1

Related Questions