Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: aws profile prompt #348

Merged
merged 4 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ jobs:

bump-version: # Bump when on master
needs: [test-container]
if: contains(github.ref, 'master')
if: contains(github.ref, 'master') && github.repository == 'pure-fish/pure'
uses: ./.github/workflows/bump-version.yml
secrets: inherit
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Fully **customizable** (colors, symbols and features):
* [Display _username_ and _hostname_ when in an `SSH` session 🛠][ssh-session] ;
* [Display command _duration_ when longer than `5` seconds 🛠][time-duration] ;
* [Display `Python` _virtualenv_ when activated 🏴🛠][python-virtualenv] ;
* [Display `AWS` profile when set 🏴🛠][aws-profile] ;
* [Display `VI` mode and custom symbol for non-insert mode 🏴🛠][vi-mode] ;
* [Display `kubernetes` context and namespace 🏴🛠][kubernetes] ;
* [Detect when running in a container (e.g. `docker`, `podman`, `LXC`/`LXD`) 🏴🛠][container-detection-docker]
Expand Down Expand Up @@ -124,6 +125,7 @@ Checkout our [Contribution Guide][contribution] to get familiar with our convent
[nix-os]: https://pure-fish.github.io/pure/#nix-os
[prompt-symbol]: https://pure-fish.github.io/pure/#prompt-symbol
[python-virtualenv]: https://pure-fish.github.io/pure/#python-virtualenv
[aws-profile]: https://pure-fish.github.io/pure/#aws-profile
[separate-error-symbol]: https://pure-fish.github.io/pure/#separate-error-symbol
[single-line-prompt]: https://pure-fish.github.io/pure/#single-line-prompt
[ssh-session]: https://pure-fish.github.io/pure/#ssh-session
Expand Down
5 changes: 5 additions & 0 deletions conf.d/pure.fish
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ _pure_set_default pure_enable_virtualenv true
_pure_set_default pure_symbol_virtualenv_prefix "" # 🐍
_pure_set_default pure_color_virtualenv pure_color_mute

# AWS profile name
_pure_set_default pure_enable_aws_profile true
_pure_set_default pure_symbol_aws_profile_prefix "" # ☁️
_pure_set_default pure_color_aws_profile pure_color_warning

# Print current working directory at the beginning of prompt
# true (default): current directory, git, user@hostname (ssh-only), command duration
# false: user@hostname (ssh-only), current directory, git, command duration
Expand Down
7 changes: 7 additions & 0 deletions docs/components/features-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@
| **`pure_enable_virtualenv`** | `true` | Show virtual env name (based on `VIRTUAL_ENV` or `CONDA_DEFAULT_ENV`). |
| **`pure_symbol_virtualenv_prefix`** | | Prefix when a Python virtual env is activated (default: [undefined][to-set]) |

### AWS Profile

| Option | Default | Description |
| :---------------------------------- | :------ | :--------------------------------------------------------------------------- |
| **`pure_enable_aws_profile`** | `true` | Show AWS profile name (based on `AWS_VAULT` or `AWS_PROFILE`). |
| **`pure_symbol_aws_profile_prefix`** | | Prefix when a AWS profile is activated (default: [undefined][to-set]) |

### Separate Error Symbol

| Option | Default | Description |
Expand Down
4 changes: 3 additions & 1 deletion docs/components/features-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Fully **customizable** (colors, symbols and features):
* [Display _username_ and _hostname_ when in an `SSH` session 🛠][ssh-session] ;
* [Display command _duration_ when longer than `5` seconds 🛠][time-duration] ;
* [Display `Python` _virtualenv_ when activated 🏴🛠][python-virtualenv] ;
* [Display `AWS` profile when set 🏴🛠][aws-profile] ;
* [Display `VI` mode and custom symbol for non-insert mode 🏴🛠][vi-mode] ;
* [Display `kubernetes` context and namespace 🏴🛠][kubernetes] ;
* [Detect when running in a container (e.g. `docker`, `podman`, `LXC`/`LXD`) 🏴🛠][container-detection-docker]
Expand All @@ -21,7 +22,7 @@ Fully **customizable** (colors, symbols and features):
* [Show number of running jobs 🏴][jobs] ;
* [Prefix when `root` 🏴🛠][working-as-root] ;
* [Display `git` branch name 🏴🛠][git] ;

