mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-10-16 19:50:09 +00:00
Compare commits
8 commits
74e86cd739
...
e13a3b4390
Author | SHA1 | Date | |
---|---|---|---|
|
e13a3b4390 | ||
|
99e2c31484 | ||
|
e52598a5cc | ||
|
d91944d47e | ||
|
865291cb7a | ||
|
9bcafe1c27 | ||
|
43079320a2 | ||
|
ee19e2b847 |
10 changed files with 135 additions and 17 deletions
|
@ -57,6 +57,16 @@ function takeurl() {
|
||||||
cd "$thedir"
|
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() {
|
function takegit() {
|
||||||
git clone "$1"
|
git clone "$1"
|
||||||
cd "$(basename ${1%%.git})"
|
cd "$(basename ${1%%.git})"
|
||||||
|
@ -65,6 +75,8 @@ function takegit() {
|
||||||
function take() {
|
function take() {
|
||||||
if [[ $1 =~ ^(https?|ftp).*\.(tar\.(gz|bz2|xz)|tgz)$ ]]; then
|
if [[ $1 =~ ^(https?|ftp).*\.(tar\.(gz|bz2|xz)|tgz)$ ]]; then
|
||||||
takeurl "$1"
|
takeurl "$1"
|
||||||
|
elif [[ $1 =~ ^(https?|ftp).*\.(zip)$ ]]; then
|
||||||
|
takezip "$1"
|
||||||
elif [[ $1 =~ ^([A-Za-z0-9]\+@|https?|git|ssh|ftps?|rsync).*\.git/?$ ]]; then
|
elif [[ $1 =~ ^([A-Za-z0-9]\+@|https?|git|ssh|ftps?|rsync).*\.git/?$ ]]; then
|
||||||
takegit "$1"
|
takegit "$1"
|
||||||
else
|
else
|
||||||
|
|
12
lib/git.zsh
12
lib/git.zsh
|
@ -162,6 +162,18 @@ function git_current_branch() {
|
||||||
echo ${ref#refs/heads/}
|
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
|
# Gets the number of commits ahead from remote
|
||||||
function git_commits_ahead() {
|
function git_commits_ahead() {
|
||||||
|
|
|
@ -16,9 +16,10 @@ plugins=(... terraform)
|
||||||
## Aliases
|
## Aliases
|
||||||
|
|
||||||
| Alias | Command |
|
| Alias | Command |
|
||||||
|--------|----------------------------|
|
|---------|----------------------------------|
|
||||||
| `tf` | `terraform` |
|
| `tf` | `terraform` |
|
||||||
| `tfa` | `terraform apply` |
|
| `tfa` | `terraform apply` |
|
||||||
|
| `tfaa` | `terraform apply -auto-approve` |
|
||||||
| `tfc` | `terraform console` |
|
| `tfc` | `terraform console` |
|
||||||
| `tfd` | `terraform destroy` |
|
| `tfd` | `terraform destroy` |
|
||||||
| `tff` | `terraform fmt` |
|
| `tff` | `terraform fmt` |
|
||||||
|
|
|
@ -17,6 +17,7 @@ function tf_version_prompt_info() {
|
||||||
|
|
||||||
alias tf='terraform'
|
alias tf='terraform'
|
||||||
alias tfa='terraform apply'
|
alias tfa='terraform apply'
|
||||||
|
alias tfaa='terraform apply -auto-approve'
|
||||||
alias tfc='terraform console'
|
alias tfc='terraform console'
|
||||||
alias tfd='terraform destroy'
|
alias tfd='terraform destroy'
|
||||||
alias tff='terraform fmt'
|
alias tff='terraform fmt'
|
||||||
|
|
29
plugins/vault-switch/README.md
Normal file
29
plugins/vault-switch/README.md
Normal 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**
|
BIN
plugins/vault-switch/example.png
Normal file
BIN
plugins/vault-switch/example.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.1 KiB |
57
plugins/vault-switch/vault-switch.plugin.zsh
Normal file
57
plugins/vault-switch/vault-switch.plugin.zsh
Normal 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
|
||||||
|
}
|
|
@ -51,6 +51,7 @@ Available search contexts are:
|
||||||
| `packagist` | `https://packagist.org/?query=` |
|
| `packagist` | `https://packagist.org/?query=` |
|
||||||
| `gopkg` | `https://pkg.go.dev/search?m=package&q=` |
|
| `gopkg` | `https://pkg.go.dev/search?m=package&q=` |
|
||||||
| `chatgpt` | `https://chatgpt.com/?q=` |
|
| `chatgpt` | `https://chatgpt.com/?q=` |
|
||||||
|
| `reddit` | `https://www.reddit.com/search/?q=` |
|
||||||
|
|
||||||
Also there are aliases for bang-searching DuckDuckGo:
|
Also there are aliases for bang-searching DuckDuckGo:
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ function web_search() {
|
||||||
packagist "https://packagist.org/?query="
|
packagist "https://packagist.org/?query="
|
||||||
gopkg "https://pkg.go.dev/search?m=package&q="
|
gopkg "https://pkg.go.dev/search?m=package&q="
|
||||||
chatgpt "https://chatgpt.com/?q="
|
chatgpt "https://chatgpt.com/?q="
|
||||||
|
reddit "https://www.reddit.com/search/?q="
|
||||||
)
|
)
|
||||||
|
|
||||||
# check whether the search engine is supported
|
# check whether the search engine is supported
|
||||||
|
@ -85,6 +86,7 @@ alias npmpkg='web_search npmpkg'
|
||||||
alias packagist='web_search packagist'
|
alias packagist='web_search packagist'
|
||||||
alias gopkg='web_search gopkg'
|
alias gopkg='web_search gopkg'
|
||||||
alias chatgpt='web_search chatgpt'
|
alias chatgpt='web_search chatgpt'
|
||||||
|
alias reddit='web_search reddit'
|
||||||
|
|
||||||
#add your own !bang searches here
|
#add your own !bang searches here
|
||||||
alias wiki='web_search duckduckgo \!w'
|
alias wiki='web_search duckduckgo \!w'
|
||||||
|
|
|
@ -30,8 +30,9 @@ local return_code="%(?..%F{red}%? ↵%f)"
|
||||||
local user_host="${PR_USER}%F{cyan}@${PR_HOST}"
|
local user_host="${PR_USER}%F{cyan}@${PR_HOST}"
|
||||||
local current_dir="%B%F{blue}%~%f%b"
|
local current_dir="%B%F{blue}%~%f%b"
|
||||||
local git_branch='$(git_prompt_info)'
|
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 "
|
╰─$PR_PROMPT "
|
||||||
RPROMPT="${return_code}"
|
RPROMPT="${return_code}"
|
||||||
|
|
||||||
|
@ -39,5 +40,7 @@ ZSH_THEME_GIT_PROMPT_PREFIX="%F{yellow}‹"
|
||||||
ZSH_THEME_GIT_PROMPT_SUFFIX="› %f"
|
ZSH_THEME_GIT_PROMPT_SUFFIX="› %f"
|
||||||
ZSH_THEME_RUBY_PROMPT_PREFIX="%F{red}‹"
|
ZSH_THEME_RUBY_PROMPT_PREFIX="%F{red}‹"
|
||||||
ZSH_THEME_RUBY_PROMPT_SUFFIX="›%f"
|
ZSH_THEME_RUBY_PROMPT_SUFFIX="›%f"
|
||||||
|
ZSH_THEME_VIRTUALENV_PREFIX="%F{red}("
|
||||||
|
ZSH_THEME_VIRTUALENV_SUFFIX=")%f "
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue