1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-10-16 19:50:09 +00:00

Compare commits

...

8 commits

Author SHA1 Message Date
Rustam
e13a3b4390
Merge 43079320a2 into 99e2c31484 2024-09-18 21:10:21 +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
Erik Teichmann
9bcafe1c27
feat(functions): add takezip (#12670) 2024-09-18 20:26:38 +02:00
Rustam Tagaev
43079320a2
#new-plugin follow Conventions 2020-06-01 20:17:41 +03:00
Rustam Tagaev
ee19e2b847
#new-plugin add a new plugin "vault-switch" 2020-06-01 20:03:41 +03:00
10 changed files with 135 additions and 17 deletions

View file

@ -57,6 +57,16 @@ function takeurl() {
cd "$thedir"
}
function takezip() {
local data thedir
data="$(mktemp)"
curl -L "$1" > "$data"
unzip "$data" -d "./"
thedir="$(unzip -l "$data" | awk 'NR==4 {print $4}' | sed 's/\/.*//')"
rm "$data"
cd "$thedir"
}
function takegit() {
git clone "$1"
cd "$(basename ${1%%.git})"
@ -65,6 +75,8 @@ function takegit() {
function take() {
if [[ $1 =~ ^(https?|ftp).*\.(tar\.(gz|bz2|xz)|tgz)$ ]]; then
takeurl "$1"
elif [[ $1 =~ ^(https?|ftp).*\.(zip)$ ]]; then
takezip "$1"
elif [[ $1 =~ ^([A-Za-z0-9]\+@|https?|git|ssh|ftps?|rsync).*\.git/?$ ]]; then
takegit "$1"
else

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() {

View file

@ -16,9 +16,10 @@ plugins=(... terraform)
## Aliases
| Alias | Command |
|--------|----------------------------|
|---------|----------------------------------|
| `tf` | `terraform` |
| `tfa` | `terraform apply` |
| `tfaa` | `terraform apply -auto-approve` |
| `tfc` | `terraform console` |
| `tfd` | `terraform destroy` |
| `tff` | `terraform fmt` |

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

@ -0,0 +1,29 @@
# Vault-switch plugin
## Description
This plugin can switch among nodes of Vault - HashiCorp
## Configuration
For using a plugin you should add VAULT_NODES to **~/.zshrc**
Variable **VAULT_NODES** must look as
```bash
VAULT_NODES="node1,https://vault1.example.com,secret_token1;node2,https://vault2.example.com,secret_token2"
```
If you want to skip verify checking of ssl then add true to end of the string.
```bash
VAULT_NODES="node1,https://vault1.example.com,secret_token1,true;node2,https://vault2.example.com,secret_token2"
```
Name of a node, address, token are separating comma. Other nodes separate semicolon.
After need to add the name of the plugin to **~/.zshrc** to variable **plugins=(vault-switch)**
**Example usage:**
![vault-switch](example.png)
State of restoring stored in **~/.vault-switch/credentials**

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

View file

@ -0,0 +1,57 @@
autoload -U add-zsh-hook
add-zsh-hook precmd _restore_cache
FILE_CREDENTIALS="${HOME}/.vault-switch/credentials"
_restore_cache(){
[ ! -d ${HOME}/.vault-switch ] && mkdir -p ${HOME}/.vault-switch
[ ! -f $FILE_CREDENTIALS ] && touch ${FILE_CREDENTIALS}
source ${FILE_CREDENTIALS}
}
_get-nodes(){
IFS=";" read -A NODES <<< ${VAULT_NODES}
}
_set-color(){
echo "\e[1;32m$1\e[0m"
}
_list-nodes(){
INDEX=1
for i in ${NODES[@]}
do
NODE=$(echo $i | cut -d "," -f 1)
[[ "${NODE}" == "${VAULT_SELECT_NODE}" ]] && ASTERISK="*"
echo "${INDEX}) ${NODE} $(_set-color ${ASTERISK})"
INDEX=$[$INDEX+1]
unset ASTERISK
done
}
_set-work-node(){
if [ $1 -gt ${#NODES[@]} ]
then
echo "Number of node not found"
else
VAULT_SELECT_NODE=$(echo ${NODES[$1]} | cut -d "," -f 1)
VAULT_ADDR=$(echo ${NODES[$1]} | cut -d "," -f 2)
VAULT_TOKEN=$(echo ${NODES[$1]} | cut -d "," -f 3)
VAULT_SKIP_VERIFY=$(echo ${NODES[$1]} | cut -d "," -f 4)
echo > ${FILE_CREDENTIALS}
echo "export VAULT_SELECT_NODE=${VAULT_SELECT_NODE}" >> ${FILE_CREDENTIALS}
echo "export VAULT_ADDR=${VAULT_ADDR}" >> ${FILE_CREDENTIALS}
echo "export VAULT_TOKEN=${VAULT_TOKEN}" >> ${FILE_CREDENTIALS}
[[ $VAULT_SKIP_VERIFY ]] && echo "export VAULT_SKIP_VERIFY=true" >> ${FILE_CREDENTIALS}
_list-nodes
fi
}
vault-switch() {
_get-nodes
[ ! $1 ] && _list-nodes
[ $1 ] && _set-work-node $1
}

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 "
}