From c50bac7b42e7d24dd9ef314fa9bf17859e4218ed Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Tue, 21 Feb 2023 11:19:56 +0100 Subject: [PATCH 01/38] fix(terraform): go back to zsh custom completion Revert fcbfdf42de702d55174fe2b19142ba232289671e --- plugins/terraform/_terraform | 411 +++++++++++++++++++++++++ plugins/terraform/terraform.plugin.zsh | 5 - 2 files changed, 411 insertions(+), 5 deletions(-) create mode 100644 plugins/terraform/_terraform diff --git a/plugins/terraform/_terraform b/plugins/terraform/_terraform new file mode 100644 index 000000000..625834563 --- /dev/null +++ b/plugins/terraform/_terraform @@ -0,0 +1,411 @@ +#compdef terraform + +local -a _terraform_cmds opt_args +_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' + 'force-unlock:Manually unlock the terraform state' + 'get:Download and install modules for the configuration' + 'graph:Create a visual graph of Terraform resources' + 'import:Import existing infrastructure into Terraform' + 'init:Initialize a Terraform working directory' + 'login:Obtain and save credentials for a remote host' + 'logout:Remove locally-stored credentials for a remote host' + 'output:Read an output from a state file' + 'plan:Generate and show an execution plan' + 'providers:Prints a tree of the providers used in the configuration' + 'refresh:Update local state file against real resources' + 'show:Inspect Terraform state or plan' + 'state:Advanced state management' + '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' + '0.12upgrade:Rewrites pre-0.12 module source code for v0.12' + '0.13upgrade:Rewrites pre-0.13 module source code for v0.13' +) + +__012upgrade() { + _arguments \ + '-yes[Skip the initial introduction messages and interactive confirmation. This can be used to run this command in batch from a script.]' \ + '-force[ Override the heuristic that attempts to detect if a configuration is already written for v0.12 or later. Some of the transformations made by this command are not idempotent, so re-running against the same module may change the meanings expressions in the module.]' +} + +__013upgrade() { + _arguments \ + '-yes[Skip the initial introduction messages and interactive confirmation. This can be used to run this command in batch from a script.]' +} + +__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.]:backupfile:_files -g "*.backup"' \ + '-compact-warnings[If Terraform produces any warnings that are not accompanied by errors, show them in a more compact form that includes only the summary messages.]' \ + '-lock=[(true) Lock the state file when locking is supported.]:lock:(true false)' \ + '-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 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=[(terraform.tfstate) Path to read and save state (unless state-out is specified).]:statefile:_files -g "*.tfstate"' \ + '-state-out=[(path) Path to write state to that is different than "-state". This can be used to preserve the old state.]:statefile:_files -g "*.tfstate"' \ + '*-target=[(resource) Resource to target. Operation will be limited to this resource and its dependencies. This flag can be used multiple times.]:target:__statelist' \ + '*-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.]:file:_files -g "*.tfvars{,.json}"' +} + +__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.]:file:_files -g "*.tfvars{,.json}"' +} + +__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.]:backupfile:_files -g "*.backup"' \ + '-auto-approve[Skip interactive approval before destroying.]' \ + '-force[Deprecated: same as auto-approve.]' \ + '-lock=[(true) Lock the state file when locking is supported.]:lock:(true false)' \ + '-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=[(terraform.tfstate) Path to read and save state (unless state-out is specified).]:statefile:_files -g "*.tfstate"' \ + '-state-out=[(path) Path to write state to that is different than "-state". This can be used to preserve the old state.]:statefile:_files -g "*.tfstate"' \ + '*-target=[(resource) Resource to target. Operation will be limited to this resource and its dependencies. This flag can be used multiple times.]:target:__statelist' \ + '*-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.]:file:_files -g "*.tfvars{,.json}"' +} + +__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.]' \ + '-recursive=[(false) Also process files in subdirectories. By default, only the given directory (or current directory) is processed.]' +} + +__force_unlock() { + _arguments \ + "-force[Don't ask for input for unlock confirmation.]" +} + +__get() { + _arguments \ + '-update=[(false) If true, modules already downloaded will be checked for updates and updated if necessary.]' \ + '-no-color[Disable text coloring in the output.]' +} + +__graph() { + _arguments \ + '-draw-cycles[Highlight any cycles in the graph with colored edges. This helps when diagnosing cycle errors.]' \ + '-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.]:backupfile:_files -g "*.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:(true false)' \ + '-lock-timeout=[(0s) Duration to retry a state lock.]' \ + '-no-color[If specified, output will contain no color.]' \ + '-state=[(PATH) Path to the source state file. Defaults to the configured backend, or "terraform.tfstate"]:statefile:_files -g "*.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.]:statefile:_files -g "*.tfstate"' \ + '*-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.]:file:_files -g "*.tfvars{,.json}"' +} + +__init() { + _arguments \ + '-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=[(SOURCE) 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:(true false)' \ + '-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.]:plugin_dir:_files -/' \ + '-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.]' +} + +__login() { + _arguments \ + +} + +__logout() { + _arguments \ + +} + +__output() { + _arguments \ + '-state=[(path) Path to the state file to read. Defaults to "terraform.tfstate".]:statefile:_files -g "*.tfstate"' \ + '-no-color[If specified, output will contain no color.]' \ + '-json[If specified, machine readable output will be printed in JSON format]' +} + +__plan() { + _arguments \ + '-compact-warnings[If Terraform produces any warnings that are not accompanied by errors, show them in a more compact form that includes only the summary messages.]' \ + '-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.]' \ + '-lock=[(true) Lock the state file when locking is supported.]:lock:(true false)' \ + '-lock-timeout=[(0s) Duration to retry a state lock.]' \ + '-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.]:statefile:_files -g "*.tfstate"' \ + '*-target=[(resource) Resource to target. Operation will be limited to this resource and its dependencies. This flag can be used multiple times.]:target:__statelist' \ + '*-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.]:file:_files -g "*.tfvars{,.json}"' +} + +__providers() { + local -a __providers_cmds + __providers_cmds=( + 'mirror:Mirrors the provider plugins needed for the current configuration' + 'schema:Prints the schemas of the providers used in the configuration' + ) + _describe -t providers "providers commands" __providers_cmds + +} + +__providers_mirror() { + _arguments \ + '-platform=[(os_arch) Choose which target platform to build a mirror for.]' \ + "*:target_dir:_files -/" +} + +__providers_schema() { + _arguments \ + '-json[]' \ + '::' +} + +__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.]::backupfile:_files -g "*.backup"' \ + '-compact-warnings[If Terraform produces any warnings that are not accompanied by errors, show them in a more compact form that includes only the summary messages.]' \ + '-input=[(true) Ask for input for variables if not directly set.]' \ + '-lock=[(true) Lock the state file when locking is supported.]:lock:(true false)' \ + '-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".]:statefile:_files -g "*.tfstate"' \ + '-state-out=[(path) Path to write state to that is different than "-state". This can be used to preserve the old state.]:statefile:_files -g "*.tfstate"' \ + '*-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:__statelist' \ + '*-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.]:file:_files -g "*.tfvars{,.json}"' +} + +__show() { + _arguments \ + '-json[If specified, output the Terraform plan or state in a machine-readable form.]' \ + '-no-color[If specified, output will not contain any color.]' +} + +__state() { + local -a __state_cmds + __state_cmds=( + 'list:List resources in the state' + 'mv:Move an item in the state' + 'pull:Pull current state and output to stdout' + 'push:Update remote state from a local state file' + 'replace-provider:Replace provider for resources in the Terraform state' + 'rm:Remove instances from the state' + 'show:Show a resource in the state' + ) + _describe -t state "state commands" __state_cmds +} + +__state_list() { + _arguments \ + '-state=[(statefile) Path to a Terraform state file to use to look up Terraform-managed resources. By default, Terraform will consult the state of the currently-selected workspace.]' \ + '-id=[(id) Filters the results to include only instances whose resource types have an attribute named id whose value equals the given id string.]' \ + "*:address:__statelist" +} + +__state_mv() { + _arguments \ + "-dry-run[If set, prints out what would've been moved but doesn't actually move anything.]" \ + '-backup=[(PATH) Path where Terraform should write the backup for the original state. This can"t be disabled. If not set, Terraform will write it to the same path as the statefile with a ".backup" extension.]:backupfile:_files -g "*.backup"' \ + '-backup-out=[(PATH) Path where Terraform should write the backup for the destination state. This can"t be disabled. If not set, Terraform will write it to the same path as the destination state file with a backup extension. This only needs to be specified if -state-out is set to a different path than -state.]:backupfile:_files -g "*.backup"' \ + "-lock=[(true) Lock the state files when locking is supported.]:lock:(true false)" \ + "-lock-timeout=[(0s) Duration to retry a state lock.]" \ + '-state=[(path) Path to the source state file. Defaults to the configured backend, or "terraform.tfstate"]:statefile:_files -g "*.tfstate"' \ + '-state-out=[(path) Path to the destination state file to write to. If this isn"t specified, the source state file will be used. This can be a new or existing path.]:statefile:_files -g "*.tfstate"' \ + "::" \ + ":source:__statelist" \ + ":destination: " +} + +__state_push() { + _arguments \ + "-force[Write the state even if lineages don't match or the remote serial is higher.]" \ + '-lock=[(true) Lock the state file when locking is supported.]:lock:(true false)' \ + "-lock-timeout=[(0s) Duration to retry a state lock.]" \ + "::" \ + ":destination:_files" +} + +__state_replace_provider() { + _arguments \ + '-auto-approve[Skip interactive approval.]' \ + '-backup=[(PATH) Path where Terraform should write the backup for the state file. This can"t be disabled. If not set, Terraform will write it to the same path as the state file with a ".backup" extension.]:backupfile:_files -g "*.backup"' \ + "-lock=[(true) Lock the state files when locking is supported.]:lock:(true false)" \ + "-lock-timeout=[(0s) Duration to retry a state lock.]" \ + '-state=[(PATH) Path to the source state file. Defaults to the configured backend, or "terraform.tfstate"]:statefile:_files -g "*.tfstate"' \ + ":from_provider_fqn:" \ + ":to_provider_fqn:" +} + +__state_rm() { + _arguments \ + "-dry-run[If set, prints out what would've been removed but doesn't actually remove anything.]" \ + '-backup=[(PATH) Path where Terraform should write the backup for the original state.]::backupfile:_files -g "*.backup"' \ + "-lock=[(true) Lock the state file when locking is supported.]:lock:(true false)" \ + "-lock-timeout=[(0s) Duration to retry a state lock.]" \ + '-state=[(PATH) Path to the state file to update. Defaults to the current workspace state.]:statefile:_files -g "*.tfstate"' \ + "*:address:__statelist" +} + + +__state_show() { + _arguments \ + '-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.]:statefile:_files -g "*.tfstate"' \ + "*:address:__statelist" +} + +__statelist() { + compadd $(terraform state list $opt_args[-state]) +} + +__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.]:backupfile:_files -g "*.backup"' \ + '-lock=[(true) Lock the state file when locking is supported.]:lock:(true false)' \ + '-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).]' \ + '-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]:statefile:_files -g "*.tfstate"' \ + '-state-out=[(path) Path to write updated state file. By default, the "-state" path will be used.]:statefile:_files -g "*.tfstate"' \ + "*:address:__statelist" +} + +__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.]:backupfile:_files -g "*.backup"' \ + '-lock=[(true) Lock the state file when locking is supported.]:lock:(true false)' \ + '-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).]' \ + '-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]:statefile:_files -g "*.tfstate"' \ + '-state-out=[(path) Path to write updated state file. By default, the "-state" path will be used.]:statefile:_files -g "*.tfstate"' +} + +__validate() { + _arguments \ + '-no-color[If specified, output will not contain any color.]' \ + '-json[Produce output in a machine-readable JSON format, suitable for use in text editor integrations and other automated systems.]' \ + ':dir:_files -/' +} + +__version() { + _arguments \ + '-json[Output the version information as a JSON object.]' +} + +__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 + _describe -t commands "terraform command" _terraform_cmds + return +fi + +local -a _command_args +case "$words[1]" in + 0.12upgrade) + __012upgrade ;; + 0.13upgrade) + __013upgrade ;; + apply) + __apply ;; + console) + __console;; + destroy) + __destroy ;; + fmt) + __fmt;; + force-unlock) + __force_unlock;; + get) + __get ;; + graph) + __graph ;; + import) + __import;; + init) + __init ;; + login) + __login ;; + logout) + __logout ;; + output) + __output ;; + plan) + __plan ;; + providers) + test $CURRENT -lt 3 && __providers + [[ $words[2] = "mirror" ]] && __providers_mirror + [[ $words[2] = "schema" ]] && __providers_schema + ;; + refresh) + __refresh ;; + show) + __show ;; + state) + test $CURRENT -lt 3 && __state + [[ $words[2] = "list" ]] && __state_list + [[ $words[2] = "mv" ]] && __state_mv + [[ $words[2] = "push" ]] && __state_push + [[ $words[2] = "replace-provider" ]] && __state_replace_provider + [[ $words[2] = "rm" ]] && __state_rm + [[ $words[2] = "show" ]] && __state_show + ;; + taint) + __taint ;; + untaint) + __untaint ;; + validate) + __validate ;; + version) + __version ;; + workspace) + test $CURRENT -lt 3 && __workspace ;; +esac diff --git a/plugins/terraform/terraform.plugin.zsh b/plugins/terraform/terraform.plugin.zsh index eaa1e2e81..d9e39e6ac 100644 --- a/plugins/terraform/terraform.plugin.zsh +++ b/plugins/terraform/terraform.plugin.zsh @@ -16,8 +16,3 @@ alias tfi='terraform init' alias tfo='terraform output' alias tfp='terraform plan' alias tfv='terraform validate' - -if (( $+commands[terraform] )); then - autoload -U +X bashcompinit && bashcompinit - complete -o nospace -C terraform terraform -fi From 9f9d3b7d247b3c3e21542abaaf107e3d15aac1a5 Mon Sep 17 00:00:00 2001 From: rohitbahekar <57762527+rohitbahekar@users.noreply.github.com> Date: Tue, 21 Feb 2023 15:53:04 +0530 Subject: [PATCH 02/38] feat(terraform): add `tfc` alias (#10815) --- plugins/terraform/README.md | 1 + plugins/terraform/terraform.plugin.zsh | 1 + 2 files changed, 2 insertions(+) diff --git a/plugins/terraform/README.md b/plugins/terraform/README.md index 59c6e7f2a..c19f2ad1c 100644 --- a/plugins/terraform/README.md +++ b/plugins/terraform/README.md @@ -19,6 +19,7 @@ plugins=(... terraform) | ----- | -------------------- | | `tf` | `terraform` | | `tfa` | `terraform apply` | +| `tfc` | `terraform console` | | `tfd` | `terraform destroy` | | `tff` | `terraform fmt` | | `tfi` | `terraform init` | diff --git a/plugins/terraform/terraform.plugin.zsh b/plugins/terraform/terraform.plugin.zsh index d9e39e6ac..7006f204b 100644 --- a/plugins/terraform/terraform.plugin.zsh +++ b/plugins/terraform/terraform.plugin.zsh @@ -10,6 +10,7 @@ function tf_prompt_info() { alias tf='terraform' alias tfa='terraform apply' +alias tfc='terraform console' alias tfd='terraform destroy' alias tff='terraform fmt' alias tfi='terraform init' From a4f08ad238dba23a68df2a89b8fd47b8a9d26b0e Mon Sep 17 00:00:00 2001 From: Filippo Bonazzi Date: Wed, 22 Feb 2023 10:16:28 +0100 Subject: [PATCH 03/38] feat(extract): support `obscpio` format (#11511) Co-authored-by: Carlo Sala --- plugins/extract/README.md | 15 ++++++++------- plugins/extract/_extract | 2 +- plugins/extract/extract.plugin.zsh | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/plugins/extract/README.md b/plugins/extract/README.md index f67b53618..ac4a8e197 100644 --- a/plugins/extract/README.md +++ b/plugins/extract/README.md @@ -1,10 +1,10 @@ # extract plugin -This plugin defines a function called `extract` that extracts the archive file -you pass it, and it supports a wide variety of archive filetypes. +This plugin defines a function called `extract` that extracts the archive file you pass it, and it supports a +wide variety of archive filetypes. -This way you don't have to know what specific command extracts a file, you just -do `extract ` and the function takes care of the rest. +This way you don't have to know what specific command extracts a file, you just do `extract ` and +the function takes care of the rest. To use it, add `extract` to the plugins array in your zshrc file: @@ -15,7 +15,7 @@ plugins=(... extract) ## Supported file extensions | Extension | Description | -|:------------------|:-------------------------------------| +| :---------------- | :----------------------------------- | | `7z` | 7zip file | | `Z` | Z archive (LZW) | | `apk` | Android app file | @@ -32,6 +32,7 @@ plugins=(... extract) | `lrz` | LRZ archive | | `lz4` | LZ4 archive | | `lzma` | LZMA archive | +| `obscpio` | cpio archive used on OBS | | `rar` | WinRAR archive | | `rpm` | RPM package | | `sublime-package` | Sublime Text package | @@ -57,5 +58,5 @@ plugins=(... extract) | `zst` | Zstandard file (zstd) | | `zpaq` | Zpaq file | -See [list of archive formats](https://en.wikipedia.org/wiki/List_of_archive_formats) for -more information regarding archive formats. +See [list of archive formats](https://en.wikipedia.org/wiki/List_of_archive_formats) for more information +regarding archive formats. diff --git a/plugins/extract/_extract b/plugins/extract/_extract index 64678fede..56b17058f 100644 --- a/plugins/extract/_extract +++ b/plugins/extract/_extract @@ -3,5 +3,5 @@ _arguments \ '(-r --remove)'{-r,--remove}'[Remove archive.]' \ - "*::archive file:_files -g '(#i)*.(7z|Z|apk|aar|bz2|cab|cpio|deb|ear|gz|ipa|ipsw|jar|lrz|lz4|lzma|rar|rpm|sublime-package|tar|tar.bz2|tar.gz|tar.lrz|tar.lz|tar.lz4|tar.xz|tar.zma|tar.zst|tbz|tbz2|tgz|tlz|txz|tzst|war|whl|xpi|xz|zip|zst|zpaq)(-.)'" \ + "*::archive file:_files -g '(#i)*.(7z|Z|apk|aar|bz2|cab|cpio|deb|ear|gz|ipa|ipsw|jar|lrz|lz4|lzma|obscpio|rar|rpm|sublime-package|tar|tar.bz2|tar.gz|tar.lrz|tar.lz|tar.lz4|tar.xz|tar.zma|tar.zst|tbz|tbz2|tgz|tlz|txz|tzst|war|whl|xpi|xz|zip|zst|zpaq)(-.)'" \ && return 0 diff --git a/plugins/extract/extract.plugin.zsh b/plugins/extract/extract.plugin.zsh index 4c84ef883..7b7a2fa4f 100644 --- a/plugins/extract/extract.plugin.zsh +++ b/plugins/extract/extract.plugin.zsh @@ -72,7 +72,7 @@ EOF builtin cd -q ..; command rm *.tar.* debian-binary ;; (*.zst) unzstd "$file" ;; (*.cab) cabextract -d "$extract_dir" "$file" ;; - (*.cpio) cpio -idmvF "$file" ;; + (*.cpio|*.obscpio) cpio -idmvF "$file" ;; (*.zpaq) zpaq x "$file" ;; (*) echo "extract: '$file' cannot be extracted" >&2 From 221eb9b90ab4d03b6f00e62f31e979459e08e7ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E4=B8=8D=E6=B8=B8?= <71683364+mefengl@users.noreply.github.com> Date: Tue, 21 Feb 2023 03:07:45 +0800 Subject: [PATCH 04/38] feat(marktext): add plugin Closes #11507 --- plugins/marktext/README.md | 17 +++++++++++++++++ plugins/marktext/marktext.plugin.zsh | 7 +++++++ 2 files changed, 24 insertions(+) create mode 100644 plugins/marktext/README.md create mode 100644 plugins/marktext/marktext.plugin.zsh diff --git a/plugins/marktext/README.md b/plugins/marktext/README.md new file mode 100644 index 000000000..71d287451 --- /dev/null +++ b/plugins/marktext/README.md @@ -0,0 +1,17 @@ +## marktext + +Plugin for MarkText, a previewer for Markdown files on Mac OS X + +### Requirements + + * [MarkText](https://github.com/marktext/marktext) + +### Usage + + * If `marktext` is called without an argument, open MarkText + + * If `marktext` is passed a file, open it in MarkText + +### Credits + + * just copied from plugins/marked2, all credits to marked2 plugin author diff --git a/plugins/marktext/marktext.plugin.zsh b/plugins/marktext/marktext.plugin.zsh new file mode 100644 index 000000000..1da85bcca --- /dev/null +++ b/plugins/marktext/marktext.plugin.zsh @@ -0,0 +1,7 @@ +# +# If marktext is called without an argument, open MarkText +# If marktext is passed a file, open it in MarkText +# +function marktext() { + open -a "MarkText.app" "$1" +} From a24e91908adb25dfc222e6a6f6431e2fbc890545 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E4=B8=8D=E6=B8=B8?= <71683364+mefengl@users.noreply.github.com> Date: Wed, 22 Feb 2023 18:26:30 +0800 Subject: [PATCH 05/38] feat(marked): remove unnecessary code --- plugins/marked2/marked2.plugin.zsh | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/plugins/marked2/marked2.plugin.zsh b/plugins/marked2/marked2.plugin.zsh index 56863ade5..45f4b65c1 100644 --- a/plugins/marked2/marked2.plugin.zsh +++ b/plugins/marked2/marked2.plugin.zsh @@ -3,10 +3,5 @@ # If marked is passed a file, open it in Marked # function marked() { - if [ "$1" ] - then - open -a "marked 2.app" "$1" - else - open -a "marked 2.app" - fi + open -a "marked 2.app" "$1" } From aca048814b2462501ab82938ff2473661182fffb Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Wed, 22 Feb 2023 15:35:12 +0100 Subject: [PATCH 06/38] fix(theme-and-appearance): avoid infinite recursion --- lib/theme-and-appearance.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/theme-and-appearance.zsh b/lib/theme-and-appearance.zsh index c83f58c7b..1b64b51d4 100644 --- a/lib/theme-and-appearance.zsh +++ b/lib/theme-and-appearance.zsh @@ -47,7 +47,7 @@ fi # enable diff color if possible. if command diff --color /dev/null /dev/null &>/dev/null; then function color-diff { - diff --color $@ + command diff --color $@ } alias diff="color-diff" compdef _diff color-diff # compdef is already loaded by this point From b54ef89fab89eaa62ece588f96d8cbd7c222d854 Mon Sep 17 00:00:00 2001 From: WaferJay <17383312+WaferJay@users.noreply.github.com> Date: Fri, 24 Feb 2023 05:32:40 +0800 Subject: [PATCH 07/38] fix(af-magic): fix logic for separator with virtualenv (#11518) --- themes/af-magic.zsh-theme | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/themes/af-magic.zsh-theme b/themes/af-magic.zsh-theme index 1b629e43a..70549d01f 100644 --- a/themes/af-magic.zsh-theme +++ b/themes/af-magic.zsh-theme @@ -6,7 +6,8 @@ # dashed separator size function afmagic_dashes { # check either virtualenv or condaenv variables - local python_env="${VIRTUAL_ENV:-$CONDA_DEFAULT_ENV}" + local python_env_dir="${VIRTUAL_ENV:-$CONDA_DEFAULT_ENV}" + local python_env="${python_env_dir##*/}" # if there is a python virtual environment and it is displayed in # the prompt, account for it when returning the number of dashes From 8a008e1f51d451db21232edd6f1709e6c5ea334e Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Thu, 23 Feb 2023 23:00:31 +0100 Subject: [PATCH 08/38] fix(azure): load completion properly for brew (#11499) Closes #11497 --- plugins/azure/azure.plugin.zsh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/azure/azure.plugin.zsh b/plugins/azure/azure.plugin.zsh index 7bb173a5c..51b54dbc1 100644 --- a/plugins/azure/azure.plugin.zsh +++ b/plugins/azure/azure.plugin.zsh @@ -32,12 +32,14 @@ function _az-homebrew-installed() { (( $+commands[brew] )) || return 1 # speculatively check default brew prefix - if [ -h /usr/local/opt/az ]; then - _brew_prefix=/usr/local/opt/az + if [[ -d /usr/local ]]; then + _brew_prefix=/usr/local + elif [[ -d /opt/homebrew ]]; then + _brew_prefix=/opt/homebrew else # ok, it is not in the default prefix # this call to brew is expensive (about 400 ms), so at least let's make it only once - _brew_prefix=$(brew --prefix azure-cli) + _brew_prefix=$(brew --prefix) fi } @@ -49,12 +51,12 @@ _az_zsh_completer_path="$commands[az_zsh_completer.sh]" if [[ -z $_az_zsh_completer_path ]]; then # Homebrew if _az-homebrew-installed; then - _az_zsh_completer_path=$_brew_prefix/libexec/bin/az.completion.sh + _az_zsh_completer_path=$_brew_prefix/etc/bash_completion.d/az # Linux else _az_zsh_completer_path=/etc/bash_completion.d/azure-cli fi fi -[[ -r $_az_zsh_completer_path ]] && source $_az_zsh_completer_path +[[ -r $_az_zsh_completer_path ]] && autoload -U +X bashcompinit && bashcompinit && source $_az_zsh_completer_path unset _az_zsh_completer_path _brew_prefix From bd9c216fe04a1542913f524cad1719797ce39ba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Reegn?= Date: Fri, 24 Feb 2023 17:27:15 +0100 Subject: [PATCH 09/38] feat(iterm2): add shell integration script (#11509) --- plugins/iterm2/README.md | 12 ++ plugins/iterm2/iterm2.plugin.zsh | 11 ++ plugins/iterm2/iterm2_shell_integration.zsh | 178 ++++++++++++++++++++ plugins/iterm2/update | 4 + 4 files changed, 205 insertions(+) create mode 100644 plugins/iterm2/iterm2_shell_integration.zsh create mode 100755 plugins/iterm2/update diff --git a/plugins/iterm2/README.md b/plugins/iterm2/README.md index 50cdebf5e..3d11622df 100644 --- a/plugins/iterm2/README.md +++ b/plugins/iterm2/README.md @@ -2,11 +2,20 @@ This plugin adds a few functions that are useful when using [iTerm2](https://www.iterm2.com/). + To use it, add _iterm2_ to the plugins array of your zshrc file: ``` plugins=(... iterm2) ``` +Optionally, the plugin also applies the [Shell Integration Script for iTerm2](https://iterm2.com/documentation-shell-integration.html). +You can enable the integration with zstyle. It's important to add this line +before the line sourcing oh-my-zsh: + +``` +zstyle :omz:plugins:iterm2 shell-integration yes +``` + ## Plugin commands * `_iterm2_command ` @@ -24,6 +33,9 @@ plugins=(... iterm2) * `iterm2_tab_color_reset` resets the color of iTerm2's current tab back to default. + +For shell integration features see the [official documentation](https://iterm2.com/documentation-shell-integration.html). + ## Contributors - [Aviv Rosenberg](https://github.com/avivrosenberg) diff --git a/plugins/iterm2/iterm2.plugin.zsh b/plugins/iterm2/iterm2.plugin.zsh index 9d8e40bf6..d00232a30 100644 --- a/plugins/iterm2/iterm2.plugin.zsh +++ b/plugins/iterm2/iterm2.plugin.zsh @@ -7,6 +7,17 @@ # This plugin is only relevant if the terminal is iTerm2 on OSX. if [[ "$OSTYPE" == darwin* ]] && [[ -n "$ITERM_SESSION_ID" ]] ; then + # maybe make it the default in the future and allow opting out? + if zstyle -t ':omz:plugins:iterm2' shell-integration; then + # Handle $0 according to the standard: + # https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html + 0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}" + 0="${${(M)0:#/*}:-$PWD/$0}" + + # See official docs: https://iterm2.com/documentation-shell-integration.html + source "${0:A:h}/iterm2_shell_integration.zsh" + fi + ### # Executes an arbitrary iTerm2 command via an escape code sequence. # See https://iterm2.com/documentation-escape-codes.html for all supported commands. diff --git a/plugins/iterm2/iterm2_shell_integration.zsh b/plugins/iterm2/iterm2_shell_integration.zsh new file mode 100644 index 000000000..7871ddded --- /dev/null +++ b/plugins/iterm2/iterm2_shell_integration.zsh @@ -0,0 +1,178 @@ +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +if [[ -o interactive ]]; then + if [ "${ITERM_ENABLE_SHELL_INTEGRATION_WITH_TMUX-}""$TERM" != "tmux-256color" -a "${ITERM_ENABLE_SHELL_INTEGRATION_WITH_TMUX-}""$TERM" != "screen" -a "${ITERM_SHELL_INTEGRATION_INSTALLED-}" = "" -a "$TERM" != linux -a "$TERM" != dumb ]; then + ITERM_SHELL_INTEGRATION_INSTALLED=Yes + ITERM2_SHOULD_DECORATE_PROMPT="1" + # Indicates start of command output. Runs just before command executes. + iterm2_before_cmd_executes() { + if [ "$TERM_PROGRAM" = "iTerm.app" ]; then + printf "\033]133;C;\r\007" + else + printf "\033]133;C;\007" + fi + } + + iterm2_set_user_var() { + printf "\033]1337;SetUserVar=%s=%s\007" "$1" $(printf "%s" "$2" | base64 | tr -d '\n') + } + + # Users can write their own version of this method. It should call + # iterm2_set_user_var but not produce any other output. + # e.g., iterm2_set_user_var currentDirectory $PWD + # Accessible in iTerm2 (in a badge now, elsewhere in the future) as + # \(user.currentDirectory). + whence -v iterm2_print_user_vars > /dev/null 2>&1 + if [ $? -ne 0 ]; then + iterm2_print_user_vars() { + true + } + fi + + iterm2_print_state_data() { + local _iterm2_hostname="${iterm2_hostname-}" + if [ -z "${iterm2_hostname:-}" ]; then + _iterm2_hostname=$(hostname -f 2>/dev/null) + fi + printf "\033]1337;RemoteHost=%s@%s\007" "$USER" "${_iterm2_hostname-}" + printf "\033]1337;CurrentDir=%s\007" "$PWD" + iterm2_print_user_vars + } + + # Report return code of command; runs after command finishes but before prompt + iterm2_after_cmd_executes() { + printf "\033]133;D;%s\007" "$STATUS" + iterm2_print_state_data + } + + # Mark start of prompt + iterm2_prompt_mark() { + printf "\033]133;A\007" + } + + # Mark end of prompt + iterm2_prompt_end() { + printf "\033]133;B\007" + } + + # There are three possible paths in life. + # + # 1) A command is entered at the prompt and you press return. + # The following steps happen: + # * iterm2_preexec is invoked + # * PS1 is set to ITERM2_PRECMD_PS1 + # * ITERM2_SHOULD_DECORATE_PROMPT is set to 1 + # * The command executes (possibly reading or modifying PS1) + # * iterm2_precmd is invoked + # * ITERM2_PRECMD_PS1 is set to PS1 (as modified by command execution) + # * PS1 gets our escape sequences added to it + # * zsh displays your prompt + # * You start entering a command + # + # 2) You press ^C while entering a command at the prompt. + # The following steps happen: + # * (iterm2_preexec is NOT invoked) + # * iterm2_precmd is invoked + # * iterm2_before_cmd_executes is called since we detected that iterm2_preexec was not run + # * (ITERM2_PRECMD_PS1 and PS1 are not messed with, since PS1 already has our escape + # sequences and ITERM2_PRECMD_PS1 already has PS1's original value) + # * zsh displays your prompt + # * You start entering a command + # + # 3) A new shell is born. + # * PS1 has some initial value, either zsh's default or a value set before this script is sourced. + # * iterm2_precmd is invoked + # * ITERM2_SHOULD_DECORATE_PROMPT is initialized to 1 + # * ITERM2_PRECMD_PS1 is set to the initial value of PS1 + # * PS1 gets our escape sequences added to it + # * Your prompt is shown and you may begin entering a command. + # + # Invariants: + # * ITERM2_SHOULD_DECORATE_PROMPT is 1 during and just after command execution, and "" while the prompt is + # shown and until you enter a command and press return. + # * PS1 does not have our escape sequences during command execution + # * After the command executes but before a new one begins, PS1 has escape sequences and + # ITERM2_PRECMD_PS1 has PS1's original value. + iterm2_decorate_prompt() { + # This should be a raw PS1 without iTerm2's stuff. It could be changed during command + # execution. + ITERM2_PRECMD_PS1="$PS1" + ITERM2_SHOULD_DECORATE_PROMPT="" + + # Add our escape sequences just before the prompt is shown. + # Use ITERM2_SQUELCH_MARK for people who can't mdoify PS1 directly, like powerlevel9k users. + # This is gross but I had a heck of a time writing a correct if statetment for zsh 5.0.2. + local PREFIX="" + if [[ $PS1 == *"$(iterm2_prompt_mark)"* ]]; then + PREFIX="" + elif [[ "${ITERM2_SQUELCH_MARK-}" != "" ]]; then + PREFIX="" + else + PREFIX="%{$(iterm2_prompt_mark)%}" + fi + PS1="$PREFIX$PS1%{$(iterm2_prompt_end)%}" + ITERM2_DECORATED_PS1="$PS1" + } + + iterm2_precmd() { + local STATUS="$?" + if [ -z "${ITERM2_SHOULD_DECORATE_PROMPT-}" ]; then + # You pressed ^C while entering a command (iterm2_preexec did not run) + iterm2_before_cmd_executes + if [ "$PS1" != "${ITERM2_DECORATED_PS1-}" ]; then + # PS1 changed, perhaps in another precmd. See issue 9938. + ITERM2_SHOULD_DECORATE_PROMPT="1" + fi + fi + + iterm2_after_cmd_executes "$STATUS" + + if [ -n "$ITERM2_SHOULD_DECORATE_PROMPT" ]; then + iterm2_decorate_prompt + fi + } + + # This is not run if you press ^C while entering a command. + iterm2_preexec() { + # Set PS1 back to its raw value prior to executing the command. + PS1="$ITERM2_PRECMD_PS1" + ITERM2_SHOULD_DECORATE_PROMPT="1" + iterm2_before_cmd_executes + } + + # If hostname -f is slow on your system set iterm2_hostname prior to + # sourcing this script. We know it is fast on macOS so we don't cache + # it. That lets us handle the hostname changing like when you attach + # to a VPN. + if [ -z "${iterm2_hostname-}" ]; then + if [ "$(uname)" != "Darwin" ]; then + iterm2_hostname=`hostname -f 2>/dev/null` + # Some flavors of BSD (i.e. NetBSD and OpenBSD) don't have the -f option. + if [ $? -ne 0 ]; then + iterm2_hostname=`hostname` + fi + fi + fi + + [[ -z ${precmd_functions-} ]] && precmd_functions=() + precmd_functions=($precmd_functions iterm2_precmd) + + [[ -z ${preexec_functions-} ]] && preexec_functions=() + preexec_functions=($preexec_functions iterm2_preexec) + + iterm2_print_state_data + printf "\033]1337;ShellIntegrationVersion=14;shell=zsh\007" + fi +fi diff --git a/plugins/iterm2/update b/plugins/iterm2/update new file mode 100755 index 000000000..da8dae690 --- /dev/null +++ b/plugins/iterm2/update @@ -0,0 +1,4 @@ +#!/bin/sh + +curl -s -L https://iterm2.com/shell_integration/zsh \ + -o iterm2_shell_integration.zsh From 5cb943eea46d322542c5c2a9f54b201eddc2aa67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Fri, 24 Feb 2023 17:27:23 +0100 Subject: [PATCH 10/38] fix(lib): fix return code after expected non-zero exit code (#11524) Fixes #11524 --- lib/directories.zsh | 2 +- lib/vcs_info.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/directories.zsh b/lib/directories.zsh index 091140626..9274b5f5f 100644 --- a/lib/directories.zsh +++ b/lib/directories.zsh @@ -8,7 +8,7 @@ setopt pushdminus # to your `zshrc` before loading `oh-my-zsh.sh` # to disable the following aliases and functions -zstyle -T ':omz:directories' aliases || return +zstyle -T ':omz:directories' aliases || return 0 alias -g ...='../..' alias -g ....='../../..' diff --git a/lib/vcs_info.zsh b/lib/vcs_info.zsh index e60938c14..be6d32ee9 100644 --- a/lib/vcs_info.zsh +++ b/lib/vcs_info.zsh @@ -38,7 +38,7 @@ # due to malicious input as a consequence of CVE-2021-45444, which affects # zsh versions from 5.0.3 to 5.8. # -autoload -Uz +X regexp-replace VCS_INFO_formats 2>/dev/null || return +autoload -Uz +X regexp-replace VCS_INFO_formats 2>/dev/null || return 0 # We use $tmp here because it's already a local variable in VCS_INFO_formats typeset PATCH='for tmp (base base-name branch misc revision subdir) hook_com[$tmp]="${hook_com[$tmp]//\%/%%}"' From 277f38212aef31a6baba2cf1a0a355af611be5e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Fri, 24 Feb 2023 20:55:31 +0100 Subject: [PATCH 11/38] refactor: reorganize setopts in lib folder --- lib/directories.zsh | 1 + lib/misc.zsh | 8 +++----- lib/theme-and-appearance.zsh | 2 -- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/directories.zsh b/lib/directories.zsh index 9274b5f5f..13b680c19 100644 --- a/lib/directories.zsh +++ b/lib/directories.zsh @@ -1,4 +1,5 @@ # Changing/making/removing directory +setopt auto_cd setopt auto_pushd setopt pushd_ignore_dups setopt pushdminus diff --git a/lib/misc.zsh b/lib/misc.zsh index 1f637083a..132f33551 100644 --- a/lib/misc.zsh +++ b/lib/misc.zsh @@ -15,8 +15,9 @@ if [[ $DISABLE_MAGIC_FUNCTIONS != true ]]; then done fi -## jobs -setopt long_list_jobs +setopt multios # enable redirect to multiple streams: echo >file1 >file2 +setopt long_list_jobs # show long list format job notifications +setopt interactivecomments # recognize comments env_default 'PAGER' 'less' env_default 'LESS' '-R' @@ -30,6 +31,3 @@ if (( $+commands[ack-grep] )); then elif (( $+commands[ack] )); then alias afind='ack -il' fi - -# recognize comments -setopt interactivecomments diff --git a/lib/theme-and-appearance.zsh b/lib/theme-and-appearance.zsh index 1b64b51d4..208ab9ce5 100644 --- a/lib/theme-and-appearance.zsh +++ b/lib/theme-and-appearance.zsh @@ -53,8 +53,6 @@ if command diff --color /dev/null /dev/null &>/dev/null; then compdef _diff color-diff # compdef is already loaded by this point fi -setopt auto_cd -setopt multios setopt prompt_subst [[ -n "$WINDOW" ]] && SCREEN_NO="%B$WINDOW%b " || SCREEN_NO="" From cd647b6dc6779a1aafa2bcc3a81ec10b65c783ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Sun, 26 Feb 2023 15:44:18 +0100 Subject: [PATCH 12/38] fix(gnu-utils): reset ls alias to use GNU-based --color argument (#11527) Fixes #11503 --- plugins/gnu-utils/gnu-utils.plugin.zsh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plugins/gnu-utils/gnu-utils.plugin.zsh b/plugins/gnu-utils/gnu-utils.plugin.zsh index 9419127d8..6bd3e8463 100644 --- a/plugins/gnu-utils/gnu-utils.plugin.zsh +++ b/plugins/gnu-utils/gnu-utils.plugin.zsh @@ -61,3 +61,14 @@ __gnu_utils_preexec() { autoload -Uz add-zsh-hook add-zsh-hook preexec __gnu_utils_preexec + +# lib/theme-and-appearance.zsh sets the alias for ls not knowing that +# we'll be using GNU ls. We'll reset this to use GNU ls --color. +# See https://github.com/ohmyzsh/ohmyzsh/issues/11503 +# +# The ls alias might look like: +# - ls='ls -G' +# - ls='gls --color=tty' +if [[ -x "${commands[gls]}" && "${aliases[ls]}" = (*-G*|gls*) ]]; then + alias ls='ls --color=tty' +fi From 0ca8907f0e6185545c5e38f77ae2f09ca2a44e77 Mon Sep 17 00:00:00 2001 From: Jannik Date: Sun, 26 Feb 2023 20:37:03 +0100 Subject: [PATCH 13/38] fix(lib): fix case-insensitive completion for zsh 5.9 (#11526) --- lib/completion.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/completion.zsh b/lib/completion.zsh index 2c5695487..63379b53f 100644 --- a/lib/completion.zsh +++ b/lib/completion.zsh @@ -18,9 +18,9 @@ if [[ "$CASE_SENSITIVE" = true ]]; then zstyle ':completion:*' matcher-list 'r:|=*' 'l:|=* r:|=*' else if [[ "$HYPHEN_INSENSITIVE" = true ]]; then - zstyle ':completion:*' matcher-list 'm:{a-zA-Z-_}={A-Za-z_-}' 'r:|=*' 'l:|=* r:|=*' + zstyle ':completion:*' matcher-list 'm:{[:lower:][:upper:]-_}={[:upper:][:lower:]_-}' 'r:|=*' 'l:|=* r:|=*' else - zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|=*' 'l:|=* r:|=*' + zstyle ':completion:*' matcher-list 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' 'r:|=*' 'l:|=* r:|=*' fi fi unset CASE_SENSITIVE HYPHEN_INSENSITIVE From 16050ab80e63f8e53c07777b4c2ae16ad085e5ad Mon Sep 17 00:00:00 2001 From: Richard Mitchell Date: Sun, 26 Feb 2023 16:40:44 -0500 Subject: [PATCH 14/38] feat(macos): allow multiple man pages in `man-preview` (#11365) --- plugins/macos/README.md | 2 +- plugins/macos/macos.plugin.zsh | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/macos/README.md b/plugins/macos/README.md index 1bc4244a4..1cb9b395d 100644 --- a/plugins/macos/README.md +++ b/plugins/macos/README.md @@ -25,7 +25,7 @@ Original author: [Sorin Ionescu](https://github.com/sorin-ionescu) | `pxd` | Return the current Xcode project directory | | `cdx` | `cd` to the current Xcode project directory | | `quick-look` | Quick-Look a specified file | -| `man-preview` | Open a specified man page in Preview app | +| `man-preview` | Open man pages in Preview app | | `showfiles` | Show hidden files in Finder | | `hidefiles` | Hide the hidden files in Finder | | `itunes` | _DEPRECATED_. Use `music` from macOS Catalina on | diff --git a/plugins/macos/macos.plugin.zsh b/plugins/macos/macos.plugin.zsh index e4d759dcf..e27d412c8 100644 --- a/plugins/macos/macos.plugin.zsh +++ b/plugins/macos/macos.plugin.zsh @@ -224,9 +224,10 @@ function quick-look() { } function man-preview() { - local location - # Don't let Preview.app steal focus if the man page doesn't exist - location=$(man -w "$@") && mandoc -Tpdf $location | open -f -a Preview + local page + for page in "${(@f)"$(man -w $@)"}"; do + command mandoc -Tpdf $page | open -f -a Preview + done } compdef _man man-preview From 21bdb18b2d1fe8b547a42da7ac7b58fb28563a2c Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Monti Date: Mon, 27 Feb 2023 20:22:39 +0100 Subject: [PATCH 15/38] feat(nodenv): add plugin for `nodenv` (#9880) Co-authored-by: Matthew Boston --- plugins/nodenv/README.md | 20 +++++++++++++++ plugins/nodenv/nodenv.plugin.zsh | 43 ++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 plugins/nodenv/README.md create mode 100644 plugins/nodenv/nodenv.plugin.zsh diff --git a/plugins/nodenv/README.md b/plugins/nodenv/README.md new file mode 100644 index 000000000..550597025 --- /dev/null +++ b/plugins/nodenv/README.md @@ -0,0 +1,20 @@ +# nodenv plugin + +The primary job of this plugin is to provide `nodenv_prompt_info` which can be added to your theme to include Node +version information into your prompt. + +To use it, add `nodenv` to the plugins array in your zshrc file: + +```zsh +plugins=(... nodenv) +``` + +## Functions + +* `nodenv_prompt_info`: displays the Node version in use by nodenv; or the global Node + version, if nodenv wasn't found. You can use this function in your prompt by adding + `$(nodenv_prompt_info)` to PROMPT or RPROMPT: + + ```zsh + RPROMPT='$(nodenv_prompt_info)' + ``` diff --git a/plugins/nodenv/nodenv.plugin.zsh b/plugins/nodenv/nodenv.plugin.zsh new file mode 100644 index 000000000..79a4ffbb5 --- /dev/null +++ b/plugins/nodenv/nodenv.plugin.zsh @@ -0,0 +1,43 @@ +# This plugin loads nodenv into the current shell and provides prompt info via +# the 'nodenv_prompt_info' function. + +FOUND_NODENV=${+commands[nodenv]} + +if [[ $FOUND_NODENV -ne 1 ]]; then + nodenvdirs=( + "$HOME/.nodenv" + "/usr/local/nodenv" + "/opt/nodenv" + "/usr/local/opt/nodenv" + ) + for dir in $nodenvdirs; do + if [[ -d "${dir}/bin" ]]; then + export PATH="$PATH:${dir}/bin" + FOUND_NODENV=1 + break + fi + done + + if [[ $FOUND_NODENV -ne 1 ]]; then + if (( $+commands[brew] )) && dir=$(brew --prefix nodenv 2>/dev/null); then + if [[ -d "${dir}/bin" ]]; then + export PATH="$PATH:${dir}/bin" + FOUND_NODENV=1 + fi + fi + fi +fi + +if [[ $FOUND_NODENV -eq 1 ]]; then + eval "$(nodenv init --no-rehash - zsh)" + function nodenv_prompt_info() { + nodenv version-name 2>/dev/null + } +else + # fallback to system node + function nodenv_prompt_info() { + echo "system: $(node -v 2>&1 | cut -c 2-)" + } +fi + +unset FOUND_NODENV nodenvdirs dir From f42c965da44be6940134b805edb54c5eca37d9ae Mon Sep 17 00:00:00 2001 From: ZYX Date: Mon, 27 Feb 2023 14:39:38 -0500 Subject: [PATCH 16/38] fix(aliases): clarify how to pass in keywords to `acs` (#11521) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marc Cornellà --- plugins/aliases/README.md | 2 +- plugins/aliases/cheatsheet.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/aliases/README.md b/plugins/aliases/README.md index 4e77f67b3..6a2da3d74 100644 --- a/plugins/aliases/README.md +++ b/plugins/aliases/README.md @@ -19,7 +19,7 @@ Requirements: Python needs to be installed. - `acs -h/--help`: print help mesage -- `acs `: filter aliases by `` and highlight +- `acs `: filter and highlight aliases by `` - `acs -g /--group `: show only aliases for group ``. Multiple uses of the flag show all groups diff --git a/plugins/aliases/cheatsheet.py b/plugins/aliases/cheatsheet.py index 3362a6ab6..fb8c74aa4 100644 --- a/plugins/aliases/cheatsheet.py +++ b/plugins/aliases/cheatsheet.py @@ -51,18 +51,18 @@ def pretty_print(cheatsheet, wfilter, group_list=None, groups_only=False): continue aliases = cheatsheet.get(key) if not wfilter: - pretty_print_group(key, aliases, wfilter, groups_only) + pretty_print_group(key, aliases, only_groupname=groups_only) else: - pretty_print_group(key, [ alias for alias in aliases if alias[0].find(wfilter)>-1 or alias[1].find(wfilter)>-1], wfilter) + pretty_print_group(key, [ alias for alias in aliases if wfilter in alias[0] or wfilter in alias[1] ], wfilter) if __name__ == '__main__': - parser = argparse.ArgumentParser(description="Pretty print aliases.") - parser.add_argument('filter', nargs="*", help="search aliases matching string") + parser = argparse.ArgumentParser(description="Pretty print aliases.", prog="acs") + parser.add_argument('filter', nargs="*", metavar="", help="search aliases matching keywords") parser.add_argument('-g', '--group', dest="group_list", action='append', help="only print aliases in given groups") parser.add_argument('--groups', dest='groups_only', action='store_true', help="only print alias groups") args = parser.parse_args() lines = sys.stdin.readlines() group_list = args.group_list or None - wfilter = " ".join(args.filter) or None + wfilter = " ".join(args.filter[1:]) if args.filter else None pretty_print(cheatsheet(lines), wfilter, group_list, args.groups_only) From b602e0a066d8c98e8c02201ad16c764447fd8531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Mon, 27 Feb 2023 20:46:42 +0100 Subject: [PATCH 17/38] fix(aliases): fix regression in filter argument --- plugins/aliases/cheatsheet.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/aliases/cheatsheet.py b/plugins/aliases/cheatsheet.py index fb8c74aa4..7505d304b 100644 --- a/plugins/aliases/cheatsheet.py +++ b/plugins/aliases/cheatsheet.py @@ -51,9 +51,9 @@ def pretty_print(cheatsheet, wfilter, group_list=None, groups_only=False): continue aliases = cheatsheet.get(key) if not wfilter: - pretty_print_group(key, aliases, only_groupname=groups_only) + pretty_print_group(key, aliases, wfilter, groups_only) else: - pretty_print_group(key, [ alias for alias in aliases if wfilter in alias[0] or wfilter in alias[1] ], wfilter) + pretty_print_group(key, [ alias for alias in aliases if alias[0].find(wfilter)>-1 or alias[1].find(wfilter)>-1], wfilter) if __name__ == '__main__': parser = argparse.ArgumentParser(description="Pretty print aliases.", prog="acs") @@ -64,5 +64,5 @@ if __name__ == '__main__': lines = sys.stdin.readlines() group_list = args.group_list or None - wfilter = " ".join(args.filter[1:]) if args.filter else None + wfilter = " ".join(args.filter) or None pretty_print(cheatsheet(lines), wfilter, group_list, args.groups_only) From a4a9a8cd8ccb4240a7c5df5f6766bd5340646e63 Mon Sep 17 00:00:00 2001 From: Julian Suarez <49501306+jsred@users.noreply.github.com> Date: Wed, 1 Mar 2023 07:23:32 -0300 Subject: [PATCH 18/38] feat(rvm): add `rb32` alias (#11533) --- plugins/rvm/README.md | 1 + plugins/rvm/rvm.plugin.zsh | 1 + 2 files changed, 2 insertions(+) diff --git a/plugins/rvm/README.md b/plugins/rvm/README.md index 576b037b0..410bd60c0 100644 --- a/plugins/rvm/README.md +++ b/plugins/rvm/README.md @@ -24,6 +24,7 @@ plugins=(... rvm) | `rb27` | `rvm use ruby-2.7` | | `rb30` | `rvm use ruby-3.0` | | `rb31` | `rvm use ruby-3.1` | +| `rb32` | `rvm use ruby-3.2` | | `rvm-update` | `rvm get head` | | `gems` | `gem list` | | `rvms` | `rvm gemset` | diff --git a/plugins/rvm/rvm.plugin.zsh b/plugins/rvm/rvm.plugin.zsh index 2a091d019..3ddf04176 100644 --- a/plugins/rvm/rvm.plugin.zsh +++ b/plugins/rvm/rvm.plugin.zsh @@ -27,6 +27,7 @@ rubies=( 27 'ruby-2.7' 30 'ruby-3.0' 31 'ruby-3.1' + 32 'ruby-3.2' ) for v in ${(k)rubies}; do From 14978859c5b8d9385c9b836cd09c97cc08b6035b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Batuhan=20=C5=9Eanl=C4=B1?= <32306925+batuhan0sanli@users.noreply.github.com> Date: Thu, 2 Mar 2023 12:03:50 +0300 Subject: [PATCH 19/38] docs(brew): remove duplication (#11535) --- plugins/brew/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/brew/README.md b/plugins/brew/README.md index d0c150237..412daae63 100644 --- a/plugins/brew/README.md +++ b/plugins/brew/README.md @@ -21,7 +21,6 @@ defined for convenience. | -------- | --------------------------------------- | ------------------------------------------------------------------- | | `bcubc` | `brew upgrade --cask && brew cleanup` | Update outdated casks, then run cleanup. | | `bcubo` | `brew update && brew outdated --cask` | Update Homebrew data, then list outdated casks. | -| `bcubc` | `brew upgrade --cask && brew cleanup` | Update outdated casks, then run cleanup. | | `brewp` | `brew pin` | Pin a specified formula so that it's not upgraded. | | `brews` | `brew list -1` | List installed formulae or the installed files for a given formula. | | `brewsp` | `brew list --pinned` | List pinned formulae, or show the version of a given formula. | From 5bf7f9c83325a6cb2752e14ca01a574dbeef206e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Fri, 3 Mar 2023 12:34:31 +0100 Subject: [PATCH 20/38] fix(lib): use `$BROWSER` in `open_command` if set (#11532) Fixes #11098 --- lib/functions.zsh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/functions.zsh b/lib/functions.zsh index 6e1faa6aa..1d85ea38a 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -30,6 +30,13 @@ function open_command() { ;; esac + # If a URL is passed, $BROWSER might be set to a local browser within SSH. + # See https://github.com/ohmyzsh/ohmyzsh/issues/11098 + if [[ -n "$BROWSER" && "$1" = (http|https)://* ]]; then + "$BROWSER" "$@" + return + fi + ${=open_cmd} "$@" &>/dev/null } From 95d0c4b603e0c880bcf20bc9211b2162e94ed925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Fri, 3 Mar 2023 14:38:50 +0100 Subject: [PATCH 21/38] refactor(theme-and-appearance): reorganize and clean up logic (#11529) Co-authored-by: Andrew Janke Co-authored-by: Marcelo Parada Co-authored-by: Uy Ha Co-authored-by: Valentin Uveges --- lib/theme-and-appearance.zsh | 147 +++++++++++++++++++++-------------- 1 file changed, 87 insertions(+), 60 deletions(-) diff --git a/lib/theme-and-appearance.zsh b/lib/theme-and-appearance.zsh index 208ab9ce5..985d3bc11 100644 --- a/lib/theme-and-appearance.zsh +++ b/lib/theme-and-appearance.zsh @@ -1,66 +1,93 @@ -# ls colors +# Sets color variable such as $fg, $bg, $color and $reset_color autoload -U colors && colors -# Enable ls colors -export LSCOLORS="Gxfxcxdxbxegedabagacad" - -# TODO organise this chaotic logic - -if [[ "$DISABLE_LS_COLORS" != "true" ]]; then - if [[ -d "$ZSH" ]]; then - _test_dir="$ZSH" - else - _test_dir="." - fi - # Find the option for using colors in ls, depending on the version - if [[ "$OSTYPE" == netbsd* ]]; then - # On NetBSD, test if "gls" (GNU ls) is installed (this one supports colors); - # otherwise, leave ls as is, because NetBSD's ls doesn't support -G - gls --color -d "$_test_dir" &>/dev/null && alias ls='gls --color=tty' - elif [[ "$OSTYPE" == openbsd* ]]; then - # On OpenBSD, "gls" (ls from GNU coreutils) and "colorls" (ls from base, - # with color and multibyte support) are available from ports. "colorls" - # will be installed on purpose and can't be pulled in by installing - # coreutils, so prefer it to "gls". - gls --color -d "$_test_dir" &>/dev/null && alias ls='gls --color=tty' - colorls -G -d "$_test_dir" &>/dev/null && alias ls='colorls -G' - elif [[ "$OSTYPE" == (darwin|freebsd)* ]]; then - # this is a good alias, it works by default just using $LSCOLORS - ls -G "$_test_dir" &>/dev/null && alias ls='ls -G' - - # only use coreutils ls if there is a dircolors customization present ($LS_COLORS or .dircolors file) - # otherwise, gls will use the default color scheme which is ugly af - [[ -n "$LS_COLORS" || -f "$HOME/.dircolors" ]] && gls --color -d "$_test_dir" &>/dev/null && alias ls='gls --color=tty' - else - # For GNU ls, we use the default ls color theme. They can later be overwritten by themes. - if [[ -z "$LS_COLORS" ]]; then - (( $+commands[dircolors] )) && eval "$(dircolors -b)" - fi - - ls --color -d "$_test_dir" &>/dev/null && alias ls='ls --color=tty' || { ls -G "$_test_dir" &>/dev/null && alias ls='ls -G' } - - # Take advantage of $LS_COLORS for completion as well. - zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" - fi -fi - -# enable diff color if possible. -if command diff --color /dev/null /dev/null &>/dev/null; then - function color-diff { - command diff --color $@ - } - alias diff="color-diff" - compdef _diff color-diff # compdef is already loaded by this point -fi - +# Expand variables and commands in PROMPT variables setopt prompt_subst -[[ -n "$WINDOW" ]] && SCREEN_NO="%B$WINDOW%b " || SCREEN_NO="" - -# git theming default: Variables for theming the git info prompt -ZSH_THEME_GIT_PROMPT_PREFIX="git:(" # Prefix at the very beginning of the prompt, before the branch name -ZSH_THEME_GIT_PROMPT_SUFFIX=")" # At the very end of the prompt -ZSH_THEME_GIT_PROMPT_DIRTY="*" # Text to display if the branch is dirty -ZSH_THEME_GIT_PROMPT_CLEAN="" # Text to display if the branch is clean +# Prompt function theming defaults +ZSH_THEME_GIT_PROMPT_PREFIX="git:(" # Beginning of the git prompt, before the branch name +ZSH_THEME_GIT_PROMPT_SUFFIX=")" # End of the git prompt +ZSH_THEME_GIT_PROMPT_DIRTY="*" # Text to display if the branch is dirty +ZSH_THEME_GIT_PROMPT_CLEAN="" # Text to display if the branch is clean ZSH_THEME_RUBY_PROMPT_PREFIX="(" ZSH_THEME_RUBY_PROMPT_SUFFIX=")" + + +# Use diff --color if available +if command diff --color /dev/null{,} &>/dev/null; then + function diff { + command diff --color "$@" + } +fi + + +# Don't set ls coloring if disabled +[[ "$DISABLE_LS_COLORS" != true ]] || return 0 + +function test-ls-args { + local cmd="$1" # ls, gls, colorls, ... + local args="${@[2,-1]}" # arguments except the first one + command "$cmd" "$args" /dev/null &>/dev/null +} + +# Find the option for using colors in ls, depending on the version +case "$OSTYPE" in + netbsd*) + # On NetBSD, test if `gls` (GNU ls) is installed (this one supports colors); + # otherwise, leave ls as is, because NetBSD's ls doesn't support -G + test-ls-args gls --color && alias ls='gls --color=tty' + ;; + openbsd*) + # On OpenBSD, `gls` (ls from GNU coreutils) and `colorls` (ls from base, + # with color and multibyte support) are available from ports. + # `colorls` will be installed on purpose and can't be pulled in by installing + # coreutils (which might be installed for ), so prefer it to `gls`. + test-ls-args gls --color && alias ls='gls --color=tty' + test-ls-args colorls -G && alias ls='colorls -G' + ;; + (darwin|freebsd)*) + # This alias works by default just using $LSCOLORS + test-ls-args ls -G && alias ls='ls -G' + # Only use GNU ls if installed and there are user defaults for $LS_COLORS, + # as the default coloring scheme is not very pretty + [[ -n "$LS_COLORS" || -f "$HOME/.dircolors" ]] \ + && test-ls-args gls --color \ + && alias ls='gls --color=tty' + ;; + *) + if test-ls-args ls --color; then + alias ls='ls --color=tty' + elif test-ls-args ls -G; then + alias ls='ls -G' + fi + ;; +esac + +unfunction test-ls-args + + +# Default coloring for BSD-based ls +export LSCOLORS="Gxfxcxdxbxegedabagacad" + +# Default coloring for GNU-based ls +if [[ -z "$LS_COLORS" ]]; then + # Define LS_COLORS via dircolors if available. Otherwise, set a default + # equivalent to LSCOLORS (generated via https://geoff.greer.fm/lscolors) + if (( $+commands[dircolors] )); then + [[ -f "$HOME/.dircolors" ]] \ + && source <(dircolors -b "$HOME/.dircolors") \ + || source <(dircolors -b) + else + export LS_COLORS="di=34:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=37;41:sg=30;43:tw=30;42:ow=34;42:" + fi +fi + +# Take advantage of $LS_COLORS for completion as well. +function omz_set_completion_colors { + zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" + add-zsh-hook -d precmd omz_set_completion_colors + unfunction omz_set_completion_colors +} + +autoload -Uz add-zsh-hook +add-zsh-hook precmd omz_set_completion_colors From 6f3304f442afde6e1cf3e7e8641a405d29d2e73d Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Sat, 4 Mar 2023 09:25:01 +0100 Subject: [PATCH 22/38] feat(argocd): add completion plugin Co-authored-by: Sumudu Lansakara Closes #9900 --- plugins/argocd/README.md | 20 ++++++++++++++++++++ plugins/argocd/gh.plugin.zsh | 14 ++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 plugins/argocd/README.md create mode 100644 plugins/argocd/gh.plugin.zsh diff --git a/plugins/argocd/README.md b/plugins/argocd/README.md new file mode 100644 index 000000000..0f900ff22 --- /dev/null +++ b/plugins/argocd/README.md @@ -0,0 +1,20 @@ +# Argo CD plugin + +This plugin adds completion for the [Argo CD](https://argoproj.github.io/cd/) CLI. + +To use it, add `argocd` to the plugins array in your zshrc file: + +```zsh +plugins=(... argocd) +``` + +This plugin does not add any aliases. + +## Cache + +This plugin caches the completion script and is automatically updated asynchronously when the plugin is +loaded, which is usually when you start up a new terminal emulator. + +The cache is stored at: + +- `$ZSH_CACHE/completions/_argocd` completions script diff --git a/plugins/argocd/gh.plugin.zsh b/plugins/argocd/gh.plugin.zsh new file mode 100644 index 000000000..8de7b0238 --- /dev/null +++ b/plugins/argocd/gh.plugin.zsh @@ -0,0 +1,14 @@ +# Autocompletion for argocd. +if (( ! $+commands[argocd] )); then + return +fi + +# If the completion file doesn't exist yet, we need to autoload it and +# bind it to `argocd`. Otherwise, compinit will have already done that. +if [[ ! -f "$ZSH_CACHE_DIR/completions/_argocd" ]]; then + typeset -g -A _comps + autoload -Uz _argocd + _comps[argocd]=_argocd +fi + +argocd completion zsh >| "$ZSH_CACHE_DIR/completions/_argocd" &| From 3b759c5dc926d0973d82fa1b8ffed45d770d20e8 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Mon, 6 Mar 2023 11:25:47 +0100 Subject: [PATCH 23/38] fix(argocd): typo in filename --- plugins/argocd/{gh.plugin.zsh => argocd.plugin.zsh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename plugins/argocd/{gh.plugin.zsh => argocd.plugin.zsh} (100%) diff --git a/plugins/argocd/gh.plugin.zsh b/plugins/argocd/argocd.plugin.zsh similarity index 100% rename from plugins/argocd/gh.plugin.zsh rename to plugins/argocd/argocd.plugin.zsh From 06c16175ea4aa81d4b64c0772f44c11e505a0eb7 Mon Sep 17 00:00:00 2001 From: Karim Benbourenane Date: Tue, 7 Mar 2023 03:25:34 -0500 Subject: [PATCH 24/38] fix(aliases): group properly aliases (#11546) --- plugins/aliases/cheatsheet.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/aliases/cheatsheet.py b/plugins/aliases/cheatsheet.py index 7505d304b..f742fba9e 100644 --- a/plugins/aliases/cheatsheet.py +++ b/plugins/aliases/cheatsheet.py @@ -15,6 +15,7 @@ def parse(line): def cheatsheet(lines): exps = [ parse(line) for line in lines ] + exps.sort(key=lambda exp:exp[2]) cheatsheet = {'_default': []} for key, group in itertools.groupby(exps, lambda exp:exp[2]): group_list = [ item for item in group ] From 46fd7972a2170388c9b8e9f6e58d6c8408ad4904 Mon Sep 17 00:00:00 2001 From: potato <851951875@qq.com> Date: Tue, 7 Mar 2023 20:33:16 +0800 Subject: [PATCH 25/38] feat(aws): add AWS_REGION to aws_prompt_info (#10062) --- plugins/aws/README.md | 22 +++++++++++++++----- plugins/aws/aws.plugin.zsh | 41 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/plugins/aws/README.md b/plugins/aws/README.md index d6f4f4600..e1e355741 100644 --- a/plugins/aws/README.md +++ b/plugins/aws/README.md @@ -1,7 +1,7 @@ # aws This plugin provides completion support for [awscli](https://docs.aws.amazon.com/cli/latest/reference/index.html) -and a few utilities to manage AWS profiles and display them in the prompt. +and a few utilities to manage AWS profiles/regions and display them in the prompt. To use it, add `aws` to the plugins array in your zshrc file. @@ -16,6 +16,9 @@ plugins=(... aws) Run `asp` without arguments to clear the profile. * `asp [] login`: If AWS SSO has been configured in your aws profile, it will run the `aws sso login` command following profile selection. +* `asr []`: sets `$AWS_REGION` and `$AWS_DEFAULT_REGION` (legacy) to ``. + Run `asr` without arguments to clear the profile. + * `acp [] []`: in addition to `asp` functionality, it actually changes the profile by assuming the role specified in the `` configuration. It supports MFA and sets `$AWS_ACCESS_KEY_ID`, `$AWS_SECRET_ACCESS_KEY` and `$AWS_SESSION_TOKEN`, if @@ -25,25 +28,34 @@ plugins=(... aws) * `agp`: gets the current value of `$AWS_PROFILE`. +* `agr`: gets the current value of `$AWS_REGION`. + * `aws_change_access_key`: changes the AWS access key of a profile. * `aws_profiles`: lists the available profiles in the `$AWS_CONFIG_FILE` (default: `~/.aws/config`). Used to provide completion for the `asp` function. +* `aws_regions`: lists the available regions. + Used to provide completion for the `asr` function. + ## Plugin options * Set `SHOW_AWS_PROMPT=false` in your zshrc file if you want to prevent the plugin from modifying your RPROMPT. Some themes might overwrite the value of RPROMPT instead of appending to it, so they'll need to be fixed to - see the AWS profile prompt. + see the AWS profile/region prompt. ## Theme The plugin creates an `aws_prompt_info` function that you can use in your theme, which displays -the current `$AWS_PROFILE`. It uses two variables to control how that is shown: +the current `$AWS_PROFILE` and `$AWS_REGION`. It uses four variables to control how that is shown: -* ZSH_THEME_AWS_PREFIX: sets the prefix of the AWS_PROFILE. Defaults to ``. +* ZSH_THEME_AWS_PROFILE_SUFFIX: sets the suffix of the AWS_PROFILE. Defaults to `>`. + +* ZSH_THEME_AWS_REGION_PREFIX: sets the prefix of the AWS_REGION. Defaults to ``. ## Configuration diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh index 865e82f19..1c386a3e1 100644 --- a/plugins/aws/aws.plugin.zsh +++ b/plugins/aws/aws.plugin.zsh @@ -2,6 +2,10 @@ function agp() { echo $AWS_PROFILE } +function agr() { + echo $AWS_REGION +} + # AWS profile selection function asp() { if [[ -z "$1" ]]; then @@ -27,6 +31,25 @@ function asp() { fi } +# AWS region selection +function asr() { + if [[ -z "$1" ]]; then + unset AWS_DEFAULT_REGION AWS_REGION + echo AWS region cleared. + return + fi + + local -a available_regions + available_regions=($(aws_regions)) + if [[ -z "${available_regions[(r)$1]}" ]]; then + echo "${fg[red]}Available regions: \n$(aws_regions)" + return 1 + fi + + export AWS_REGION=$1 + export AWS_DEFAULT_REGION=$1 +} + # AWS profile switch function acp() { if [[ -z "$1" ]]; then @@ -145,12 +168,25 @@ function aws_change_access_key() { AWS_PAGER="" aws iam list-access-keys } +function aws_regions() { + if [[ $AWS_DEFAULT_PROFILE || $AWS_PROFILE ]];then + aws ec2 describe-regions |grep RegionName | awk -F ':' '{gsub(/"/, "", $2);gsub(/,/, "", $2);gsub(/ /, "", $2); print $2}' + else + echo "You must specify a AWS profile." + fi +} + function aws_profiles() { aws --no-cli-pager configure list-profiles 2> /dev/null && return [[ -r "${AWS_CONFIG_FILE:-$HOME/.aws/config}" ]] || return 1 grep --color=never -Eo '\[.*\]' "${AWS_CONFIG_FILE:-$HOME/.aws/config}" | sed -E 's/^[[:space:]]*\[(profile)?[[:space:]]*([^[:space:]]+)\][[:space:]]*$/\2/g' } +function _aws_regions() { + reply=($(aws_regions)) +} +compctl -K _aws_regions asr + function _aws_profiles() { reply=($(aws_profiles)) } @@ -158,8 +194,8 @@ compctl -K _aws_profiles asp acp aws_change_access_key # AWS prompt function aws_prompt_info() { - [[ -n "$AWS_PROFILE" ]] || return - echo "${ZSH_THEME_AWS_PREFIX=}" + if [[ -z $AWS_REGION && -z $AWS_PROFILE ]];then return; fi + echo "${ZSH_THEME_AWS_PROFILE_PREFIX:=} ${ZSH_THEME_AWS_REGION_PREFIX:=}" } if [[ "$SHOW_AWS_PROMPT" != false && "$RPROMPT" != *'$(aws_prompt_info)'* ]]; then @@ -211,3 +247,4 @@ else [[ -r $_aws_zsh_completer_path ]] && source $_aws_zsh_completer_path unset _aws_zsh_completer_path _brew_prefix fi + From d342b353e32091ef7384b86fd86b1a88dbd44609 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 7 Mar 2023 18:49:17 +0100 Subject: [PATCH 26/38] fix(init): set completion colors on theme load, not with `precmd` This fixes an edge case where the user actually sets zstyle ':completion:*' list-colors in their zshrc, but the previous code used a precmd hook, which would override the user changes. With this change our modifications will be set in the init script, after the theme loads, so that later changes can affect our defaults. Note that this will not be run for users on plugin managers, as these don't generally run our init script. --- lib/theme-and-appearance.zsh | 10 ---------- oh-my-zsh.sh | 3 +++ 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/theme-and-appearance.zsh b/lib/theme-and-appearance.zsh index 985d3bc11..e245570e3 100644 --- a/lib/theme-and-appearance.zsh +++ b/lib/theme-and-appearance.zsh @@ -81,13 +81,3 @@ if [[ -z "$LS_COLORS" ]]; then export LS_COLORS="di=34:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=37;41:sg=30;43:tw=30;42:ow=34;42:" fi fi - -# Take advantage of $LS_COLORS for completion as well. -function omz_set_completion_colors { - zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" - add-zsh-hook -d precmd omz_set_completion_colors - unfunction omz_set_completion_colors -} - -autoload -Uz add-zsh-hook -add-zsh-hook precmd omz_set_completion_colors diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index 98bda8c8b..363cfca8b 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -189,3 +189,6 @@ if [[ -n "$ZSH_THEME" ]]; then echo "[oh-my-zsh] theme '$ZSH_THEME' not found" fi fi + +# set completion colors to be the same as `ls`, after theme has been loaded +[[ -z "$LS_COLORS" ]] || zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" From e0f92c8df52335c266f73e3cc3384b277f3e9a34 Mon Sep 17 00:00:00 2001 From: Julien Vincent Date: Tue, 7 Mar 2023 21:46:21 +0200 Subject: [PATCH 27/38] feat(vi-mode): add settings for vi-mode cursor styles (#10860) --- plugins/vi-mode/README.md | 21 +++++++++++++++++++++ plugins/vi-mode/vi-mode.plugin.zsh | 23 ++++++++++++++++------- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/plugins/vi-mode/README.md b/plugins/vi-mode/README.md index 476666bf6..3b819c7cb 100644 --- a/plugins/vi-mode/README.md +++ b/plugins/vi-mode/README.md @@ -29,6 +29,8 @@ plugins=(... vi-mode) VI_MODE_SET_CURSOR=true ``` + See [Cursor Styles](#cursor-styles) for controlling how the cursor looks in different modes + - `MODE_INDICATOR`: controls the string displayed when the shell is in normal mode. See [Mode indicators](#mode-indicators) for details. @@ -52,6 +54,25 @@ INSERT_MODE_INDICATOR="%F{yellow}+%f" You can also use the `vi_mode_prompt_info` function in your prompt, which will display this mode indicator. +## Cursor Styles + +You can control the cursor style used in each active vim mode by changing the values of the following variables. + +```zsh +# defaults +VI_MODE_CURSOR_NORMAL=2 +VI_MODE_CURSOR_VISUAL=6 +VI_MODE_CURSOR_INSERT=6 +VI_MODE_CURSOR_OPPEND=0 +``` + +- 0, 1 - Blinking block +- 2 - Solid block +- 3 - Blinking underline +- 4 - Solid underline +- 5 - Blinking line +- 6 - Solid line + ## Key bindings Use `ESC` or `CTRL-[` to enter `Normal mode`. diff --git a/plugins/vi-mode/vi-mode.plugin.zsh b/plugins/vi-mode/vi-mode.plugin.zsh index 149d6bbd5..9a410c1fb 100644 --- a/plugins/vi-mode/vi-mode.plugin.zsh +++ b/plugins/vi-mode/vi-mode.plugin.zsh @@ -14,6 +14,15 @@ typeset -g VI_MODE_RESET_PROMPT_ON_MODE_CHANGE # Unset or set to any other value to do the opposite. typeset -g VI_MODE_SET_CURSOR +# Control how the cursor appears in the various vim modes. This only applies +# if $VI_MODE_SET_CURSOR=true. +# +# See https://vt100.net/docs/vt510-rm/DECSCUSR for cursor styles +typeset -g VI_MODE_CURSOR_NORMAL=2 +typeset -g VI_MODE_CURSOR_VISUAL=6 +typeset -g VI_MODE_CURSOR_INSERT=6 +typeset -g VI_MODE_CURSOR_OPPEND=0 + typeset -g VI_KEYMAP=main function _vi-mode-set-cursor-shape-for-keymap() { @@ -22,13 +31,13 @@ function _vi-mode-set-cursor-shape-for-keymap() { # https://vt100.net/docs/vt510-rm/DECSCUSR local _shape=0 case "${1:-${VI_KEYMAP:-main}}" in - main) _shape=6 ;; # vi insert: line - viins) _shape=6 ;; # vi insert: line - isearch) _shape=6 ;; # inc search: line - command) _shape=6 ;; # read a command name - vicmd) _shape=2 ;; # vi cmd: block - visual) _shape=2 ;; # vi visual mode: block - viopp) _shape=0 ;; # vi operation pending: blinking block + main) _shape=$VI_MODE_CURSOR_INSERT ;; # vi insert: line + viins) _shape=$VI_MODE_CURSOR_INSERT ;; # vi insert: line + isearch) _shape=$VI_MODE_CURSOR_INSERT ;; # inc search: line + command) _shape=$VI_MODE_CURSOR_INSERT ;; # read a command name + vicmd) _shape=$VI_MODE_CURSOR_NORMAL ;; # vi cmd: block + visual) _shape=$VI_MODE_CURSOR_VISUAL ;; # vi visual mode: block + viopp) _shape=$VI_MODE_CURSOR_OPPEND ;; # vi operation pending: blinking block *) _shape=0 ;; esac printf $'\e[%d q' "${_shape}" From 1c325de464117aa058d5f810b96ed54d65e5d0d5 Mon Sep 17 00:00:00 2001 From: Robby Russell Date: Tue, 7 Mar 2023 11:52:38 -0800 Subject: [PATCH 28/38] Fixing link to PA website in README Was linking to an old URL --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7f4a26cab..4042c8c26 100644 --- a/README.md +++ b/README.md @@ -374,4 +374,4 @@ Oh My Zsh is released under the [MIT license](LICENSE.txt). ![Planet Argon](https://pa-github-assets.s3.amazonaws.com/PARGON_logo_digital_COL-small.jpg) -Oh My Zsh was started by the team at [Planet Argon](https://www.planetargon.com/?utm_source=github), a [Ruby on Rails development agency](https://www.planetargon.com/skills/ruby-on-rails-development?utm_source=github). Check out our [other open source projects](https://www.planetargon.com/open-source?utm_source=github). +Oh My Zsh was started by the team at [Planet Argon](https://www.planetargon.com/?utm_source=github), a [Ruby on Rails development agency](http://www.planetargon.com/services/ruby-on-rails-development?utm_source=github). Check out our [other open source projects](https://www.planetargon.com/open-source?utm_source=github). From 3ea0e0d2343a2e79be0c2c6ace030a595d5cec2f Mon Sep 17 00:00:00 2001 From: Benjamin Lieb Date: Wed, 8 Mar 2023 03:29:21 -0500 Subject: [PATCH 29/38] docs(vi-mode): document how to add vi-mode info on the prompt (#11548) --- plugins/vi-mode/README.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/plugins/vi-mode/README.md b/plugins/vi-mode/README.md index 3b819c7cb..0cb516751 100644 --- a/plugins/vi-mode/README.md +++ b/plugins/vi-mode/README.md @@ -51,8 +51,23 @@ MODE_INDICATOR="%F{white}+%f" INSERT_MODE_INDICATOR="%F{yellow}+%f" ``` -You can also use the `vi_mode_prompt_info` function in your prompt, which will display -this mode indicator. +### Adding mode indicators to your prompt + +`Vi-mode` by default will add mode indicators to `RPROMPT` **unless** that is defined by +a preceding plugin. + +If `PROMPT` or `RPROMPT` is not defined to your liking, you can add mode info manually. The `vi_mode_prompt_info` function is available to insert mode indicator information. + +Here are some examples: + +```bash +source $ZSH/oh-my-zsh.sh + +PROMPT="$PROMPT\$(vi_mode_prompt_info)" +RPROMPT="\$(vi_mode_prompt_info)$RPROMPT" +``` + +Note the `\$` here, which importantly prevents interpolation at the time of defining, but allows it to be executed for each prompt update event. ## Cursor Styles From 92387d9fff83934a8628697a4397a65030f0301e Mon Sep 17 00:00:00 2001 From: Zhong Zheng Date: Sat, 11 Mar 2023 01:52:44 +1100 Subject: [PATCH 30/38] feat(rails): add `rta` alias (#11553) --- plugins/rails/README.md | 1 + plugins/rails/rails.plugin.zsh | 1 + 2 files changed, 2 insertions(+) diff --git a/plugins/rails/README.md b/plugins/rails/README.md index fa66750f0..b2425aabc 100644 --- a/plugins/rails/README.md +++ b/plugins/rails/README.md @@ -47,6 +47,7 @@ plugins=(... rails) | `rsp` | `rails server --port` | Launch a web server and specify the listening port | | `rsts` | `rails stats` | Print code statistics | | `rt` | `rails test` | Run Rails tests | +| `rta` | `rails test:all` | Runs all Rails tests, including system tests | | `ru` | `rails runner` | Run Ruby code in the context of Rails | ### Foreman diff --git a/plugins/rails/rails.plugin.zsh b/plugins/rails/rails.plugin.zsh index b11cbb5c7..015dc9ecb 100644 --- a/plugins/rails/rails.plugin.zsh +++ b/plugins/rails/rails.plugin.zsh @@ -75,6 +75,7 @@ alias rsd='rails server --debugger' alias rsp='rails server --port' alias rsts='rails stats' alias rt='rails test' +alias rta='rails test:all' alias ru='rails runner' # Foreman aliases From 72732a224e886933df6b64a49ec6f5e94c884612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Sun, 12 Mar 2023 15:47:58 +0100 Subject: [PATCH 31/38] fix(lib): set equivalent LS_COLORS and LSCOLORS variables As reported by https://geoff.greer.fm/lscolors Fixes #11554 --- lib/theme-and-appearance.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/theme-and-appearance.zsh b/lib/theme-and-appearance.zsh index e245570e3..d8859b04c 100644 --- a/lib/theme-and-appearance.zsh +++ b/lib/theme-and-appearance.zsh @@ -78,6 +78,6 @@ if [[ -z "$LS_COLORS" ]]; then && source <(dircolors -b "$HOME/.dircolors") \ || source <(dircolors -b) else - export LS_COLORS="di=34:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=37;41:sg=30;43:tw=30;42:ow=34;42:" + export LS_COLORS="di=1;36:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43" fi fi From 82d261603d968dfe5e86a44464c38fd88dda802c Mon Sep 17 00:00:00 2001 From: vladislav doster <10052309+vladdoster@users.noreply.github.com> Date: Mon, 20 Mar 2023 02:11:03 -0500 Subject: [PATCH 32/38] feat(gnu-utils): add `gindent` (#11569) --- plugins/gnu-utils/gnu-utils.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/gnu-utils/gnu-utils.plugin.zsh b/plugins/gnu-utils/gnu-utils.plugin.zsh index 6bd3e8463..6023bf2b4 100644 --- a/plugins/gnu-utils/gnu-utils.plugin.zsh +++ b/plugins/gnu-utils/gnu-utils.plugin.zsh @@ -19,7 +19,7 @@ __gnu_utils() { 'gchown' 'gchroot' 'gcksum' 'gcomm' 'gcp' 'gcsplit' 'gcut' 'gdate' 'gdd' 'gdf' 'gdir' 'gdircolors' 'gdirname' 'gdu' 'gecho' 'genv' 'gexpand' 'gexpr' 'gfactor' 'gfalse' 'gfmt' 'gfold' 'ggroups' 'ghead' 'ghostid' - 'gid' 'ginstall' 'gjoin' 'gkill' 'glink' 'gln' 'glogname' 'gls' 'gmd5sum' + 'gid' 'gindent' 'ginstall' 'gjoin' 'gkill' 'glink' 'gln' 'glogname' 'gls' 'gmd5sum' 'gmkdir' 'gmkfifo' 'gmknod' 'gmktemp' 'gmv' 'gnice' 'gnl' 'gnohup' 'gnproc' 'god' 'gpaste' 'gpathchk' 'gpinky' 'gpr' 'gprintenv' 'gprintf' 'gptx' 'gpwd' 'greadlink' 'grm' 'grmdir' 'gruncon' 'gseq' 'gsha1sum' 'gsha224sum' From 4a39779067eda369152bfd6b653f843286c930c0 Mon Sep 17 00:00:00 2001 From: Yu Xiang Zhang Date: Tue, 14 Mar 2023 19:02:54 +0000 Subject: [PATCH 33/38] feat(aws): set region when AWS_REGION is not set --- plugins/aws/README.md | 2 +- plugins/aws/aws.plugin.zsh | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/aws/README.md b/plugins/aws/README.md index e1e355741..846bf1414 100644 --- a/plugins/aws/README.md +++ b/plugins/aws/README.md @@ -12,7 +12,7 @@ plugins=(... aws) ## Plugin commands * `asp []`: sets `$AWS_PROFILE` and `$AWS_DEFAULT_PROFILE` (legacy) to ``. - It also sets `$AWS_EB_PROFILE` to `` for the Elastic Beanstalk CLI. + It also sets `$AWS_EB_PROFILE` to `` for the Elastic Beanstalk CLI. It sets `$AWS_PROFILE_REGION` for display in `aws_prompt_info`. Run `asp` without arguments to clear the profile. * `asp [] login`: If AWS SSO has been configured in your aws profile, it will run the `aws sso login` command following profile selection. diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh index 1c386a3e1..39c47d572 100644 --- a/plugins/aws/aws.plugin.zsh +++ b/plugins/aws/aws.plugin.zsh @@ -9,7 +9,7 @@ function agr() { # AWS profile selection function asp() { if [[ -z "$1" ]]; then - unset AWS_DEFAULT_PROFILE AWS_PROFILE AWS_EB_PROFILE + unset AWS_DEFAULT_PROFILE AWS_PROFILE AWS_EB_PROFILE AWS_PROFILE_REGION echo AWS profile cleared. return fi @@ -26,6 +26,8 @@ function asp() { export AWS_PROFILE=$1 export AWS_EB_PROFILE=$1 + export AWS_PROFILE_REGION=$(aws configure get region) + if [[ "$2" == "login" ]]; then aws sso login fi @@ -195,7 +197,8 @@ compctl -K _aws_profiles asp acp aws_change_access_key # AWS prompt function aws_prompt_info() { if [[ -z $AWS_REGION && -z $AWS_PROFILE ]];then return; fi - echo "${ZSH_THEME_AWS_PROFILE_PREFIX:=} ${ZSH_THEME_AWS_REGION_PREFIX:=}" + region=${AWS_REGION:-${AWS_DEFAULT_REGION:-$AWS_PROFILE_REGION}} + echo "${ZSH_THEME_AWS_PROFILE_PREFIX:=} ${ZSH_THEME_AWS_REGION_PREFIX:=}" } if [[ "$SHOW_AWS_PROMPT" != false && "$RPROMPT" != *'$(aws_prompt_info)'* ]]; then From f9f01e48a890ad4359a6973d1b8a7039f57b2d08 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Tue, 21 Mar 2023 15:29:48 +0100 Subject: [PATCH 34/38] fix(aws): do not print region if it's not defined Closes #11568 Closes #11570 --- plugins/aws/aws.plugin.zsh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh index 39c47d572..0242be97e 100644 --- a/plugins/aws/aws.plugin.zsh +++ b/plugins/aws/aws.plugin.zsh @@ -196,9 +196,15 @@ compctl -K _aws_profiles asp acp aws_change_access_key # AWS prompt function aws_prompt_info() { - if [[ -z $AWS_REGION && -z $AWS_PROFILE ]];then return; fi - region=${AWS_REGION:-${AWS_DEFAULT_REGION:-$AWS_PROFILE_REGION}} - echo "${ZSH_THEME_AWS_PROFILE_PREFIX:=} ${ZSH_THEME_AWS_REGION_PREFIX:=}" + local _aws_to_show + if [[ -n $AWS_PROFILE ]];then + _aws_to_show+="${ZSH_THEME_AWS_PROFILE_PREFIX:=}" + fi + if [[ -n $AWS_REGION ]]; then + [[ -n $AWS_PROFILE ]] && _aws_to_show+=" " + _aws_to_show+="${ZSH_THEME_AWS_REGION_PREFIX:=}" + fi + echo "$_aws_to_show" } if [[ "$SHOW_AWS_PROMPT" != false && "$RPROMPT" != *'$(aws_prompt_info)'* ]]; then From 5efcfc39735c818a9778172356f82ec0eb3e5916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20C=2E=20Mass=C3=B3n?= <939888+Abuelodelanada@users.noreply.github.com> Date: Thu, 23 Mar 2023 05:42:20 -0300 Subject: [PATCH 35/38] feat(juju): add functions to get current controller and model (#11572) --- plugins/juju/README.md | 2 ++ plugins/juju/juju.plugin.zsh | 32 +++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/plugins/juju/README.md b/plugins/juju/README.md index f0c65309c..6ee333f50 100644 --- a/plugins/juju/README.md +++ b/plugins/juju/README.md @@ -126,5 +126,7 @@ Naming convention: - `jaddr [unit_num]`: display app or unit IP address. - `jreld `: display app and unit relation data. - `jclean`: destroy all controllers +- `jcontroller`: display the controller your are connected to. +- `jmodel`: display the model your are connected to. - `wjst [interval_secs] [args_for_watch]`: watch juju status, with optional interval (default: 5s); you may pass additional arguments to `watch`. diff --git a/plugins/juju/juju.plugin.zsh b/plugins/juju/juju.plugin.zsh index be8a2c7ae..0c60e35ce 100644 --- a/plugins/juju/juju.plugin.zsh +++ b/plugins/juju/juju.plugin.zsh @@ -163,10 +163,40 @@ jreld() { juju run "relation-get -r $relid - $2" --unit $2/$3 } +# Return Juju current controller +jcontroller() { + local controller="$(awk '/current-controller/ {print $2}' ~/.local/share/juju/controllers.yaml)" + if [[ -z "$controller" ]]; then + return 1 + fi + + echo $controller + return 0 +} + +# Return Juju current model +jmodel() { + local yqbin="$(whereis yq | awk '{print $2}')" + + if [[ -z "$yqbin" ]]; then + echo "--" + return 1 + fi + + local model="$(yq e ".controllers.$(jcontroller).current-model" < ~/.local/share/juju/models.yaml | cut -d/ -f2)" + + if [[ -z "$model" ]]; then + echo "--" + return 1 + fi + + echo $model + return 0 +} + # Watch juju status, with optional interval (default: 5 sec) wjst() { local interval="${1:-5}" shift $(( $# > 0 )) watch -n "$interval" --color juju status --relations --color "$@" } - From c08b925d282e35ea7bd9a8f4c29de2ece0debb49 Mon Sep 17 00:00:00 2001 From: Michele Bologna Date: Thu, 23 Mar 2023 14:34:43 +0100 Subject: [PATCH 36/38] fix(uninstall): abort uninstall if unable to change shell (#10357) --- tools/uninstall.sh | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/tools/uninstall.sh b/tools/uninstall.sh index 6a0e7b4c7..6e3df7aca 100644 --- a/tools/uninstall.sh +++ b/tools/uninstall.sh @@ -1,3 +1,15 @@ +if hash chsh >/dev/null 2>&1 && [ -f ~/.shell.pre-oh-my-zsh ]; then + old_shell=$(cat ~/.shell.pre-oh-my-zsh) + echo "Switching your shell back to '$old_shell':" + if chsh -s "$old_shell"; then + rm -f ~/.shell.pre-oh-my-zsh + else + echo "Could not change default shell. Change it manually by running chsh" + echo "or editing the /etc/passwd file." + exit + fi +fi + read -r -p "Are you sure you want to remove Oh My Zsh? [y/N] " confirmation if [ "$confirmation" != y ] && [ "$confirmation" != Y ]; then echo "Uninstall cancelled" @@ -25,16 +37,5 @@ else echo "No original zsh config found" fi -if hash chsh >/dev/null 2>&1 && [ -f ~/.shell.pre-oh-my-zsh ]; then - old_shell=$(cat ~/.shell.pre-oh-my-zsh) - echo "Switching your shell back to '$old_shell':" - if chsh -s "$old_shell"; then - rm -f ~/.shell.pre-oh-my-zsh - else - echo "Could not change default shell. Change it manually by running chsh" - echo "or editing the /etc/passwd file." - fi -fi - echo "Thanks for trying out Oh My Zsh. It's been uninstalled." echo "Don't forget to restart your terminal!" From 8f6fbe238969ecb22fbdae75450a9f8705c9f979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Bartnes?= Date: Tue, 28 Mar 2023 12:50:05 +0200 Subject: [PATCH 37/38] feat(upgrade): add verbosity settings Co-authored-by: Carlo Sala Closes #11574 Closes #11579 --- README.md | 12 +++++++++ lib/cli.zsh | 5 ++-- tools/check_for_upgrade.sh | 3 ++- tools/upgrade.sh | 53 ++++++++++++++++++++++++++++---------- 4 files changed, 56 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 4042c8c26..4f0aeb7b4 100644 --- a/README.md +++ b/README.md @@ -317,6 +317,18 @@ zstyle ':omz:update' frequency 7 zstyle ':omz:update' frequency 0 ``` +### Updates verbosity + +You can also limit the update verbosity with the following settings: + +```sh +zstyle ':omz:update' verbose default # default update prompt + +zstyle ':omz:update' verbose minimal # only few lines + +zstyle ':omz:update' verbose silent # only errors +``` + ### Manual Updates If you'd like to update at any point in time (maybe someone just released a new plugin and you don't want to wait a week?) you just need to run: diff --git a/lib/cli.zsh b/lib/cli.zsh index fed00d21d..ba3e39eb5 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -776,10 +776,11 @@ function _omz::update { local last_commit=$(builtin cd -q "$ZSH"; git rev-parse HEAD) # Run update script + zstyle -s ':omz:update' verbose verbose_mode || verbose_mode=default if [[ "$1" != --unattended ]]; then - ZSH="$ZSH" command zsh -f "$ZSH/tools/upgrade.sh" --interactive || return $? + ZSH="$ZSH" command zsh -f "$ZSH/tools/upgrade.sh" -i -v $verbose_mode || return $? else - ZSH="$ZSH" command zsh -f "$ZSH/tools/upgrade.sh" || return $? + ZSH="$ZSH" command zsh -f "$ZSH/tools/upgrade.sh" -v $verbose_mode || return $? fi # Update last updated file diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh index 734714c94..81c371b3f 100644 --- a/tools/check_for_upgrade.sh +++ b/tools/check_for_upgrade.sh @@ -95,7 +95,8 @@ function update_last_updated_file() { } function update_ohmyzsh() { - if ZSH="$ZSH" zsh -f "$ZSH/tools/upgrade.sh" --interactive; then + zstyle -s ':omz:update' verbose verbose_mode || verbose_mode=default + if ZSH="$ZSH" zsh -f "$ZSH/tools/upgrade.sh" -i -v $verbose_mode; then update_last_updated_file fi } diff --git a/tools/upgrade.sh b/tools/upgrade.sh index 596a59302..684ad894a 100755 --- a/tools/upgrade.sh +++ b/tools/upgrade.sh @@ -12,6 +12,23 @@ esac cd "$ZSH" +verbose_mode="default" +interactive=false + +while getopts "v:i" opt; do + case $opt in + v) + if [[ $OPTARG == default || $OPTARG == minimal || $OPTARG == silent ]]; then + verbose_mode=$OPTARG + else + echo "[oh-my-zsh] update verbosity '$OPTARG' is not valid" + echo "[oh-my-zsh] valid options are 'default', 'minimal' and 'silent'" + fi + ;; + i) interactive=true ;; + esac +done + # Use colors, but only if connected to a terminal # and that terminal supports them. @@ -203,7 +220,9 @@ git checkout -q "$branch" -- || exit 1 last_commit=$(git rev-parse "$branch") # Update Oh My Zsh -printf "${BLUE}%s${RESET}\n" "Updating Oh My Zsh" +if [[ $verbose_mode != silent ]]; then + printf "${BLUE}%s${RESET}\n" "Updating Oh My Zsh" +fi if LANG= git pull --quiet --rebase $remote $branch; then # Check if it was really updated or not if [[ "$(git rev-parse HEAD)" = "$last_commit" ]]; then @@ -215,24 +234,30 @@ if LANG= git pull --quiet --rebase $remote $branch; then git config oh-my-zsh.lastVersion "$last_commit" # Print changelog to the terminal - if [[ "$1" = --interactive ]]; then + if [[ interactive == true && $verbose_mode == default ]] ; then "$ZSH/tools/changelog.sh" HEAD "$last_commit" fi - printf "${BLUE}%s \`${BOLD}%s${RESET}${BLUE}\`${RESET}\n" "You can see the changelog with" "omz changelog" + if [[ $verbose_mode != silent ]]; then + printf "${BLUE}%s \`${BOLD}%s${RESET}${BLUE}\`${RESET}\n" "You can see the changelog with" "omz changelog" + fi fi - printf '%s %s__ %s %s %s %s %s__ %s\n' $RAINBOW $RESET - printf '%s ____ %s/ /_ %s ____ ___ %s__ __ %s ____ %s_____%s/ /_ %s\n' $RAINBOW $RESET - printf '%s / __ \\%s/ __ \\ %s / __ `__ \\%s/ / / / %s /_ / %s/ ___/%s __ \\ %s\n' $RAINBOW $RESET - printf '%s/ /_/ /%s / / / %s / / / / / /%s /_/ / %s / /_%s(__ )%s / / / %s\n' $RAINBOW $RESET - printf '%s\\____/%s_/ /_/ %s /_/ /_/ /_/%s\\__, / %s /___/%s____/%s_/ /_/ %s\n' $RAINBOW $RESET - printf '%s %s %s %s /____/ %s %s %s %s\n' $RAINBOW $RESET - printf '\n' - printf "${BLUE}%s${RESET}\n\n" "$message" - printf "${BLUE}${BOLD}%s %s${RESET}\n" "To keep up with the latest news and updates, follow us on Twitter:" "$(fmt_link @ohmyzsh https://twitter.com/ohmyzsh)" - printf "${BLUE}${BOLD}%s %s${RESET}\n" "Want to get involved in the community? Join our Discord:" "$(fmt_link "Discord server" https://discord.gg/ohmyzsh)" - printf "${BLUE}${BOLD}%s %s${RESET}\n" "Get your Oh My Zsh swag at:" "$(fmt_link "Planet Argon Shop" https://shop.planetargon.com/collections/oh-my-zsh)" + if [[ $verbose_mode == default ]]; then + printf '%s %s__ %s %s %s %s %s__ %s\n' $RAINBOW $RESET + printf '%s ____ %s/ /_ %s ____ ___ %s__ __ %s ____ %s_____%s/ /_ %s\n' $RAINBOW $RESET + printf '%s / __ \\%s/ __ \\ %s / __ `__ \\%s/ / / / %s /_ / %s/ ___/%s __ \\ %s\n' $RAINBOW $RESET + printf '%s/ /_/ /%s / / / %s / / / / / /%s /_/ / %s / /_%s(__ )%s / / / %s\n' $RAINBOW $RESET + printf '%s\\____/%s_/ /_/ %s /_/ /_/ /_/%s\\__, / %s /___/%s____/%s_/ /_/ %s\n' $RAINBOW $RESET + printf '%s %s %s %s /____/ %s %s %s %s\n' $RAINBOW $RESET + printf '\n' + printf "${BLUE}%s${RESET}\n\n" "$message" + printf "${BLUE}${BOLD}%s %s${RESET}\n" "To keep up with the latest news and updates, follow us on Twitter:" "$(fmt_link @ohmyzsh https://twitter.com/ohmyzsh)" + printf "${BLUE}${BOLD}%s %s${RESET}\n" "Want to get involved in the community? Join our Discord:" "$(fmt_link "Discord server" https://discord.gg/ohmyzsh)" + printf "${BLUE}${BOLD}%s %s${RESET}\n" "Get your Oh My Zsh swag at:" "$(fmt_link "Planet Argon Shop" https://shop.planetargon.com/collections/oh-my-zsh)" + elif [[ $verbose_mode == minimal ]]; then + printf "${BLUE}%s${RESET}\n" "$message" + fi else ret=$? printf "${RED}%s${RESET}\n" 'There was an error updating. Try again later?' From fcbdc330ff50617c8b84d39ce069cc75df41108f Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Tue, 28 Mar 2023 16:55:53 +0200 Subject: [PATCH 38/38] fix(aws): restore accidentally deleted variable Closes #11589 --- plugins/aws/aws.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh index 0242be97e..a379eaa18 100644 --- a/plugins/aws/aws.plugin.zsh +++ b/plugins/aws/aws.plugin.zsh @@ -197,6 +197,7 @@ compctl -K _aws_profiles asp acp aws_change_access_key # AWS prompt function aws_prompt_info() { local _aws_to_show + local region="${AWS_REGION:-${AWS_DEFAULT_REGION:-$AWS_PROFILE_REGION}}" if [[ -n $AWS_PROFILE ]];then _aws_to_show+="${ZSH_THEME_AWS_PROFILE_PREFIX:=}" fi @@ -211,7 +212,6 @@ if [[ "$SHOW_AWS_PROMPT" != false && "$RPROMPT" != *'$(aws_prompt_info)'* ]]; th RPROMPT='$(aws_prompt_info)'"$RPROMPT" fi - # Load awscli completions # AWS CLI v2 comes with its own autocompletion. Check if that is there, otherwise fall back