How do I include a variable in the prompt that changes if the variable changes (in zsh) - zsh

I'm trying to include the AWS_PROFILE variable in my zsh prompt so that I know which profile I'm currently working in. The problem is that when the value changes the prompt never updates in the same window. Here's my PS1 value:
PS1="%{$fg[red]%}%n%{$reset_color%}#%{$fg[blue]%}%m-%B$AWS_PROFILE%b-%{$fg[yellow]%}%~ %{$reset_color%}%% "
The AWS_PROFILE value stays the same in that same window when I export it with a new value.
Any ideas?

You need to defer the parameter expansion to the time the prompt is evaluated. This means that you need to escape the $ in front of the parameters.
That is, instead of $fg, you need a \$fg.

Related

In tmux, how can I move the current window in the next/previous session without specifying its name or index?

I'm currently using tmux 3.1c; I'd like to bind two keys in order to move the current window in the next/previous session. I want that the window is moved regardless the current session's name/index. The basic idea is that:
if I press e.g. C-b + some <key1>, the current window is moved in the session following the current one, without giving any further input; the window should be moved in the last position of this next session;
if I press e.g. C-b + some <key2> the current window is moved in the session before the current one, without giving any further input; the window should be moved in the last position of this previous session;
On the man pages I found some tokens which act as aliases in order to refer to windows/panes, but no tokens for sessions. I found some interesting examples also here, but no one pointed me to the result I wanted to achieve.
My guess is that in my .tmux.conf I need to set something like
bind-key <key1> move-window -t <target_for_next_session>
bind-key <key2> move-window -t <target_for_previous_session>
(and maybe target the current window somehow too for -s option). I tried to play around with those targets but with no luck. My main guess is that I need to combine the session_id variable in the FORMATS section with the -t option from bind-key, with some +1/-1 increment.
Unfortunately answers for this question always refer to session names/indexes, which are something I don't want to specify.
Thanks in advance!

Applescript dictionary missing fields how to iterate over settings set

In my previous question I asked how to change an AppleScript current settings to have the ShowActiveProcessArgumentsInTitle for the terminal profile. Because you can apply that plist field from another settings set yet the keywords in AppleScript are missing. This is proved by setting the terminal to a different profile red sands with that option toggled off using the current setting of that tab.
tell application "Terminal"
set newTab to do script "bash /Users/jredfox/Desktop/hello.sh"
set current settings of newTab to settings set "Red Sands"
end tell
#!/bin/bash
echo hello
read -p "Press ENTER to continue..."
exit
I have current settings of xtab and from there I want to iterate over every field in there. How can I do this? The AppleScript dictionary I just proved is missing a field that can be applied from AppleScript but isn't in the dictionary from the script editor app. So how do I iterate every field from current settings which is a settings set object. There appears to be new fields which are not in the dictionary. It's not iterable so using a repeat list isn't an option.

In R, if I want to bring down the previous command without overwriting what I've already written, how can I do this?

I know that pressing the up arrow key brings down the previous command in R. In doing so, however, it overwrites anything that has already been typed on the command line. So for instance, if I want to define an object using a long command I've just executed, I have to press the up-arrow then either click or navigate via arrow keys all the way back to the beginning of the command to add in my object_name <- [command I've just brought down].
Is there anyway to bring down the previous command to wherever my cursor is, rather than having it overwrite the entire command line?
Thanks in advance for your help!

Set return value as environment variable

I would like to set the return value of an auth call (a token) as an environment variable so that other calls can make use of the value and I don't have to change that value manually.
Can Paw already do this easily?
If not, how would I lay out an extension to achieve this?
The best is that you set your OAuth dynamic value in your header field, then copy the value (select the text and hit Cmd + C):
Go to edit your environments and paste the dynamic value (Cmd + V) in a new variable:
Now go back to your header, and start to write the name of the environment variable you just created, it will offer you to use this variable:
You should be good to go now:
If later you need a change in your token, you can go back to the environments and edit it there, all at the same place.

Passing the current commandline to a zsh autocomplete function

I track my billable hours. Every item has a description and a number of tags for different clients, projects etc.
Recently I added zsh completion for these tags. This is what I have in my zsh autocompletion file now:
_arguments "*:tags:( $(cat timetrackingdata | extract_tags.py ) )"
The python script extract_tags.py extracts all tags in my timetrackingdata file and gives them back to zsh.
I'd like to able to limit the tags returned by the tags already on the command line
So if I've already put the tag client1 on the command line I want to pass this tag to extract_tags.py so that it can filter it's output and only return tags that occur on items that also have the tag client1.
I think what you are looking for is the $words variable. This is an array of all words specified on the command line that magically exists inside completion functions.
Where is that documented? There are some passing references in man zshcompsys that I would have missed were I not specifically looking for them. However, I found it more clearly highlighted on this website.

Resources