mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2025-12-12 15:34:50 +08:00
Compare commits
4 Commits
b4b4905fc5
...
51f5e5fbc5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
51f5e5fbc5 | ||
|
|
92aed2e936 | ||
|
|
43079320a2 | ||
|
|
ee19e2b847 |
@ -77,7 +77,15 @@ EOF
|
|||||||
(*.lzma) unlzma "$full_path" ;;
|
(*.lzma) unlzma "$full_path" ;;
|
||||||
(*.z) uncompress "$full_path" ;;
|
(*.z) uncompress "$full_path" ;;
|
||||||
(*.zip|*.war|*.jar|*.ear|*.sublime-package|*.ipa|*.ipsw|*.xpi|*.apk|*.aar|*.whl|*.vsix|*.crx|*.pk3|*.pk4) unzip "$full_path" ;;
|
(*.zip|*.war|*.jar|*.ear|*.sublime-package|*.ipa|*.ipsw|*.xpi|*.apk|*.aar|*.whl|*.vsix|*.crx|*.pk3|*.pk4) unzip "$full_path" ;;
|
||||||
(*.rar) unrar x -ad "$full_path" ;;
|
(*.rar)
|
||||||
|
if (( $+commands[unrar] )); then
|
||||||
|
unrar x -ad "$full_path"
|
||||||
|
elif (( $+commands[unar] )); then
|
||||||
|
unar -o . "$full_path"
|
||||||
|
else
|
||||||
|
echo "extract: cannot extract RAR files: install unrar or unar" >&2
|
||||||
|
success=1
|
||||||
|
fi ;;
|
||||||
(*.rpm)
|
(*.rpm)
|
||||||
rpm2cpio "$full_path" | cpio --quiet -id ;;
|
rpm2cpio "$full_path" | cpio --quiet -id ;;
|
||||||
(*.7z | *.7z.[0-9]* | *.pk7) 7za x "$full_path" ;;
|
(*.7z | *.7z.[0-9]* | *.pk7) 7za x "$full_path" ;;
|
||||||
|
|||||||
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:**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user