Reputation: 809
I wanted a command that would quickly copy the current tmux
window layout to the clipboard on Mac using zsh
. I came up with the following:
tmux list-windows | awk '{print $7}' | sed 's/\]$//' | pbcopy
When I run this from the command line it works perfectly with an output like the following:
d97b,135x32,0,0[135x16,0,0{87x16,0,0,0,47x16,88,0,1},135x15,0,17{87x15,0,17,2,47x15,88,17,3}]
However, I can't seem to run it as an alias. If I add the line:
alias layout="tmux list-windows | awk '{print $7}' | sed 's/\]$//' | pbcopy"
to my .zshrc
file when I run layout
the command does not work as expected. It instead outputs the full tmux list-windows
command with the word layout
replacing the session name:
0: layout* (4 panes) [135x32] [layout d97b,135x32,0,0[135x16,0,0{87x16,0,0,0,47x16,88,0,1},135x15,0,17{87x15,0,17,2,47x15,88,17,3}]] @0 (active)
What am I doing wrong?
Thanks.
Upvotes: 3
Views: 2977
Reputation: 531325
Don't use an alias; use a function:
layout () {
tmux list-windows | awk '{print $7}' | sed 's/\]$//' | pbcopy
}
Then you don't need to worry about quoting.
Upvotes: 6
Reputation: 8432
alex_i is correct, if you escape the $7
everything works.
alias layout="tmux list-windows | awk '{print \$7}' | sed 's/\]$//' | pbcopy"
Note the backslash before the $7.
Upvotes: 6
Reputation: 308
Is your '$7' interpreted during the .zshrc loading ? Couldn't it be the issue ?
Upvotes: 5