* Display `*` when `git` repository is _dirty_ ;
* Display `≡` when `git` repository is _stashed_ ;
* Display `⇡` when branch is _ahead_ (commits to push) ;
Expand All @@ -45,6 +46,7 @@ Fully **customizable** (colors, symbols and features):
[nix-os]: #nix-os
[prompt-symbol]: #prompt-symbol
[python-virtualenv]: #python-virtualenv
[aws-profile]: #aws-profile
[separate-error-symbol]: #separate-error-symbol
[single-line-prompt]: #single-line-prompt
[ssh-session]: #ssh-session
Expand Down
2 changes: 2 additions & 0 deletions functions/_pure_prompt.fish
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ function _pure_prompt \
set --local jobs (_pure_prompt_jobs)
set --local nixdevshell (_pure_prompt_nixdevshell) # Nix build environment indicator
set --local virtualenv (_pure_prompt_virtualenv) # Python virtualenv name
set --local aws_profile (_pure_prompt_aws_profile) # AWS profile name
set --local vimode_indicator (_pure_prompt_vimode) # vi-mode indicator
set --local pure_symbol (_pure_prompt_symbol $exit_code)
set --local system_time (_pure_prompt_system_time)
Expand All @@ -23,6 +24,7 @@ function _pure_prompt \
$jobs \
$nixdevshell \
$virtualenv \
$aws_profile \
$vimode_indicator \
$pure_symbol \
)
Expand Down
19 changes: 19 additions & 0 deletions functions/_pure_prompt_aws_profile.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function _pure_prompt_aws_profile --description "Display AWS profile name"

if set --query pure_enable_aws_profile;
and test "$pure_enable_aws_profile" = true

set --local aws_profile ''
set --local aws_profile_color (_pure_set_color $pure_color_aws_profile)

if test -n "$AWS_VAULT"
set aws_profile "$AWS_VAULT"
else if test -n "$AWS_PROFILE" -o "$AWS_PROFILE" != default
set aws_profile "$AWS_PROFILE"
end

if test -n $aws_profile
echo "$pure_symbol_aws_profile_prefix$aws_profile_color$aws_profile"
end
end
end
18 changes: 18 additions & 0 deletions tests/_pure.test.fish
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,24 @@ before_all
echo $pure_color_virtualenv
) = pure_color_mute

@test "configure: pure_enable_aws_profile" (
set --erase pure_enable_aws_profile
source (status dirname)/../conf.d/pure.fish
echo $pure_enable_aws_profile
) = true

@test "configure: pure_symbol_aws_profile_prefix" (
set --erase pure_symbol_aws_profile_prefix
source (status dirname)/../conf.d/pure.fish
echo $pure_symbol_aws_profile_prefix
) = $EMPTY

@test "configure: pure_color_aws_profile" (
set --erase pure_color_aws_profile
source (status dirname)/../conf.d/pure.fish
echo $pure_color_aws_profile
) = pure_color_warning

@test "configure: pure_begin_prompt_with_current_directory" (
set --erase pure_begin_prompt_with_current_directory
source (status dirname)/../conf.d/pure.fish
Expand Down
1 change: 1 addition & 0 deletions tests/_pure_prompt.test.fish
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ source (status dirname)/../functions/_pure_prompt.fish
source (status dirname)/../functions/_pure_prompt_jobs.fish
source (status dirname)/../functions/_pure_prompt_nixdevshell.fish
source (status dirname)/../functions/_pure_prompt_virtualenv.fish
source (status dirname)/../functions/_pure_prompt_aws_profile.fish
source (status dirname)/../functions/_pure_prompt_vimode.fish
source (status dirname)/../functions/_pure_prompt_symbol.fish
source (status dirname)/../functions/_pure_get_prompt_symbol.fish
Expand Down
56 changes: 56 additions & 0 deletions tests/_pure_prompt_aws_profile.test.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
source (status dirname)/fixtures/constants.fish
source (status dirname)/../functions/_pure_set_default.fish
source (status dirname)/../functions/_pure_prompt_aws_profile.fish
@echo (_print_filename (status filename))

function before_each
_purge_configs
_disable_colors # we use mocks so cleaning them must happen before

set --erase AWS_PROFILE
set --erase AWS_VAULT
end

before_each
@test "_pure_prompt_aws_profile: ensure default behaviour has no error" (
source (status dirname)/../conf.d/pure.fish

_pure_prompt_aws_profile
) $status -eq $SUCCESS


before_each
@test "_pure_prompt_aws_profile: ensure default behaviour print nothing when no AWS variables" (
source (status dirname)/../conf.d/pure.fish

echo (_pure_prompt_aws_profile)
) = $EMPTY

before_each
@test "_pure_prompt_aws_profile: print AWS_VAULT when present" (
set --universal pure_enable_aws_profile true
set --universal pure_symbol_aws_profile_prefix "🅰"
set --global AWS_VAULT my-vault

_pure_prompt_aws_profile
) = '🅰my-vault'

before_each
@test "_pure_prompt_aws_profile: print AWS_PROFILE when present" (
set --universal pure_enable_aws_profile true
set --universal pure_symbol_aws_profile_prefix "🅰"
set --global AWS_PROFILE my-profile

_pure_prompt_aws_profile
) = '🅰my-profile'


before_each
@test "_pure_prompt_aws_profile: print only AWS_VAULT when vault and profile are present" (
set --universal pure_enable_aws_profile true
set --universal pure_symbol_aws_profile_prefix "🅰"
set --global AWS_VAULT my-vault
set --global AWS_PROFILE my-profile

_pure_prompt_aws_profile
) = '🅰my-vault'