TYPKRFT
TYPKRFT

Reputation: 326

Proper formatting of Command Substitution

I am trying to add the currently playing song if there is one to my ZSH prompt. I'm using a JXA command osascript -l JavaScript -e "Application('Music').currentTrack.name()". I am trying to assign it to a variable. and then echo that command.

precmd() {
  SONG=$( echo -e osascript -l JavaScript -e "Application('Music').currentTrack.name()" )
  LEFT=echo $SONG
  RIGHT="$(dracula_time_segment) $(battery_pct_prompt)"
  RIGHTWIDTH=$(($COLUMNS-${#LEFT}))
}

I've tried a number of variations eg: echo inside and outside the expression and various flags.

Upvotes: 0

Views: 81

Answers (1)

chepner
chepner

Reputation: 532268

You don't need echo at all, as demonstrated by your later command substitutions when setting RIGHT; command substitution just takes a command and executes it.

SONG=$(osascript -l JavaScript -e "Application('Music').currentTrack.name()")
LEFT="$SONG"

You could combine the previous two commands; SONG isn't needed.

LEFT=$(osascript ...)

Upvotes: 2

Related Questions