Unverified Commit 0232ac4b authored by Marc Cornellà's avatar Marc Cornellà Committed by GitHub
Browse files

Merge branch 'master' into master

parents afb02876 ebc700be
......@@ -3,7 +3,6 @@
# -----------
#
# This is one for the system administrator, operation and maintenance.
# Some of which come from http://justinlilly.com/dotfiles/zsh.html
#
# ------------------------------------------------------------------------------
# Authors
......@@ -13,14 +12,6 @@
#
# ------------------------------------------------------------------------------
function retval() {
if [[ -z $1 ]];then
echo '.'
else
echo $1
fi
}
function retlog() {
if [[ -z $1 ]];then
echo '/var/log/nginx/access.log'
......@@ -30,8 +21,8 @@ function retlog() {
}
alias ping='ping -c 5'
alias clr='clear;echo "Currently logged in on $(tty), as $USER in directory $PWD."'
alias path='echo -e ${PATH//:/\\n}'
alias clr='clear; echo Currently logged in on $TTY, as $USER in directory $PWD.'
alias path='print -l $path'
alias mkdir='mkdir -pv'
# get top process eating memory
alias psmem='ps -e -orss=,args= | sort -b -k1,1n'
......@@ -44,10 +35,10 @@ alias hist10='print -l ${(o)history%% *} | uniq -c | sort -nr | head -n 10'
# directory LS
dls () {
ls -l | grep "^d" | awk '{ print $9 }' | tr -d "/"
print -l *(/)
}
psgrep() {
ps aux | grep "$(retval $1)" | grep -v grep
ps aux | grep "${1:-.}" | grep -v grep
}
# Kills any process that matches a regexp passed to it
killit() {
......@@ -55,7 +46,7 @@ killit() {
}
# list contents of directories in a tree-like format
if [ -z "\${which tree}" ]; then
if ! (( $+commands[tree] )); then
tree () {
find $@ -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
}
......@@ -98,7 +89,7 @@ syn20() {
# Printing process according to the port number
port_pro() {
netstat -ntlp | grep "$(retval $1)" | awk '{print $7}' | cut -d/ -f1
netstat -ntlp | grep "${1:-.}" | awk '{print $7}' | cut -d/ -f1
}
# top10 of gain access to the ip address
......@@ -135,7 +126,7 @@ httpstatus() {
# Delete 0 byte file
d0() {
find "$(retval $1)" -type f -size 0 -exec rm -rf {} \;
find "${1:-.}" -type f -size 0 -exec rm -rf {} \;
}
# gather external ip address
......@@ -143,12 +134,12 @@ geteip() {
curl -s -S https://icanhazip.com
}
# determine local IP address
# determine local IP address(es)
getip() {
if (( ${+commands[ip]} )); then
ip addr | grep "inet " | grep -v '127.0.0.1' | awk '{print $2}'
ip addr | awk '/inet /{print $2}' | command grep -v 127.0.0.1
else
ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'
ifconfig | awk '/inet /{print $2}' | command grep -v 127.0.0.1
fi
}
......
# Systemd plugin
The systemd plugin provides many useful aliases for systemd.
To use it, add systemd to the plugins array of your zshrc file:
```
plugins=(... systemd)
```
## Aliases
| Alias | Command | Description |
|:-----------------------|:-----------------------------------|:-----------------------------------------------------------------|
| `sc-list-units` | `systemctl list-units` | List all units systemd has in memory |
| `sc-is-active` | `systemctl is-active` | Show whether a unit is active |
| `sc-status` | `systemctl status` | Show terse runtime status information about one or more units |
| `sc-show` | `systemctl show` | Show properties of units, jobs, or the manager itself |
| `sc-help` | `systemctl help` | Show man page of units |
| `sc-list-unit-files` | `systemctl list-unit-files` | List unit files installed on the system |
| `sc-is-enabled` | `systemctl is-enabled` | Checks whether any of the specified unit files are enabled |
| `sc-list-jobs` | `systemctl list-jobs` | List jobs that are in progress |
| `sc-show-environment` | `systemctl show-environment` | Dump the systemd manager environment block |
| `sc-cat` | `systemctl cat` | Show backing files of one or more units |
| `sc-list-timers` | `systemctl list-timers` | List timer units currently in memory |
| **Aliases with sudo** |
| `sc-start` | `sudo systemctl start` | Start Unit(s) |
| `sc-stop` | `sudo systemctl stop` | Stop Unit(s) |
| `sc-reload` | `sudo systemctl reload` | Reload Unit(s) |
| `sc-restart` | `sudo systemctl restart` | Restart Unit(s) |
| `sc-try-restart` | `sudo systemctl try-restart` | Restart Unit(s) |
| `sc-isolate` | `sudo systemctl isolate` | Start a unit and its dependencies and stop all others |
| `sc-kill` | `sudo systemctl kill` | Kill unit(s) |
| `sc-reset-failed` | `sudo systemctl reset-failed` | Reset the "failed" state of the specified units, |
| `sc-enable` | `sudo systemctl enable` | Enable unit(s) |
| `sc-disable` | `sudo systemctl disable` | Disable unit(s) |
| `sc-reenable` | `sudo systemctl reenable` | Reenable unit(s) |
| `sc-preset` | `sudo systemctl preset` | Reset the enable/disable status one or more unit files |
| `sc-mask` | `sudo systemctl mask` | Mask unit(s) |
| `sc-unmask` | `sudo systemctl unmask` | Unmask unit(s) |
| `sc-link` | `sudo systemctl link` | Link a unit file into the unit file search path |
| `sc-load` | `sudo systemctl load` | Load unit(s) |
| `sc-cancel` | `sudo systemctl cancel` | Cancel job(s) |
| `sc-set-environment` | `sudo systemctl set-environment` | Set one or more systemd manager environment variables |
| `sc-unset-environment` | `sudo systemctl unset-environment` | Unset one or more systemd manager environment variables |
| `sc-edit` | `sudo systemctl edit` | Edit a drop-in snippet or a whole replacement file with `--full` |
| `sc-enable-now` | `sudo systemctl enable --now` | Enable and start unit(s) |
| `sc-disable-now` | `sudo systemctl disable --now` | Disable and stop unit(s) |
| `sc-mask-now` | `sudo systemctl mask --now` | Mask and stop unit(s) |
### User aliases
You can use the above aliases as `--user` by using the prefix `scu` instead of `sc`.
For example: `scu-list-units` will be aliased to `systemctl --user list-units`.
......@@ -10,7 +10,13 @@ sudo_commands=(
for c in $user_commands; do; alias sc-$c="systemctl $c"; done
for c in $sudo_commands; do; alias sc-$c="sudo systemctl $c"; done
for c in $user_commands; do; alias scu-$c="systemctl --user $c"; done
for c in $sudo_commands; do; alias scu-$c="systemctl --user $c"; done
alias sc-enable-now="sc-enable --now"
alias sc-disable-now="sc-disable --now"
alias sc-mask-now="sc-mask --now"
alias scu-enable-now="scu-enable --now"
alias scu-disable-now="scu-disable --now"
alias scu-mask-now="scu-mask --now"
# taskwarrior
This plugin adds smart tab completion for [TaskWarrior](http://taskwarrior.org/).
This plugin adds smart tab completion for [TaskWarrior](https://taskwarrior.org/).
It uses the zsh tab completion script (`_task`) shipped with TaskWarrior for the
completion definitions.
......
......@@ -21,7 +21,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php
# https://www.opensource.org/licenses/mit-license.php
#
typeset -g _task_cmds _task_projects _task_tags _task_config _task_modifiers
_task_projects=($(task _projects))
......
## atom
## Terraform oh-my-zsh plugin
Plugin for Terraform, a tool from Hashicorp for managing infrastructure safely and efficiently.
Current as of Terraform v0.11.7
### Requirements
* [Terraform](https://terraform.io/)
......@@ -13,7 +15,7 @@ Plugin for Terraform, a tool from Hashicorp for managing infrastructure safely a
### Expanding ZSH prompt with current Terraform workspace name
If you want to get current Terraform workspace name in your ZSH prompt open
your .zsh-theme file and in a choosen place insert:
your .zsh-theme file and in a chosen place insert:
```
$FG[045]\
......
......@@ -3,91 +3,151 @@
local -a _terraform_cmds
_terraform_cmds=(
'apply:Builds or changes infrastructure'
'console:Interactive console for Terraform interpolations'
'destroy:Destroy Terraform-managed infrastructure'
'fmt:Rewrites config files to canonical format'
'get:Download and install modules for the configuration'
'graph:Create a visual graph of Terraform resources'
'init:Initializes Terraform configuration from a module'
'import:Import existing infrastructure into Terraform'
'init:Initialize a Terraform working directory'
'output:Read an output from a state file'
'plan:Generate and show an execution plan'
'pull:Refreshes the local state copy from the remote server'
'push:Uploads the local state to the remote server'
'providers:Prints a tree of the providers used in the configuration'
'push:Upload this Terraform module to Atlas to run'
'refresh:Update local state file against real resources'
'remote:Configures remote state management'
'show:Inspect Terraform state or plan'
'taint:Manually forcing a destroy and recreate on the next plan/apply'
'taint:Manually mark a resource for recreation'
'untaint:Manually unmark a resource as tainted'
'validate:Validates the Terraform files'
'version:Prints the Terraform version'
'workspace:Workspace management'
)
__apply() {
_arguments \
'-auto-approve[Skip interactive approval of plan before applying.]' \
'-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]' \
'-auto-approve[Skip interactive approval of plan before applying.]' \
'-lock=[(true) Lock the state file when locking is supported.]' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-input=[(true) Ask for input for variables if not directly set.]' \
'-no-color[If specified, output will not contain any color.]' \
'-no-color[If specified, output wil be colorless.]' \
'-parallelism=[(10) Limit the number of parallel resource operations.]' \
'-refresh=[(true) Update state prior to checking for differences. This has no effect if a plan file is given to apply.]' \
'-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]' \
'-state=[(terraform.tfstate) Path to read and save state (unless state-out is specified).]' \
'-state-out=[(path) Path to write state to that is different than "-state". This can be used to preserve the old state.]' \
'-target=[(resource) A Resource Address to target. Operation will be limited to this resource and its dependencies. This flag can be used multiple times.]' \
'-target=[(resource) Resource to target. Operation will be limited to this resource and its dependencies. This flag can be used multiple times.]' \
'-var[("foo=bar") Set a variable in the Terraform configuration. This flag can be set multiple times.]' \
'-var-file=[(path) Set variables in the Terraform configuration from a file. If "terraform.tfvars" is present, it will be automatically loaded if this flag is not specified.]'
'-var-file=[(foo) Set variables in the Terraform configuration from a file. If "terraform.tfvars" or any ".auto.tfvars" files are present, they will be automatically loaded.]'
}
__console() {
_arguments \
'-state=[(terraform.tfstate) Path to read state.]' \
'-var[("foo=bar") Set a variable in the Terraform configuration. This flag can be set multiple times.]' \
'-var-file=[(foo) Set variables in the Terraform configuration from a file. If "terraform.tfvars" or any ".auto.tfvars" files are present, they will be automatically loaded.]'
}
__destroy() {
_arguments \
'-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]' \
'-force[If set, then the destroy confirmation will not be shown.]' \
'-input=[(true) Ask for input for variables if not directly set.]' \
'-no-color[If specified, output will not contain any color.]' \
'-auto-approve[Skip interactive approval before destroying.]' \
'-force[Deprecated: same as auto-approve.]' \
'-lock=[(true) Lock the state file when locking is supported.]' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-no-color[If specified, output will contain no color.]' \
'-parallelism=[(10) Limit the number of concurrent operations.]' \
'-refresh=[(true) Update state prior to checking for differences. This has no effect if a plan file is given to apply.]' \
'-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]' \
'-state=[(terraform.tfstate) Path to read and save state (unless state-out is specified).]' \
'-state-out=[(path) Path to write state to that is different than "-state". This can be used to preserve the old state.]' \
'-target=[(resource) Instead of affecting "dependencies" will instead also destroy any resources that depend on the target(s) specified.]' \
'-target=[(resource) Resource to target. Operation will be limited to this resource and its dependencies. This flag can be used multiple times.]' \
'-var[("foo=bar") Set a variable in the Terraform configuration. This flag can be set multiple times.]' \
'-var-file=[(path) Set variables in the Terraform configuration from a file. If "terraform.tfvars" is present, it will be automatically loaded if this flag is not specified.]'
'-var-file=[(foo) Set variables in the Terraform configuration from a file. If "terraform.tfvars" or any ".auto.tfvars" files are present, they will be automatically loaded.]'
}
__fmt() {
_arguments \
'-list=[(true) List files whose formatting differs (always false if using STDIN)]' \
'-write=[(true) Write result to source file instead of STDOUT (always false if using STDIN or -check)]' \
'-diff=[(false) Display diffs of formatting changes]' \
'-check=[(false) Check if the input is formatted. Exit status will be 0 if all input is properly formatted and non-zero otherwise.]'
}
__get() {
_arguments \
'-update=[(false) If true, modules already downloaded will be checked for updates and updated if necessary.]'
'-update=[(false) If true, modules already downloaded will be checked for updates and updated if necessary.]' \
'-no-color[If specified, output will contain no color.]'
}
__graph() {
_arguments \
'-draw-cycles[Highlight any cycles in the graph with colored edges. This helps when diagnosing cycle errors.]' \
'-module-depth=[(n) The maximum depth to expand modules. By default this is zero, which will not expand modules at all.]' \
'-verbose[Generate a verbose, "worst-case" graph, with all nodes for potential operations in place.]'
'-no-color[If specified, output will contain no color.]' \
'-type=[(plan) Type of graph to output. Can be: plan, plan-destroy, apply, validate, input, refresh.]'
}
__import() {
_arguments \
'-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]' \
'-config=[(path) Path to a directory of Terraform configuration files to use to configure the provider. Defaults to pwd. If no config files are present, they must be provided via the input prompts or env vars.]' \
'-allow-missing-config[Allow import when no resource configuration block exists.]' \
'-input=[(true) Ask for input for variables if not directly set.]' \
'-lock=[(true) Lock the state file when locking is supported.]' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-no-color[If specified, output will contain no color.]' \
'-provider=[(provider) Specific provider to use for import. This is used for specifying aliases, such as "aws.eu". Defaults to the normal provider prefix of the resource being imported.]' \
'-state=[(PATH) Path to the source state file. Defaults to the configured backend, or "terraform.tfstate"]' \
'-state-out=[(PATH) Path to the destination state file to write to. If this is not specified, the source state file will be used. This can be a new or existing path.]' \
'-var[("foo=bar") Set a variable in the Terraform configuration. This flag can be set multiple times. This is only useful with the "-config" flag.]' \
'-var-file=[(foo) Set variables in the Terraform configuration from a file. If "terraform.tfvars" or any ".auto.tfvars" files are present, they will be automatically loaded.]'
}
__init() {
_arguments \
'-address=[(url) URL of the remote storage server. Required for HTTP backend, optional for Atlas and Consul.]' \
'-access-token=[(token) Authentication token for state storage server. Required for Atlas backend, optional for Consul.]' \
'-backend=[(atlas) Specifies the type of remote backend. Must be one of Atlas, Consul, or HTTP. Defaults to atlas.]' \
'-backend-config=[(path) Specifies the path to remote backend config file.]' \
'-name=[(name) Name of the state file in the state storage server. Required for Atlas backend.]' \
'-path=[(path) Path of the remote state in Consul. Required for the Consul backend.]'
'-backend=[(true) Configure the backend for this configuration.]' \
'-backend-config=[This can be either a path to an HCL file with key/value assignments (same format as terraform.tfvars) or a 'key=value' format. This is merged with what is in the configuration file. This can be specified multiple times. The backend type must be in the configuration itself.]' \
'-force-copy[Suppress prompts about copying state data. This is equivalent to providing a "yes" to all confirmation prompts.]' \
'-from-module=[Copy the contents of the given module into the target directory before initialization.]' \
'-get=[(true) Download any modules for this configuration.]' \
'-get-plugins=[(true) Download any missing plugins for this configuration.]' \
'-input=[(true) Ask for input if necessary. If false, will error if input was required.]' \
'-lock=[(true) Lock the state file when locking is supported.]' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-no-color[If specified, output will contain no color.]' \
'-plugin-dir[Directory containing plugin binaries. This overrides all default search paths for plugins, and prevents the automatic installation of plugins. This flag can be used multiple times.]' \
'-reconfigure[Reconfigure the backend, ignoring any saved configuration.]' \
'-upgrade=[(false) If installing modules (-get) or plugins (-get-plugins), ignore previously-downloaded objects and install the latest version allowed within configured constraints.]' \
'-verify-plugins=[(true) Verify the authenticity and integrity of automatically downloaded plugins.]'
}
__output() {
_arguments \
'-state=[(path) Path to the state file to read. Defaults to "terraform.tfstate".]' \
'-module=[(module_name) The module path which has needed output. By default this is the root path. Other modules can be specified by a period-separated list.]'
'-no-color[ If specified, output will contain no color.]' \
'-module=[(name) If specified, returns the outputs for a specific module]' \
'-json[If specified, machine readable output will be printed in JSON format]'
}
__plan() {
_arguments \
'-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with" .backup" extension. Set to "-" to disable backup.]' \
'-destroy[If set, a plan will be generated to destroy all resources managed by the given configuration and state.]' \
'-detailed-exitcode[Return a detailed exit code when the command exits. When provided, this argument changes the exit codes and their meanings to provide more granular information about what the resulting plan contains]' \
'-destroy[() If set, a plan will be generated to destroy all resources managed by the given configuration and state.]' \
'-detailed-exitcode[() Return detailed exit codes when the command exits. This will change the meaning of exit codes to: 0 - Succeeded, diff is empty (no changes); 1 - Errored, 2 - Succeeded; there is a diff]' \
'-input=[(true) Ask for input for variables if not directly set.]' \
'-module-depth=[(n) Specifies the depth of modules to show in the output. This does not affect the plan itself, only the output shown. By default, this is zero. -1 will expand all.]' \
'-no-color[If specified, output will not contain any color.]' \
'-lock=[(true) Lock the state file when locking is supported.]' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-module-depth=[(n) Specifies the depth of modules to show in the output. This does not affect the plan itself, only the output shown. By default, this is -1, which will expand all.]' \
'-no-color[() If specified, output will contain no color.]' \
'-out=[(path) Write a plan file to the given path. This can be used as input to the "apply" command.]' \
'-parallelism=[(10) Limit the number of concurrent operations.]' \
'-refresh=[(true) Update state prior to checking for differences.]' \
'-state=[(statefile) Path to a Terraform state file to use to look up Terraform-managed resources. By default it will use the state "terraform.tfstate" if it exists.]' \
'-target=[(resource) A Resource Address to target. Operation will be limited to this resource and its dependencies. This flag can be used multiple times.]' \
'-target=[(resource) Resource to target. Operation will be limited to this resource and its dependencies. This flag can be used multiple times.]' \
'-var[("foo=bar") Set a variable in the Terraform configuration. This flag can be set multiple times.]' \
'-var-file=[(path) Set variables in the Terraform configuration from a file. If "terraform.tfvars" is present, it will be automatically loaded if this flag is not specified.]'
'-var-file=[(foo) Set variables in the Terraform configuration from a file. If "terraform.tfvars" or any ".auto.tfvars" files are present, they will be automatically loaded.]' \
}
__providers() {
_arguments \
}
__push() {
......@@ -106,6 +166,9 @@ __push() {
__refresh() {
_arguments \
'-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]' \
'-input=[(true) Ask for input for variables if not directly set.]' \
'-lock=[(true) Lock the state file when locking is supported.]' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-no-color[If specified, output will not contain any color.]' \
'-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]' \
'-state-out=[(path) Path to write state to that is different than "-state". This can be used to preserve the old state.]' \
......@@ -114,19 +177,6 @@ __refresh() {
'-var-file=[(path) Set variables in the Terraform configuration from a file. If "terraform.tfvars" is present, it will be automatically loaded if this flag is not specified.]'
}
__remote() {
_arguments \
'-address=[(url) URL of the remote storage server. Required for HTTP backend, optional for Atlas and Consul.]' \
'-access-token=[(token) Authentication token for state storage server. Required for Atlas backend, optional for Consul.]' \
'-backend=[(atlas) Specifies the type of remote backend. Must be one of Atlas, Consul, or HTTP. Defaults to atlas.]' \
'-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]' \
'-disable[Disables remote state management and migrates the state to the -state path.]' \
'-name=[(name) Name of the state file in the state storage server. Required for Atlas backend.]' \
'-path=[(path) Path of the remote state in Consul. Required for the Consul backend.]' \
'-pull=[(true) Controls if the remote state is pulled before disabling. This defaults to true to ensure the latest state is cached before disabling.]' \
'-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]'
}
__show() {
_arguments \
'-module-depth=[(n) The maximum depth to expand modules. By default this is zero, which will not expand modules at all.]' \
......@@ -137,12 +187,46 @@ __taint() {
_arguments \
'-allow-missing[If specified, the command will succeed (exit code 0) even if the resource is missing.]' \
'-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]' \
'-lock=[(true) Lock the state file when locking is supported.]' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-module=[(path) The module path where the resource lives. By default this will be root. Child modules can be specified by names. Ex. "consul" or "consul.vpc" (nested modules).]' \
'-no-color[If specified, output will not contain any color.]' \
'-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]' \
'-state-out=[(path) Path to write updated state file. By default, the "-state" path will be used.]'
}
__untaint() {
_arguments \
'-allow-missing[If specified, the command will succeed (exit code 0) even if the resource is missing.]' \
'-backup=[(path) Path to backup the existing state file before modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup.]' \
'-lock=[(true) Lock the state file when locking is supported.]' \
'-lock-timeout=[(0s) Duration to retry a state lock.]' \
'-module=[(path) The module path where the resource lives. By default this will be root. Child modules can be specified by names. Ex. "consul" or "consul.vpc" (nested modules).]' \
'-no-color[If specified, output will not contain any color.]' \
'-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]' \
'-state-out=[(path) Path to write updated state file. By default, the "-state" path will be used.]'
}
__validate() {
_arguments \
'-check-variables=[(true) If set to true (default), the command will check whether all required variables have been specified.]' \
'-no-color[If specified, output will not contain any color.]' \
'-var[("foo=bar") Set a variable in the Terraform configuration. This flag can be set multiple times.]' \
'-var-file=[(path) Set variables in the Terraform configuration from a file. If "terraform.tfvars" is present, it will be automatically loaded if this flag is not specified.]'
}
__workspace() {
local -a __workspace_cmds
__workspace_cmds=(
'delete:Delete a workspace'
'list:List Workspaces'
'new:Create a new workspace'
'select:Select a workspace'
'show:Show the name of the current workspace'
)
_describe -t workspace "workspace commands" __workspace_cmds
}
_arguments '*:: :->command'
if (( CURRENT == 1 )); then
......@@ -154,26 +238,38 @@ local -a _command_args
case "$words[1]" in
apply)
__apply ;;
console)
__console;;
destroy)
__destroy ;;
fmt)
__fmt;;
get)
__get ;;
graph)
__graph ;;
import)
__import;;
init)
__init ;;
output)
__output ;;
plan)
__plan ;;
providers)
__providers ;;
push)
__push ;;
refresh)
__refresh ;;
remote)
__remote ;;
show)
__show ;;
taint)
__taint ;;
untaint)
__untaint ;;
validate)
__validate ;;
workspace)
test $CURRENT -lt 3 && __workspace ;;
esac
function tf_prompt_info() {
# dont show 'default' workspace in home dir
[[ "$PWD" == ~ ]] && return
# check if in terraform dir
if [ -d .terraform ]; then
workspace=$(terraform workspace show 2> /dev/null) || return
......
......@@ -4,7 +4,7 @@ Plugin for Textastic, a text and code editor for Mac OS X
### Requirements
* [Textastic](http://www.textasticapp.com/mac.html)
* [Textastic](https://www.textasticapp.com/mac.html)
### Usage
......
# TextMate plugin
The plugin adds a function for the [TextMate](https://macromates.com) editor.
To use it, add `textmate` to the plugins array of your zshrc file:
```
plugins=(... textmate)
```
## Function
The `tm` function provides the following options:
- No arguments: Run `mate` in the current directory.
- Argument that is a directory: Run `mate` in the given directory and cd to it.
- Other arguments: Pass all arguments to `mate`. This allows for easy opening of multiple files.
if [[ -z $commands[thefuck] ]]; then
echo 'thefuck is not installed, you should "pip install thefuck" first'
return -1
echo 'thefuck is not installed, you should "pip install thefuck" or "brew install thefuck" first.'
echo 'See https://github.com/nvbn/thefuck#installation'
return 1
fi
# Register alias
......
# Themes Plugin
This plugin allows you to change ZSH theme on the go.
To use it, add `themes` to the plugins array in your zshrc file:
```
plugins=(... themes)
```
## Usage
`theme <theme_name>` - Changes the ZSH theme to specified theme.
`theme ` - Changes the ZSH theme to some random theme.
`lstheme ` - Lists installed ZSH themes.
......@@ -8,9 +8,9 @@ function theme
source "$RANDOM_THEME"
echo "[oh-my-zsh] Random theme '$RANDOM_THEME' loaded..."
else
if [ -f "$ZSH_CUSTOM/$1.zsh-theme" ]
if [ -f "$ZSH_CUSTOM/themes/$1.zsh-theme" ]
then
source "$ZSH_CUSTOM/$1.zsh-theme"
source "$ZSH_CUSTOM/themes/$1.zsh-theme"
else
source "$ZSH/themes/$1.zsh-theme"
fi
......@@ -19,6 +19,8 @@ function theme
function lstheme
{
cd $ZSH/themes
ls *zsh-theme | sed 's,\.zsh-theme$,,'
# Resources:
# http://zsh.sourceforge.net/Doc/Release/Expansion.html#Modifiers
# http://zsh.sourceforge.net/Doc/Release/Expansion.html#Glob-Qualifiers
print -l {$ZSH,$ZSH_CUSTOM}/themes/*.zsh-theme(N:t:r)
}
This plugin allows to display command's execution time in a very nonintrusive way.
Timer can be tuned by these two variables:
* `TIMER_PRECISION` allows to control number of decimal places (default `1`)
* `TIMER_FORMAT` allows to adjust display format (default `'/%d'`)
Sample session:
me@here:~$ sleep 1 /1.0s
me@here:~$ sleep 73 /1m13.0s
me@here:~$ TIMER_FORMAT='[%d]'; TIMER_PRECISION=2 [0.00s]
me@here:~$ head -c50 < /dev/urandom | hexdump
0000000 b2 16 20 f0 29 1f 61 2d 8a 29 20 8c 8c 39 5a ab
0000010 21 47 0e f9 ee a4 76 46 71 9e 4f 6b a4 c4 51 cb
0000020 f9 1f 7e b9 6f 2c ae dd cf 40 6d 64 a8 fb d3 db
0000030 09 37
0000032 [0.02s]
__timer_current_time() {
perl -MTime::HiRes=time -e'print time'
}
__timer_format_duration() {
local mins=$(printf '%.0f' $(($1 / 60)))
local secs=$(printf "%.${TIMER_PRECISION:-1}f" $(($1 - 60 * mins)))
local duration_str=$(echo "${mins}m${secs}s")
local format="${TIMER_FORMAT:-/%d}"
echo "${format//\%d/${duration_str#0m}}"
}
__timer_save_time_preexec() {
__timer_cmd_start_time=$(__timer_current_time)
}
__timer_display_timer_precmd() {
if [ -n "${__timer_cmd_start_time}" ]; then
local cmd_end_time=$(__timer_current_time)
local tdiff=$((cmd_end_time - __timer_cmd_start_time))
unset __timer_cmd_start_time
local tdiffstr=$(__timer_format_duration ${tdiff})
local cols=$((COLUMNS - ${#tdiffstr} - 1))
echo -e "\033[1A\033[${cols}C ${tdiffstr}"
fi
}
preexec_functions+=(__timer_save_time_preexec)
precmd_functions+=(__timer_display_timer_precmd)
# tmux
This plugin provides aliases for [tmux](http://tmux.github.io/), the terminal multiplexer.
To use it add `tmux` to the plugins array in your zshrc file.
```zsh
plugins=(... tmux)
```
The plugin also supports the following -
- determines if tmux is installed or not, if not, prompts user to install tmux
- determines if the terminal supports the 256 colors or not, sets the appropriate configuration variable
- sets the correct local config file to use
## Aliases
| Alias | Command | Description |
| ------ | -----------------------|---------------------------------------------------------- |
| `ta` | tmux attach -t | Attach new tmux session to already running named session |
| `tad` | tmux attach -d -t | Detach named tmux session |
| `ts` | tmux new-session -s | Create a new named tmux session |
| `tl` | tmux list-sessions | Displays a list of running tmux sessions |
| `tksv` | tmux kill-server | Terminate all running tmux sessions |
| `tkss` | tmux kill-session -t | Terminate named running tmux session |
| `tmux` | `_zsh_tmux_plugin_run` | Start a new tmux session |
## Configuration Variables
| Variable | Description |
|-------------------------------------|-------------------------------------------------------------------------------|
| `ZSH_TMUX_AUTOSTART` | Automatically starts tmux (default: `false`) |
| `ZSH_TMUX_AUTOSTART_ONCE` | Autostart only if tmux hasn't been started previously (default: `true`) |
| `ZSH_TMUX_AUTOCONNECT` | Automatically connect to a previous session if it exits (default: `true`) |
| `ZSH_TMUX_AUTOQUIT` | Automatically closes terminal once tmux exits (default: `ZSH_TMUX_AUTOSTART`) |
| `ZSH_TMUX_FIXTERM` | Sets `$TERM` to 256-color term or not based on current terminal support |
| `ZSH_TMUX_ITERM2` | Sets the `-CC` option for iTerm2 tmux integration (default: `false`) |
| `ZSH_TMUX_FIXTERM_WITHOUT_256COLOR` | `$TERM` to use for non 256-color terminals (default: `screen`) |
| `ZSH_TMUX_FIXTERM_WITH_256COLOR` | `$TERM` to use for 256-color terminals (default: `screen-256color` |
#
# Aliases
#
if ! (( $+commands[tmux] )); then
print "zsh tmux plugin: tmux not found. Please install tmux before using this plugin." >&2
return 1
fi
# ALIASES
alias ta='tmux attach -t'
alias tad='tmux attach -d -t'
......@@ -9,90 +12,78 @@ alias tl='tmux list-sessions'
alias tksv='tmux kill-server'
alias tkss='tmux kill-session -t'
# Only run if tmux is actually installed
if which tmux &> /dev/null
then
# Configuration variables
#
# Automatically start tmux
[[ -n "$ZSH_TMUX_AUTOSTART" ]] || ZSH_TMUX_AUTOSTART=false
# Only autostart once. If set to false, tmux will attempt to
# autostart every time your zsh configs are reloaded.
[[ -n "$ZSH_TMUX_AUTOSTART_ONCE" ]] || ZSH_TMUX_AUTOSTART_ONCE=true
# Automatically connect to a previous session if it exists
[[ -n "$ZSH_TMUX_AUTOCONNECT" ]] || ZSH_TMUX_AUTOCONNECT=true
# Automatically close the terminal when tmux exits
[[ -n "$ZSH_TMUX_AUTOQUIT" ]] || ZSH_TMUX_AUTOQUIT=$ZSH_TMUX_AUTOSTART
# Set term to screen or screen-256color based on current terminal support
[[ -n "$ZSH_TMUX_FIXTERM" ]] || ZSH_TMUX_FIXTERM=true
# Set '-CC' option for iTerm2 tmux integration
[[ -n "$ZSH_TMUX_ITERM2" ]] || ZSH_TMUX_ITERM2=false
# The TERM to use for non-256 color terminals.
# Tmux states this should be screen, but you may need to change it on
# systems without the proper terminfo
[[ -n "$ZSH_TMUX_FIXTERM_WITHOUT_256COLOR" ]] || ZSH_TMUX_FIXTERM_WITHOUT_256COLOR="screen"
# The TERM to use for 256 color terminals.
# Tmux states this should be screen-256color, but you may need to change it on
# systems without the proper terminfo
[[ -n "$ZSH_TMUX_FIXTERM_WITH_256COLOR" ]] || ZSH_TMUX_FIXTERM_WITH_256COLOR="screen-256color"
# Get the absolute path to the current directory
local zsh_tmux_plugin_path="$(cd "$(dirname "$0")" && pwd)"
# CONFIGURATION VARIABLES
# Automatically start tmux
: ${ZSH_TMUX_AUTOSTART:=false}
# Only autostart once. If set to false, tmux will attempt to
# autostart every time your zsh configs are reloaded.
: ${ZSH_TMUX_AUTOSTART_ONCE:=true}
# Automatically connect to a previous session if it exists
: ${ZSH_TMUX_AUTOCONNECT:=true}
# Automatically close the terminal when tmux exits
: ${ZSH_TMUX_AUTOQUIT:=$ZSH_TMUX_AUTOSTART}
# Set term to screen or screen-256color based on current terminal support
: ${ZSH_TMUX_FIXTERM:=true}
# Set '-CC' option for iTerm2 tmux integration
: ${ZSH_TMUX_ITERM2:=false}
# The TERM to use for non-256 color terminals.
# Tmux states this should be screen, but you may need to change it on
# systems without the proper terminfo
: ${ZSH_TMUX_FIXTERM_WITHOUT_256COLOR:=screen}
# The TERM to use for 256 color terminals.
# Tmux states this should be screen-256color, but you may need to change it on
# systems without the proper terminfo
: ${ZSH_TMUX_FIXTERM_WITH_256COLOR:=screen-256color}
# Determine if the terminal supports 256 colors
if [[ `tput colors` == "256" ]]
then
# Determine if the terminal supports 256 colors
if [[ $terminfo[colors] == 256 ]]; then
export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITH_256COLOR
else
else
export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITHOUT_256COLOR
fi
fi
# Set the correct local config file to use.
if [[ "$ZSH_TMUX_ITERM2" == "false" ]] && [[ -f $HOME/.tmux.conf || -h $HOME/.tmux.conf ]]
then
#use this when they have a ~/.tmux.conf
export _ZSH_TMUX_FIXED_CONFIG="$zsh_tmux_plugin_path/tmux.extra.conf"
else
#use this when they don't have a ~/.tmux.conf
export _ZSH_TMUX_FIXED_CONFIG="$zsh_tmux_plugin_path/tmux.only.conf"
# Set the correct local config file to use.
if [[ "$ZSH_TMUX_ITERM2" == "false" && -e "$HOME/.tmux.conf" ]]; then
export _ZSH_TMUX_FIXED_CONFIG="${0:h:a}/tmux.extra.conf"
else
export _ZSH_TMUX_FIXED_CONFIG="${0:h:a}/tmux.only.conf"
fi
# Wrapper function for tmux.
function _zsh_tmux_plugin_run() {
if [[ -n "$@" ]]; then
command tmux "$@"
return $?
fi
# Wrapper function for tmux.
function _zsh_tmux_plugin_run()
{
# We have other arguments, just run them
if [[ -n "$@" ]]
then
\tmux $@
local -a tmux_cmd
tmux_cmd=(command tmux)
[[ "$ZSH_TMUX_ITERM2" == "true" ]] && tmux_cmd+=(-CC)
# Try to connect to an existing session.
elif [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]]
then
\tmux `[[ "$ZSH_TMUX_ITERM2" == "true" ]] && echo '-CC '` attach || \tmux `[[ "$ZSH_TMUX_ITERM2" == "true" ]] && echo '-CC '` `[[ "$ZSH_TMUX_FIXTERM" == "true" ]] && echo '-f '$_ZSH_TMUX_FIXED_CONFIG` new-session
[[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit
# Just run tmux, fixing the TERM variable if requested.
else
\tmux `[[ "$ZSH_TMUX_ITERM2" == "true" ]] && echo '-CC '` `[[ "$ZSH_TMUX_FIXTERM" == "true" ]] && echo '-f '$_ZSH_TMUX_FIXED_CONFIG`
[[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit
[[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] && $tmux_cmd attach
# If failed, just run tmux, fixing the TERM variable if requested.
if [[ $? -ne 0 ]]; then
[[ "$ZSH_TMUX_FIXTERM" == "true" ]] && tmux_cmd+=(-f "$_ZSH_TMUX_FIXED_CONFIG")
$tmux_cmd new-session
fi
}
# Use the completions for tmux for our function
compdef _tmux _zsh_tmux_plugin_run
if [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]]; then
exit
fi
}
# Alias tmux to our wrapper function.
alias tmux=_zsh_tmux_plugin_run
# Use the completions for tmux for our function
compdef _tmux _zsh_tmux_plugin_run
# Alias tmux to our wrapper function.
alias tmux=_zsh_tmux_plugin_run
# Autostart if not already in tmux and enabled.
if [[ ! -n "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" ]]
then
# Autostart if not already in tmux and enabled.
if [[ -z "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" && -z "$INSIDE_EMACS" && -z "$EMACS" && -z "$VIM" ]]; then
# Actually don't autostart if we already did and multiple autostarts are disabled.
if [[ "$ZSH_TMUX_AUTOSTART_ONCE" == "false" || "$ZSH_TMUX_AUTOSTARTED" != "true" ]]
then
if [[ "$ZSH_TMUX_AUTOSTART_ONCE" == "false" || "$ZSH_TMUX_AUTOSTARTED" != "true" ]]; then
export ZSH_TMUX_AUTOSTARTED=true
_zsh_tmux_plugin_run
fi
fi
else
print "zsh tmux plugin: tmux not found. Please install tmux before using this plugin."
fi
# Tmuxinator plugin
This plugin provides completion for [tmuxinator](https://github.com/tmuxinator/tmuxinator),
as well as aliases for frequent tmuxinator commands.
To use it add `tmuxinator` to the plugins array in your zshrc file.
```zsh
plugins=(... tmuxinator)
```
## Aliases
| Alias | Command | Description |
| ------ | ---------------- | ------------------------ |
| `txs ` | tmuxinator start | Start Tmuxinator |
| `txo ` | tmuxinator open | Open project for editing |
| `txn ` | tmuxinator new | Create project |
| `txl ` | tmuxinator list | List projects |
#compdef tmuxinator mux
#autoload
local curcontext="$curcontext" state line ret=1
local -a _configs
_tmuxinator() {
local commands projects
commands=(${(f)"$(tmuxinator commands zsh)"})
projects=(${(f)"$(tmuxinator completions start)"})
_arguments -C \
'1: :->cmds' \
'2:: :->args' && ret=0
_configs=(${$(echo ~/.tmuxinator/*.yml):r:t})
case $state in
cmds)
_values "tmuxinator command" \
"new[create a new project file and open it in your editor]" \
"start[start a tmux session using project's tmuxinator config]" \
"open[create a new project file and open it in your editor]" \
"copy[copy source_project project file to a new project called new_project]" \
"delete[deletes the project called project_name]" \
"debug[output the shell commands generated by a projet]" \
"implode[deletes all existing projects!]" \
"list[list all existing projects]" \
"doctor[look for problems in your configuration]" \
"help[shows this help document]" \
"version[shows tmuxinator version number]" \
$_configs
ret=0
;;
args)
case $line[1] in
start|open|copy|delete|debug)
[[ -n "$_configs" ]] && _values 'configs' $_configs
ret=0
if (( CURRENT == 2 )); then
_describe -t commands "tmuxinator subcommands" commands
_describe -t projects "tmuxinator projects" projects
elif (( CURRENT == 3)); then
case $words[2] in
copy|debug|delete|open|start)
_arguments '*:projects:($projects)'
;;
esac
;;
esac
fi
return
}
return ret
compdef _tmuxinator tmuxinator
# aliases
alias txs='tmuxinator start'
alias txo='tmuxinator open'
alias txn='tmuxinator new'
alias txl='tmuxinator list'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment