1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-10-16 11:40:46 +00:00

Compare commits

...

9 commits

Author SHA1 Message Date
donalshijan
77aaaad4dd
Merge 9cd054ddc0 into 1514145a09 2024-09-21 00:07:41 +05:30
Carlo Sala
1514145a09
feat(nvm): add _omz_nvm_load function 2024-09-19 11:44:51 +02:00
Carlo Sala
99e2c31484
feat(git): add git_previous_branch function
Closes #12538
2024-09-18 21:05:45 +02:00
Francesco Cataldo
e52598a5cc
feat(web-search): add reddit (#12664) 2024-09-18 20:43:52 +02:00
rakeshgm
d91944d47e
feat(gnzh): add virtualenv prompt (#12666) 2024-09-18 20:42:18 +02:00
Tushar Mohod
865291cb7a
feat (terraform): add apply -auto-approve alias (#12658)
Closes #12591
2024-09-18 20:40:54 +02:00
Donal Shijan
9cd054ddc0 refactor():Changed variable name according to guidelines 2023-10-15 21:59:32 +05:30
Donal Shijan
235b8cf4de refactor(): Removed an unnecessary comment 2023-10-15 21:51:10 +05:30
Donal Shijan
b49a1735d4 cdk cli tool completion suggestions plugin 2023-10-15 02:41:40 +05:30
10 changed files with 214 additions and 28 deletions

View file

@ -162,6 +162,18 @@ function git_current_branch() {
echo ${ref#refs/heads/}
}
# Outputs the name of the previously checked out branch
# Usage example: git pull origin $(git_current_branch)
# rev-parse --symbolic-full-name @{-1} only prints if it is a branch
function git_previous_branch() {
local ref
ref=$(__git_prompt_git rev-parse --quiet --symbolic-full-name @{-1} 2> /dev/null)
local ret=$?
if [[ $ret != 0 ]] || [[ -z $ref ]]; then
return # no git repo or non-branch previous ref
fi
echo ${ref#refs/heads/}
}
# Gets the number of commits ahead from remote
function git_commits_ahead() {

138
plugins/cdk/README.md Normal file
View file

@ -0,0 +1,138 @@
## Introduction
The `cdk plugin` uses the original aws cdk cli tool's implementation for getting completion suggestions using --get-yargs-completions option
## Usage
To use it, add `cdk` to the plugins list of your zshrc file:
```
plugins=(... cdk)
```
1. For completion suggestions, start typing the command upto the point from where onwards you would like to get suggestions, after you reach that point hit [SPACEBAR] and then [TAB].
Then completion suggestions will get listed below where you were typing the command at the same time the cursor will be left at where you last typed so that you can refer below and continue typing the command using the suggestions.
e.g
if you were to type :
cdk<space>[TAB]
You will see the following command suggestions with their respective descriptions:
acknowledge -- Acknowledge a notice so that it does not show up anymore
bootstrap -- Deploys the CDK toolkit stack into an AWS environment
context -- Manage cached context values
deploy -- Deploys the stack(s) named STACKS into your AWS account
destroy -- Destroy the stack(s) named STACKS
diff -- Compares the specified stack with the deployed stack or a local template file, and returns with status 1 if any difference is found
docs -- Opens the reference documentation in a browser
doctor -- Check your set-up for potential problems
import -- Import existing resource(s) into the given STACK
init -- Create a new, empty CDK project from a template.
list -- Lists all stacks in the app
metadata -- Returns all metadata associated with this stack
notices -- Returns a list of relevant notices
synthesize -- Synthesizes and prints the CloudFormation template for this stack
watch -- Shortcut for 'deploy --watch'
2. let's say you picked one command from the suggestion and further wanted some suggestions regarding options, then after typing the command from the suggestion you can further hit [SPACEBAR] and press [TAB] and it will first append '--' to the command you typed so far and then list out the possible options and it's descriptions below where you were typing all the while leaving the cursor right after where '--' got appended so that you can refer below and pick an option and type.
e.g
after typing:
cdk init<space>[TAB]
At this point your current command string which you were typing will get appended with a '--';
cdk init --
Further if you press [TAB] again with your command string looking like;
cdk init --[TAB]
You will see the following options suggestions with their respective descriptions:
--app -- REQUIRED WHEN RUNNING APP: command-line for executing your app or a cloud assembly directory (e.g. "node bin/my-app.js"). Can also be specified in cdk.json or ~/.cdk.json
--asset-metadata -- Include "aws:asset:*" CloudFormation metadata for resources that uses assets (enabled by default)
--build -- Command-line for a pre-synth build
--ca-bundle-path -- Path to CA certificate to use when validating HTTPS requests. Will read from AWS_CA_BUNDLE environment variable if not specified
--ci -- Force CI detection. If CI=true then logs will be sent to stdout instead of stderr
--context -- Add contextual string parameter (KEY=VALUE)
--debug -- Enable emission of additional debugging information, such as creation stack traces of tokens
--ec2creds -- Force trying to fetch EC2 instance credentials. Default: guess EC2 instance status
--generate-only -- If true, only generates project files, without executing additional operations such as setting up a git repo, installing dependencies or compiling the project
--help -- Show help
--ignore-errors -- Ignores synthesis errors, which will likely produce an invalid output
--json -- Use JSON output instead of YAML when templates are printed to STDOUT
--language -- The language to be used for the new project (default can be configured in ~/.cdk.json)
--list -- List the available templates
--lookups -- Perform context lookups (synthesis fails if this is disabled and context lookups need to be performed)
--no-color -- Removes colors and other style from console output
--notices -- Show relevant notices
--output -- Emits the synthesized cloud assembly into a directory (default: cdk.out)
--path-metadata -- Include "aws:cdk:path" CloudFormation metadata for each resource (enabled by default)
--plugin -- Name or path of a node package that extend the CDK features. Can be specified multiple times
--profile -- Use the indicated AWS profile as the default environment
--proxy -- Use the indicated proxy. Will read from HTTPS_PROXY environment variable if not specified
--role-arn -- ARN of Role to use when invoking CloudFormation
--staging -- Copy assets to the output directory (use --no-staging to disable the copy of assets which allows local debugging via the SAM CLI to reference the original source files)
--strict -- Do not construct stacks with warnings
--trace -- Print trace for stack warnings
--verbose -- Show debug logs (specify multiple times to increase verbosity)
--version -- Show version number
--version-reporting -- Include the "AWS::CDK::Metadata" resource in synthesized templates (enabled by default)
Note: You can avoid the appendment of '--' step by typing it yourself in your command string and then pressing [TAB] to save time.
3. The second usage of getting suggestions for options can be repeated in succession indefinitely.
e.g
after getting the options suggestions for cdk init command from the previous example, let's say you picked --app option:
cdk init --app
You can get further suggestions for more options by following the exact same steps for options suggestion as you did in previous example.
cdk init --app[TAB]
At this point your current command string which you were typing will get appended with a '--';
cdk init --app --
Further if you press [TAB] again with your command string looking like;
cdk init --app --[TAB]
You will see the further options suggestions with their respective descriptions:
--asset-metadata -- Include "aws:asset:*" CloudFormation metadata for resources that uses assets (enabled by default)
--build -- Command-line for a pre-synth build
--ca-bundle-path -- Path to CA certificate to use when validating HTTPS requests. Will read from AWS_CA_BUNDLE environment variable if not specified
--ci -- Force CI detection. If CI=true then logs will be sent to stdout instead of stderr
--context -- Add contextual string parameter (KEY=VALUE)
--debug -- Enable emission of additional debugging information, such as creation stack traces of tokens
--ec2creds -- Force trying to fetch EC2 instance credentials. Default: guess EC2 instance status
--generate-only -- If true, only generates project files, without executing additional operations such as setting up a git repo, installing dependencies or compiling the project
--help -- Show help
--ignore-errors -- Ignores synthesis errors, which will likely produce an invalid output
--json -- Use JSON output instead of YAML when templates are printed to STDOUT
--language -- The language to be used for the new project (default can be configured in ~/.cdk.json)
--list -- List the available templates
--lookups -- Perform context lookups (synthesis fails if this is disabled and context lookups need to be performed)
--no-color -- Removes colors and other style from console output
--notices -- Show relevant notices
--output -- Emits the synthesized cloud assembly into a directory (default: cdk.out)
--path-metadata -- Include "aws:cdk:path" CloudFormation metadata for each resource (enabled by default)
--plugin -- Name or path of a node package that extend the CDK features. Can be specified multiple times
--profile -- Use the indicated AWS profile as the default environment
--proxy -- Use the indicated proxy. Will read from HTTPS_PROXY environment variable if not specified
--role-arn -- ARN of Role to use when invoking CloudFormation
--staging -- Copy assets to the output directory (use --no-staging to disable the copy of assets which allows local debugging via the SAM CLI to reference the original source files)
--strict -- Do not construct stacks with warnings
--trace -- Print trace for stack warnings
--verbose -- Show debug logs (specify multiple times to increase verbosity)
--version -- Show version number
--version-reporting -- Include the "AWS::CDK::Metadata" resource in synthesized templates (enabled by default)
## Requirements
1. Disable any plugin or zsh configuration that interferes with tab completions,
2. Clear zcompdump Files: Sometimes, issues with completion are related to cached completion files.
You can try clearing your zcompdump files by running the command
rm -f ~/.zcompdump*
After deleting these files, you should restart your Zsh shell.
## Caveats
If aws-cdk npm package is installed on the system globally it will work really well, but if it is not installed the completion suggestions will still work but has a bit of a overhead since in such cases it will use npx under the hood to run the command and it can affect the performance depending on whether npx is able to find a local installation of the package in your current working directory or in the parent directories of your current working directory. If npx is able to find it installed locally, it will use it, but if it doesnt find any local installations it will first install the package temporarily in a local temporary directory on your system whose location can vary depending on the operating system and configuration but is typically somewhere under the user's home directory.
The package is installed for the duration of the command execution, and once the command is finished, the temporary installation is removed automatically. This means that you don't have to worry about manually cleaning up the temporary installation. npx is designed to handle this for you.
## References
1. Solution discussion - https://github.com/aws/aws-cdk/issues/5199
2. zsh-completions docs, can come in handy for futher development - https://github.com/zsh-users/zsh-completions/blob/master/zsh-completions-howto.org#writing-simple-completion-functions-using-_describe
## Contributer
https://github.com/donalshijan

View file

@ -0,0 +1,24 @@
# Check if the 'cdk' command is available in the system's PATH
if ! command -v cdk >/dev/null 2>&1; then
cdk() { npx -- cdk "$@" }
fi
###-begin-cdk-completions-###
_cdk_yargs_completions()
{
local completion_suggestions
local si=$IFS
IFS=$'
' completion_suggestions=($(COMP_CWORD="$((CURRENT-1))" COMP_LINE="$BUFFER" COMP_POINT="$CURSOR" cdk --get-yargs-completions "${words[@]}"))
IFS=$si
_describe 'values' completion_suggestions
}
compdef _cdk_yargs_completions cdk
###-end-cdk-completions-###
export ZSH_AUTOSUGGEST=true
autoload -U compinit
compinit

View file

@ -42,6 +42,8 @@ as you want:
zstyle ':omz:plugins:nvm' lazy-cmd eslint prettier typescript ...
```
There will be a function `_omz_nvm_load` available to load `nvm` without executing any other trigger command.
#### `.nvmrc` autoload
Note: _if used at the same time as `lazy`, `autoload` will start working only after nvm has been lazy-loaded_

View file

@ -20,7 +20,7 @@ if [[ -z "$NVM_DIR" ]] || [[ ! -f "$NVM_DIR/nvm.sh" ]]; then
return
fi
function _omz_load_nvm_completion {
function _omz_nvm_setup_completion {
local _nvm_completion
# Load nvm bash completion
for _nvm_completion in "$NVM_DIR/bash_completion" "$NVM_HOMEBREW/etc/bash_completion.d/nvm"; do
@ -33,12 +33,12 @@ function _omz_load_nvm_completion {
break
fi
done
unfunction _omz_load_nvm_completion
unfunction _omz_nvm_setup_completion
}
function _omz_setup_autoload {
function _omz_nvm_setup_autoload {
if ! zstyle -t ':omz:plugins:nvm' autoload; then
unfunction _omz_setup_autoload
unfunction _omz_nvm_setup_autoload
return
fi
@ -68,13 +68,13 @@ function _omz_setup_autoload {
add-zsh-hook chpwd load-nvmrc
load-nvmrc
unfunction _omz_setup_autoload
unfunction _omz_nvm_setup_autoload
}
if zstyle -t ':omz:plugins:nvm' lazy; then
# Call nvm when first using nvm, node, npm, pnpm, yarn, corepack or other commands in lazy-cmd
zstyle -a ':omz:plugins:nvm' lazy-cmd nvm_lazy_cmd
nvm_lazy_cmd=(nvm node npm npx pnpm pnpx yarn corepack $nvm_lazy_cmd) # default values
nvm_lazy_cmd=(_omz_nvm_load nvm node npm npx pnpm pnpx yarn corepack $nvm_lazy_cmd) # default values
eval "
function $nvm_lazy_cmd {
for func in $nvm_lazy_cmd; do
@ -84,14 +84,16 @@ if zstyle -t ':omz:plugins:nvm' lazy; then
done
# Load nvm if it exists in \$NVM_DIR
[[ -f \"\$NVM_DIR/nvm.sh\" ]] && source \"\$NVM_DIR/nvm.sh\"
_omz_load_nvm_completion
_omz_setup_autoload
\"\$0\" \"\$@\"
_omz_nvm_setup_completion
_omz_nvm_setup_autoload
if [[ \"\$0\" != _omz_nvm_load ]]; then
\"\$0\" \"\$@\"
fi
}
"
unset nvm_lazy_cmd
else
source "$NVM_DIR/nvm.sh"
_omz_load_nvm_completion
_omz_setup_autoload
_omz_nvm_setup_completion
_omz_nvm_setup_autoload
fi

View file

@ -15,22 +15,23 @@ plugins=(... terraform)
## Aliases
| Alias | Command |
|--------|----------------------------|
| `tf` | `terraform` |
| `tfa` | `terraform apply` |
| `tfc` | `terraform console` |
| `tfd` | `terraform destroy` |
| `tff` | `terraform fmt` |
| `tffr` | `terraform fmt -recursive` |
| `tfi` | `terraform init` |
| `tfiu` | `terraform init -upgrade` |
| `tfo` | `terraform output` |
| `tfp` | `terraform plan` |
| `tfv` | `terraform validate` |
| `tfs` | `terraform state` |
| `tft` | `terraform test` |
| `tfsh` | `terraform show` |
| Alias | Command |
|---------|----------------------------------|
| `tf` | `terraform` |
| `tfa` | `terraform apply` |
| `tfaa` | `terraform apply -auto-approve` |
| `tfc` | `terraform console` |
| `tfd` | `terraform destroy` |
| `tff` | `terraform fmt` |
| `tffr` | `terraform fmt -recursive` |
| `tfi` | `terraform init` |
| `tfiu` | `terraform init -upgrade` |
| `tfo` | `terraform output` |
| `tfp` | `terraform plan` |
| `tfv` | `terraform validate` |
| `tfs` | `terraform state` |
| `tft` | `terraform test` |
| `tfsh` | `terraform show` |
## Prompt function

View file

@ -17,6 +17,7 @@ function tf_version_prompt_info() {
alias tf='terraform'
alias tfa='terraform apply'
alias tfaa='terraform apply -auto-approve'
alias tfc='terraform console'
alias tfd='terraform destroy'
alias tff='terraform fmt'

View file

@ -51,6 +51,7 @@ Available search contexts are:
| `packagist` | `https://packagist.org/?query=` |
| `gopkg` | `https://pkg.go.dev/search?m=package&q=` |
| `chatgpt` | `https://chatgpt.com/?q=` |
| `reddit` | `https://www.reddit.com/search/?q=` |
Also there are aliases for bang-searching DuckDuckGo:

View file

@ -32,6 +32,7 @@ function web_search() {
packagist "https://packagist.org/?query="
gopkg "https://pkg.go.dev/search?m=package&q="
chatgpt "https://chatgpt.com/?q="
reddit "https://www.reddit.com/search/?q="
)
# check whether the search engine is supported
@ -85,6 +86,7 @@ alias npmpkg='web_search npmpkg'
alias packagist='web_search packagist'
alias gopkg='web_search gopkg'
alias chatgpt='web_search chatgpt'
alias reddit='web_search reddit'
#add your own !bang searches here
alias wiki='web_search duckduckgo \!w'

View file

@ -30,8 +30,9 @@ local return_code="%(?..%F{red}%? ↵%f)"
local user_host="${PR_USER}%F{cyan}@${PR_HOST}"
local current_dir="%B%F{blue}%~%f%b"
local git_branch='$(git_prompt_info)'
local venv_prompt='$(virtualenv_prompt_info)'
PROMPT="╭─${user_host} ${current_dir} \$(ruby_prompt_info) ${git_branch}
PROMPT="╭─${venv_prompt}${user_host} ${current_dir} \$(ruby_prompt_info) ${git_branch}
╰─$PR_PROMPT "
RPROMPT="${return_code}"
@ -39,5 +40,7 @@ ZSH_THEME_GIT_PROMPT_PREFIX="%F{yellow}"
ZSH_THEME_GIT_PROMPT_SUFFIX=" %f"
ZSH_THEME_RUBY_PROMPT_PREFIX="%F{red}"
ZSH_THEME_RUBY_PROMPT_SUFFIX="%f"
ZSH_THEME_VIRTUALENV_PREFIX="%F{red}("
ZSH_THEME_VIRTUALENV_SUFFIX=")%f "
}