diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 0c5f3acee..361ed624b 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,13 +1,14 @@ # Plugin owners plugins/archlinux/ @ratijas +plugins/dbt/ @msempere +plugins/eza/ @pepoluan plugins/genpass/ @atoponce plugins/git-lfs/ @hellovietduc plugins/gitfast/ @felipec plugins/react-native @esthor plugins/sdk/ @rgoldberg plugins/shell-proxy/ @septs +plugins/starship/ @axieax plugins/universalarchive/ @Konfekt plugins/wp-cli/ @joshmedeski plugins/zoxide/ @ajeetdsouza -plugins/starship/ @axieax -plugins/dbt/ @msempere diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..4dc9f3854 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: "weekly" + day: "sunday" + - package-ecosystem: "pip" + directory: "/.github/workflows/dependencies" + schedule: + interval: "weekly" + day: "sunday" diff --git a/.github/dependencies.yml b/.github/dependencies.yml new file mode 100644 index 000000000..f760ddcef --- /dev/null +++ b/.github/dependencies.yml @@ -0,0 +1,38 @@ +dependencies: + plugins/gitfast: + repo: felipec/git-completion + branch: master + version: tag:v2.1 + postcopy: | + set -e + rm -rf git-completion.plugin.zsh Makefile README.adoc t tools + test -e git-completion.zsh && mv -f git-completion.zsh _git + plugins/z: + branch: master + repo: agkozak/zsh-z + version: afaf2965b41fdc6ca66066e09382726aa0b6aa04 + precopy: | + set -e + test -e README.md && mv -f README.md MANUAL.md + postcopy: | + set -e + test -e _zshz && mv -f _zshz _z + test -e zsh-z.plugin.zsh && mv -f zsh-z.plugin.zsh z.plugin.zsh + plugins/history-substring-search: + repo: zsh-users/zsh-history-substring-search + branch: master + version: 8dd05bfcc12b0cd1ee9ea64be725b3d9f713cf64 + precopy: | + set -e + rm -f zsh-history-substring-search.plugin.zsh + test -e zsh-history-substring-search.zsh && mv zsh-history-substring-search.zsh history-substring-search.zsh + postcopy: | + set -e + test -e dependencies/OMZ-README.md && cat dependencies/OMZ-README.md >> README.md + plugins/gradle: + repo: gradle/gradle-completion + branch: master + version: 25da917cf5a88f3e58f05be3868a7b2748c8afe6 + precopy: | + set -e + find . ! -name _gradle ! -name LICENSE -delete diff --git a/.github/workflows/dependencies.yml b/.github/workflows/dependencies.yml new file mode 100644 index 000000000..2e2217e1c --- /dev/null +++ b/.github/workflows/dependencies.yml @@ -0,0 +1,29 @@ +name: Update dependencies +on: + workflow_dispatch: {} + # schedule: + # - cron: '34 3 * * */8' + +jobs: + check: + name: Check for updates + runs-on: ubuntu-latest + if: github.repository == 'ohmyzsh/ohmyzsh' + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Authenticate as @ohmyzsh + id: generate_token + uses: ohmyzsh/github-app-token@v2 + with: + app_id: ${{ secrets.OHMYZSH_APP_ID }} + private_key: ${{ secrets.OHMYZSH_APP_PRIVATE_KEY }} + - name: Process dependencies + env: + GH_TOKEN: ${{ steps.generate_token.outputs.token }} + GIT_APP_NAME: ohmyzsh[bot] + GIT_APP_EMAIL: 54982679+ohmyzsh[bot]@users.noreply.github.com + TMP_DIR: ${{ runner.temp }} + run: | + pip install -r .github/workflows/dependencies/requirements.txt + python3 .github/workflows/dependencies/updater.py diff --git a/.github/workflows/dependencies/requirements.txt b/.github/workflows/dependencies/requirements.txt new file mode 100644 index 000000000..3c4c149ea --- /dev/null +++ b/.github/workflows/dependencies/requirements.txt @@ -0,0 +1,2 @@ +PyYAML~=6.0.1 +requests~=2.31.0 diff --git a/.github/workflows/dependencies/updater.py b/.github/workflows/dependencies/updater.py new file mode 100644 index 000000000..f54d316f9 --- /dev/null +++ b/.github/workflows/dependencies/updater.py @@ -0,0 +1,450 @@ +import os +import subprocess +import sys +import requests +import shutil +import yaml +from copy import deepcopy +from typing import Optional, TypedDict + +# Get TMP_DIR variable from environment +TMP_DIR = os.path.join(os.environ.get("TMP_DIR", "/tmp"), "ohmyzsh") +# Relative path to dependencies.yml file +DEPS_YAML_FILE = ".github/dependencies.yml" +# Dry run flag +DRY_RUN = os.environ.get("DRY_RUN", "0") == "1" + +import timeit +class CodeTimer: + def __init__(self, name=None): + self.name = " '" + name + "'" if name else '' + + def __enter__(self): + self.start = timeit.default_timer() + + def __exit__(self, exc_type, exc_value, traceback): + self.took = (timeit.default_timer() - self.start) * 1000.0 + print('Code block' + self.name + ' took: ' + str(self.took) + ' ms') + + +### YAML representation +def str_presenter(dumper, data): + """ + Configures yaml for dumping multiline strings + Ref: https://stackoverflow.com/a/33300001 + """ + if len(data.splitlines()) > 1: # check for multiline string + return dumper.represent_scalar('tag:yaml.org,2002:str', data, style='|') + return dumper.represent_scalar('tag:yaml.org,2002:str', data) + +yaml.add_representer(str, str_presenter) +yaml.representer.SafeRepresenter.add_representer(str, str_presenter) + + +# Types +class DependencyDict(TypedDict): + repo: str + branch: str + version: str + precopy: Optional[str] + postcopy: Optional[str] + +class DependencyYAML(TypedDict): + dependencies: dict[str, DependencyDict] + +class UpdateStatus(TypedDict): + has_updates: bool + version: Optional[str] + compare_url: Optional[str] + head_ref: Optional[str] + head_url: Optional[str] + + +class CommandRunner: + class Exception(Exception): + def __init__(self, message, returncode, stage, stdout, stderr): + super().__init__(message) + self.returncode = returncode + self.stage = stage + self.stdout = stdout + self.stderr = stderr + + @staticmethod + def run_or_fail(command: list[str], stage: str, *args, **kwargs): + if DRY_RUN and command[0] == "gh": + command.insert(0, "echo") + + result = subprocess.run(command, *args, capture_output=True, **kwargs) + + if result.returncode != 0: + raise CommandRunner.Exception( + f"{stage} command failed with exit code {result.returncode}", returncode=result.returncode, + stage=stage, + stdout=result.stdout.decode("utf-8"), + stderr=result.stderr.decode("utf-8") + ) + + return result + + +class DependencyStore: + store: DependencyYAML = { + "dependencies": {} + } + + @staticmethod + def set(data: DependencyYAML): + DependencyStore.store = data + + @staticmethod + def update_dependency_version(path: str, version: str) -> DependencyYAML: + with CodeTimer(f"store deepcopy: {path}"): + store_copy = deepcopy(DependencyStore.store) + + dependency = store_copy["dependencies"].get(path, {}) + dependency["version"] = version + store_copy["dependencies"][path] = dependency + + return store_copy + + @staticmethod + def write_store(file: str, data: DependencyYAML): + with open(file, "w") as yaml_file: + yaml.safe_dump(data, yaml_file, sort_keys=False) + + +class Dependency: + def __init__(self, path: str, values: DependencyDict): + self.path = path + self.values = values + + self.name: str = "" + self.desc: str = "" + self.kind: str = "" + + match path.split("/"): + case ["plugins", name]: + self.name = name + self.kind = "plugin" + self.desc = f"{name} plugin" + case ["themes", name]: + self.name = name.replace(".zsh-theme", "") + self.kind = "theme" + self.desc = f"{self.name} theme" + case _: + self.name = self.desc = path + + def __str__(self): + output: str = "" + for key in DependencyDict.__dict__['__annotations__'].keys(): + if key not in self.values: + output += f"{key}: None\n" + continue + + value = self.values[key] + if "\n" not in value: + output += f"{key}: {value}\n" + else: + output += f"{key}:\n " + output += value.replace("\n", "\n ", value.count("\n") - 1) + return output + + def update_or_notify(self): + # Print dependency settings + print(f"Processing {self.desc}...", file=sys.stderr) + print(self, file=sys.stderr) + + # Check for updates + repo = self.values["repo"] + remote_branch = self.values["branch"] + version = self.values["version"] + is_tag = version.startswith("tag:") + + try: + with CodeTimer(f"update check: {repo}"): + if is_tag: + status = GitHub.check_newer_tag(repo, version.replace("tag:", "")) + else: + status = GitHub.check_updates(repo, remote_branch, version) + + if status["has_updates"]: + short_sha = status["head_ref"][:8] + new_version = status["version"] if is_tag else short_sha + + try: + # Create new branch + branch = Git.create_branch(self.path, new_version) + + # Update dependencies.yml file + self.__update_yaml(f"tag:{new_version}" if is_tag else status["version"]) + + # Update dependency files + self.__apply_upstream_changes() + + # Add all changes and commit + Git.add_and_commit(self.name, short_sha) + + # Push changes to remote + Git.push(branch) + + # Create GitHub PR + GitHub.create_pr( + branch, + f"feat({self.name}): update to version {new_version}", + f"""## Description + +Update for **{self.desc}**: update to version [{new_version}]({status['head_url']}). +Check out the [list of changes]({status['compare_url']}). +""" + ) + + # Clean up repository + Git.clean_repo() + except (CommandRunner.Exception, shutil.Error) as e: + # Handle exception on automatic update + match type(e): + case CommandRunner.Exception: + # Print error message + print(f"Error running {e.stage} command: {e.returncode}", file=sys.stderr) + print(e.stderr, file=sys.stderr) + case shutil.Error: + print(f"Error copying files: {e}", file=sys.stderr) + + try: + Git.clean_repo() + except CommandRunner.Exception as e: + print(f"Error reverting repository to clean state: {e}", file=sys.stderr) + sys.exit(1) + + # Create a GitHub issue to notify maintainer + title = f"{self.path}: update to {new_version}" + body = ( + f"""## Description + +There is a new version of `{self.name}` {self.kind} available. + +New version: [{new_version}]({status['head_url']}) +Check out the [list of changes]({status['compare_url']}). +""" + ) + + print(f"Creating GitHub issue", file=sys.stderr) + print(f"{title}\n\n{body}", file=sys.stderr) + GitHub.create_issue(title, body) + except Exception as e: + print(e, file=sys.stderr) + + def __update_yaml(self, new_version: str) -> None: + dep_yaml = DependencyStore.update_dependency_version(self.path, new_version) + DependencyStore.write_store(DEPS_YAML_FILE, dep_yaml) + + def __apply_upstream_changes(self) -> None: + # Patterns to ignore in copying files from upstream repo + GLOBAL_IGNORE = [ + ".git", + ".github", + ".gitignore" + ] + + path = os.path.abspath(self.path) + precopy = self.values.get("precopy") + postcopy = self.values.get("postcopy") + + repo = self.values["repo"] + branch = self.values["branch"] + remote_url = f"https://github.com/{repo}.git" + repo_dir = os.path.join(TMP_DIR, repo) + + # Clone repository + Git.clone(remote_url, branch, repo_dir, reclone=True) + + # Run precopy on tmp repo + if precopy is not None: + print("Running precopy script:", end="\n ", file=sys.stderr) + print(precopy.replace("\n", "\n ", precopy.count("\n") - 1), file=sys.stderr) + CommandRunner.run_or_fail(["bash", "-c", precopy], cwd=repo_dir, stage="Precopy") + + # Copy files from upstream repo + print(f"Copying files from {repo_dir} to {path}", file=sys.stderr) + shutil.copytree(repo_dir, path, dirs_exist_ok=True, ignore=shutil.ignore_patterns(*GLOBAL_IGNORE)) + + # Run postcopy on our repository + if postcopy is not None: + print("Running postcopy script:", end="\n ", file=sys.stderr) + print(postcopy.replace("\n", "\n ", postcopy.count("\n") - 1), file=sys.stderr) + CommandRunner.run_or_fail(["bash", "-c", postcopy], cwd=path, stage="Postcopy") + + +class Git: + default_branch = "master" + + @staticmethod + def clone(remote_url: str, branch: str, repo_dir: str, reclone=False): + # If repo needs to be fresh + if reclone and os.path.exists(repo_dir): + shutil.rmtree(repo_dir) + + # Clone repo in tmp directory and checkout branch + if not os.path.exists(repo_dir): + print(f"Cloning {remote_url} to {repo_dir} and checking out {branch}", file=sys.stderr) + CommandRunner.run_or_fail(["git", "clone", "--depth=1", "-b", branch, remote_url, repo_dir], stage="Clone") + + @staticmethod + def create_branch(path: str, version: str): + # Get current branch name + result = CommandRunner.run_or_fail(["git", "rev-parse", "--abbrev-ref", "HEAD"], stage="GetDefaultBranch") + Git.default_branch = result.stdout.decode("utf-8").strip() + + # Create new branch and return created branch name + branch_name = f"update/{path}/{version}" + CommandRunner.run_or_fail(["git", "checkout", "-b", branch_name], stage="CreateBranch") + return branch_name + + @staticmethod + def add_and_commit(scope: str, version: str): + user_name = os.environ.get("GIT_APP_NAME") + user_email = os.environ.get("GIT_APP_EMAIL") + + # Add all files to git staging + CommandRunner.run_or_fail(["git", "add", "-A", "-v"], stage="AddFiles") + + # Reset environment and git config + clean_env = os.environ.copy() + clean_env["LANG"]="C.UTF-8" + clean_env["GIT_CONFIG_GLOBAL"]="/dev/null" + clean_env["GIT_CONFIG_NOSYSTEM"]="1" + + # Commit with settings above + CommandRunner.run_or_fail([ + "git", + "-c", f"user.name={user_name}", + "-c", f"user.email={user_email}", + "commit", + "-m", f"feat({scope}): update to {version}" + ], stage="CreateCommit", env=clean_env) + + @staticmethod + def push(branch: str): + CommandRunner.run_or_fail(["git", "push", "-u", "origin", branch], stage="PushBranch") + + @staticmethod + def clean_repo(): + CommandRunner.run_or_fail(["git", "reset", "--hard", "HEAD"], stage="ResetRepository") + CommandRunner.run_or_fail(["git", "checkout", Git.default_branch], stage="CheckoutDefaultBranch") + + +class GitHub: + @staticmethod + def check_newer_tag(repo, current_tag) -> UpdateStatus: + # GET /repos/:owner/:repo/git/refs/tags + url = f"https://api.github.com/repos/{repo}/git/refs/tags" + + # Send a GET request to the GitHub API + response = requests.get(url) + + # If the request was successful + if response.status_code == 200: + # Parse the JSON response + data = response.json() + + if len(data) == 0: + return { + "has_updates": False, + } + + latest_ref = data[-1] + latest_tag = latest_ref["ref"].replace("refs/tags/", "") + + if latest_tag == current_tag: + return { + "has_updates": False, + } + + return { + "has_updates": True, + "version": latest_tag, + "compare_url": f"https://github.com/{repo}/compare/{current_tag}...{latest_tag}", + "head_ref": latest_ref["object"]["sha"], + "head_url": f"https://github.com/{repo}/releases/tag/{latest_tag}", + } + else: + # If the request was not successful, raise an exception + raise Exception(f"GitHub API request failed with status code {response.status_code}: {response.json()}") + + @staticmethod + def check_updates(repo, branch, version) -> UpdateStatus: + # TODO: add support for semver updating (based on tags) + # Check if upstream github repo has a new version + # GitHub API URL for comparing two commits + url = f"https://api.github.com/repos/{repo}/compare/{version}...{branch}" + + # Send a GET request to the GitHub API + response = requests.get(url) + + # If the request was successful + if response.status_code == 200: + # Parse the JSON response + data = response.json() + + # If the base is behind the head, there is a newer version + has_updates = data["status"] != "identical" + + if not has_updates: + return { + "has_updates": False, + } + + return { + "has_updates": data["status"] != "identical", + "version": data["commits"][-1]["sha"], + "compare_url": data["permalink_url"], + "head_ref": data["commits"][-1]["sha"], + "head_url": data["commits"][-1]["html_url"] + } + else: + # If the request was not successful, raise an exception + raise Exception(f"GitHub API request failed with status code {response.status_code}: {response.json()}") + + @staticmethod + def create_issue(title: str, body: str) -> None: + cmd = [ + "gh", + "issue", + "create", + "-t", title, + "-b", body + ] + CommandRunner.run_or_fail(cmd, stage="CreateIssue") + + @staticmethod + def create_pr(branch: str, title: str, body: str) -> None: + cmd = [ + "gh", + "pr", + "create", + "-B", Git.default_branch, + "-H", branch, + "-t", title, + "-b", body + ] + CommandRunner.run_or_fail(cmd, stage="CreatePullRequest") + + +def main(): + # Load the YAML file + with open(DEPS_YAML_FILE, "r") as yaml_file: + data: DependencyYAML = yaml.safe_load(yaml_file) + + if "dependencies" not in data: + raise Exception(f"dependencies.yml not properly formatted") + + # Cache YAML version + DependencyStore.set(data) + + dependencies = data["dependencies"] + for path in dependencies: + dependency = Dependency(path, dependencies[path]) + dependency.update_or_notify() + +if __name__ == "__main__": + main() diff --git a/.github/workflows/installer.yml b/.github/workflows/installer.yml index ac88d10b0..5593c9175 100644 --- a/.github/workflows/installer.yml +++ b/.github/workflows/installer.yml @@ -3,9 +3,9 @@ on: workflow_dispatch: {} push: paths: - - tools/install.sh - - .github/workflows/installer - - .github/workflows/installer.yml + - 'tools/install.sh' + - '.github/workflows/installer/**' + - '.github/workflows/installer.yml' concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} @@ -17,6 +17,7 @@ permissions: jobs: test: name: Test installer + if: github.repository == 'ohmyzsh/ohmyzsh' runs-on: ${{ matrix.os }} strategy: matrix: @@ -25,7 +26,7 @@ jobs: - macos-latest steps: - name: Set up git repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install zsh if: runner.os == 'Linux' run: sudo apt-get update; sudo apt-get install zsh @@ -41,15 +42,15 @@ jobs: - test steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install Vercel CLI run: npm install -g vercel - name: Setup project and deploy env: VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} run: | cp tools/install.sh .github/workflows/installer/install.sh cd .github/workflows/installer - vc link --yes -t ${{ secrets.VERCEL_TOKEN }} - vc deploy --prod -t ${{ secrets.VERCEL_TOKEN }} + vc deploy --prod -t "$VERCEL_TOKEN" diff --git a/.github/workflows/installer/vercel.json b/.github/workflows/installer/vercel.json index 8c5aec5e0..524dc3c0f 100644 --- a/.github/workflows/installer/vercel.json +++ b/.github/workflows/installer/vercel.json @@ -2,7 +2,16 @@ "headers": [ { "source": "/((?!favicon.ico).*)", - "headers": [{ "key": "Content-Type", "value": "text/plain" }] + "headers": [ + { + "key": "Content-Type", + "value": "text/plain" + }, + { + "key": "Content-Disposition", + "value": "inline; filename=\"install.sh\"" + } + ] } ], "rewrites": [ diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 57403629c..264ac31f3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,16 +20,12 @@ permissions: jobs: tests: name: Run tests - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest if: github.repository == 'ohmyzsh/ohmyzsh' - strategy: - matrix: - os: [ubuntu-latest, macos-latest] steps: - name: Set up git repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install zsh - if: runner.os == 'Linux' run: sudo apt-get update; sudo apt-get install zsh - name: Check syntax run: | diff --git a/.github/workflows/project.yml b/.github/workflows/project.yml index 1d961d8c0..2c2a1cdaa 100644 --- a/.github/workflows/project.yml +++ b/.github/workflows/project.yml @@ -15,9 +15,15 @@ jobs: name: Add to project runs-on: ubuntu-latest if: github.repository == 'ohmyzsh/ohmyzsh' - env: - GITHUB_TOKEN: ${{ secrets.PROJECT_TOKEN }} steps: + - name: Authenticate as @ohmyzsh + id: generate_token + uses: ohmyzsh/github-app-token@v2 + with: + app_id: ${{ secrets.OHMYZSH_APP_ID }} + private_key: ${{ secrets.OHMYZSH_APP_PRIVATE_KEY }} + - name: Store app token + run: echo "GH_TOKEN=${{ steps.generate_token.outputs.token }}" >> "$GITHUB_ENV" - name: Read project data env: ORGANIZATION: ohmyzsh diff --git a/README.md b/README.md index a30595581..dea36fda7 100644 --- a/README.md +++ b/README.md @@ -13,41 +13,43 @@ Finally, you'll begin to get the sort of attention that you have always felt you To learn more, visit [ohmyz.sh](https://ohmyz.sh), follow [@ohmyzsh](https://twitter.com/ohmyzsh) on Twitter, and join us on [Discord](https://discord.gg/ohmyzsh). [![CI](https://github.com/ohmyzsh/ohmyzsh/workflows/CI/badge.svg)](https://github.com/ohmyzsh/ohmyzsh/actions?query=workflow%3ACI) -[![Follow @ohmyzsh](https://img.shields.io/twitter/follow/ohmyzsh?label=Follow+@ohmyzsh&style=flat)](https://twitter.com/intent/follow?screen_name=ohmyzsh) +[![X (formerly Twitter) Follow](https://img.shields.io/twitter/follow/ohmyzsh?label=%40ohmyzsh&logo=x&style=flat)](https://twitter.com/intent/follow?screen_name=ohmyzsh) +[![Mastodon Follow](https://img.shields.io/mastodon/follow/111169632522566717?label=%40ohmyzsh&domain=https%3A%2F%2Fmstdn.social&logo=mastodon&style=flat)](https://mstdn.social/@ohmyzsh) [![Discord server](https://img.shields.io/discord/642496866407284746)](https://discord.gg/ohmyzsh) [![Gitpod ready](https://img.shields.io/badge/Gitpod-ready-blue?logo=gitpod)](https://gitpod.io/#https://github.com/ohmyzsh/ohmyzsh) -[![huntr.dev](https://cdn.huntr.dev/huntr_security_badge_mono.svg)](https://huntr.dev/bounties/disclose/?utm_campaign=ohmyzsh%2Fohmyzsh&utm_medium=social&utm_source=github&target=https%3A%2F%2Fgithub.com%2Fohmyzsh%2Fohmyzsh)
Table of Contents - [Getting Started](#getting-started) + - [Operating System Compatibility](#operating-system-compatibility) - [Prerequisites](#prerequisites) - [Basic Installation](#basic-installation) - - [Manual inspection](#manual-inspection) + - [Manual Inspection](#manual-inspection) - [Using Oh My Zsh](#using-oh-my-zsh) - [Plugins](#plugins) - [Enabling Plugins](#enabling-plugins) - [Using Plugins](#using-plugins) - [Themes](#themes) - - [Selecting a Theme](#selecting-a-theme) + - [Selecting A Theme](#selecting-a-theme) - [FAQ](#faq) - [Advanced Topics](#advanced-topics) - [Advanced Installation](#advanced-installation) - [Custom Directory](#custom-directory) - - [Unattended install](#unattended-install) - - [Installing from a forked repository](#installing-from-a-forked-repository) + - [Unattended Install](#unattended-install) + - [Installing From A Forked Repository](#installing-from-a-forked-repository) - [Manual Installation](#manual-installation) - [Installation Problems](#installation-problems) - - [Custom Plugins and Themes](#custom-plugins-and-themes) - - [Enable GNU ls in macOS and freeBSD systems](#enable-gnu-ls) - - [Skip aliases](#skip-aliases) + - [Custom Plugins And Themes](#custom-plugins-and-themes) + - [Enable GNU ls In macOS And freeBSD Systems](#enable-gnu-ls-in-macos-and-freebsd-systems) + - [Skip Aliases](#skip-aliases) + - [Disable async git prompt](#disable-async-git-prompt) - [Getting Updates](#getting-updates) - - [Updates verbosity](#updates-verbosity) + - [Updates Verbosity](#updates-verbosity) - [Manual Updates](#manual-updates) - [Uninstalling Oh My Zsh](#uninstalling-oh-my-zsh) -- [How do I contribute to Oh My Zsh?](#how-do-i-contribute-to-oh-my-zsh) - - [Do NOT send us themes](#do-not-send-us-themes) +- [How Do I Contribute To Oh My Zsh?](#how-do-i-contribute-to-oh-my-zsh) + - [Do Not Send Us Themes](#do-not-send-us-themes) - [Contributors](#contributors) - [Follow Us](#follow-us) - [Merchandise](#merchandise) @@ -58,9 +60,21 @@ To learn more, visit [ohmyz.sh](https://ohmyz.sh), follow [@ohmyzsh](https://twi ## Getting Started +### Operating System Compatibility + +| O/S | Status | +| :------------- | :-----: | +| Android | ✅ | +| freeBSD | ✅ | +| LCARS | 🛸 | +| Linux | ✅ | +| macOS | ✅ | +| OS/2 Warp | ❌ | +| Windows (WSL2) | ✅ | + + ### Prerequisites -- A Unix-like operating system: macOS, Linux, BSD. On Windows: WSL2 is preferred, but cygwin or msys also mostly work. - [Zsh](https://www.zsh.org) should be installed (v4.3.9 or more recent is fine but we prefer 5.0.8 and newer). If not pre-installed (run `zsh --version` to confirm), check the following wiki instructions here: [Installing ZSH](https://github.com/ohmyzsh/ohmyzsh/wiki/Installing-ZSH) - `curl` or `wget` should be installed - `git` should be installed (recommended v2.4.11 or higher) @@ -75,9 +89,17 @@ Oh My Zsh is installed by running one of the following commands in your terminal | **wget** | `sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"` | | **fetch** | `sh -c "$(fetch -o - https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"` | +Alternatively, the installer is also mirrored outside GitHub. Using this URL instead may be required if you're in a country like India or China, that blocks `raw.githubusercontent.com`: + +| Method | Command | +| :-------- | :------------------------------------------------------------------------------------------------ | +| **curl** | `sh -c "$(curl -fsSL https://install.ohmyz.sh/)"` | +| **wget** | `sh -c "$(wget -O- https://install.ohmyz.sh/)"` | +| **fetch** | `sh -c "$(fetch -o - https://install.ohmyz.sh/)"` | + _Note that any previous `.zshrc` will be renamed to `.zshrc.pre-oh-my-zsh`. After installation, you can move the configuration you want to preserve into the new `.zshrc`._ -#### Manual inspection +#### Manual Inspection It's a good idea to inspect the install script from projects you don't yet know. You can do that by downloading the install script first, looking through it so everything looks normal, @@ -88,6 +110,8 @@ wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh sh install.sh ``` +If the above URL times out or otherwise fails, you may have to substitute the URL for `https://install.ohmyz.sh` to be able to get the script. + ## Using Oh My Zsh ### Plugins @@ -126,7 +150,7 @@ Each built-in plugin includes a **README**, documenting it. This README should s We'll admit it. Early in the Oh My Zsh world, we may have gotten a bit too theme happy. We have over one hundred and fifty themes now bundled. Most of them have [screenshots](https://github.com/ohmyzsh/ohmyzsh/wiki/Themes) on the wiki (We are working on updating this!). Check them out! -#### Selecting a Theme +#### Selecting A Theme _Robby's theme is the default one. It's not the fanciest one. It's not the simplest one. It's just the right one (for him)._ @@ -197,7 +221,7 @@ like this: ZSH="$HOME/.dotfiles/oh-my-zsh" sh install.sh ``` -#### Unattended install +#### Unattended Install If you're running the Oh My Zsh install script as part of an automated install, you can pass the `--unattended` flag to the `install.sh` script. This will have the effect of not trying to change @@ -207,7 +231,9 @@ the default shell, and it also won't run `zsh` when the installation has finishe sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended ``` -#### Installing from a forked repository +If you're in China, India, or another country that blocks `raw.githubusercontent.com`, you may have to substitute the URL for `https://install.ohmyz.sh` for it to install. + +#### Installing From A Forked Repository The install script also accepts these variables to allow installation of a different repository: @@ -232,19 +258,19 @@ REPO=apjanke/oh-my-zsh BRANCH=edge sh install.sh #### Manual Installation -##### 1. Clone the repository +##### 1. Clone The Repository ```sh git clone https://github.com/ohmyzsh/ohmyzsh.git ~/.oh-my-zsh ``` -##### 2. _Optionally_, backup your existing `~/.zshrc` file +##### 2. _Optionally_, Backup Your Existing `~/.zshrc` File ```sh cp ~/.zshrc ~/.zshrc.orig ``` -##### 3. Create a new zsh configuration file +##### 3. Create A New Zsh Configuration File You can create a new zsh config file by copying the template that we have included for you. @@ -252,7 +278,7 @@ You can create a new zsh config file by copying the template that we have includ cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc ``` -##### 4. Change your default shell +##### 4. Change Your Default Shell ```sh chsh -s $(which zsh) @@ -260,7 +286,7 @@ chsh -s $(which zsh) You must log out from your user session and log back in to see this change. -##### 5. Initialize your new zsh configuration +##### 5. Initialize Your New Zsh Configuration Once you open up a new terminal window, it should load zsh with Oh My Zsh's configuration. @@ -271,7 +297,7 @@ If you have any hiccups installing, here are a few common fixes. - You _might_ need to modify your `PATH` in `~/.zshrc` if you're not able to find some commands after switching to `oh-my-zsh`. - If you installed manually or changed the install location, check the `ZSH` environment variable in `~/.zshrc`. -### Custom Plugins and Themes +### Custom Plugins And Themes If you want to override any of the default behaviors, just add a new file (ending in `.zsh`) in the `custom/` directory. @@ -279,7 +305,7 @@ If you have many functions that go well together, you can put them as a `XYZ.plu If you would like to override the functionality of a plugin distributed with Oh My Zsh, create a plugin of the same name in the `custom/plugins/` directory and it will be loaded instead of the one in `plugins/`. -### Enable GNU ls in macOS and freeBSD systems +### Enable GNU ls In macOS And freeBSD Systems @@ -293,7 +319,7 @@ zstyle ':omz:lib:theme-and-appearance' gnu-ls yes _Note: this is not compatible with `DISABLE_LS_COLORS=true`_ -### Skip aliases +### Skip Aliases @@ -336,6 +362,17 @@ Instead, you can now use the following: zstyle ':omz:lib:directories' aliases no ``` +### Disable async git prompt + +Async prompt functions are an experimental feature (included on April 3, 2024) that allows Oh My Zsh to render prompt information +asyncronously. This can improve prompt rendering performance, but it might not work well with some setups. We hope that's not an +issue, but if you're seeing problems with this new feature, you can turn it off by setting the following in your .zshrc file, +before Oh My Zsh is sourced: + +```sh +zstyle ':omz:alpha:lib:git' async-prompt no +``` + #### Notice > This feature is currently in a testing phase and it may be subject to change in the future. @@ -376,7 +413,7 @@ zstyle ':omz:update' frequency 7 zstyle ':omz:update' frequency 0 ``` -### Updates verbosity +### Updates Verbosity You can also limit the update verbosity with the following settings: @@ -404,7 +441,7 @@ Oh My Zsh isn't for everyone. We'll miss you, but we want to make this an easy b If you want to uninstall `oh-my-zsh`, just run `uninstall_oh_my_zsh` from the command-line. It will remove itself and revert your previous `bash` or `zsh` configuration. -## How do I contribute to Oh My Zsh? +## How Do I Contribute To Oh My Zsh? Before you participate in our delightful community, please read the [code of conduct](CODE_OF_CONDUCT.md). @@ -414,7 +451,7 @@ We also need people to test out pull requests. So take a look through [the open See [Contributing](CONTRIBUTING.md) for more details. -### Do NOT send us themes +### Do Not Send Us Themes We have (more than) enough themes for the time being. Please add your theme to the [external themes](https://github.com/ohmyzsh/ohmyzsh/wiki/External-themes) wiki page. @@ -424,6 +461,10 @@ Oh My Zsh has a vibrant community of happy users and delightful contributors. Wi Thank you so much! + + + + ## Follow Us We're on social media: diff --git a/SECURITY.md b/SECURITY.md index 7e5c8eed0..ae7458ee2 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -17,8 +17,7 @@ In the near future we will introduce versioning, so expect this section to chang **Do not submit an issue or pull request**: this might reveal the vulnerability. -Instead, you should email the maintainers directly at: [**security@ohmyz.sh**](mailto:security@ohmyz.sh). +Instead, you should email the maintainers directly at: [**security@ohmyz.sh**](mailto:security@ohmyz.sh), +or using the link to [privately report a vulnerability with GitHub](https://github.com/ohmyzsh/ohmyzsh/security/advisories/new). We will deal with the vulnerability privately and submit a patch as soon as possible. - -You can also submit your vulnerability report to [huntr.dev](https://huntr.dev/bounties/disclose/?utm_campaign=ohmyzsh%2Fohmyzsh&utm_medium=social&utm_source=github&target=https%3A%2F%2Fgithub.com%2Fohmyzsh%2Fohmyzsh) and see if you can get a bounty reward. diff --git a/custom/example.zsh b/custom/example.zsh index 21a8d8be7..c194f49d7 100644 --- a/custom/example.zsh +++ b/custom/example.zsh @@ -1,12 +1,12 @@ # Put files in this folder to add your own custom functionality. # See: https://github.com/ohmyzsh/ohmyzsh/wiki/Customization -# +# # Files in the custom/ directory will be: # - loaded automatically by the init script, in alphabetical order # - loaded last, after all built-ins in the lib/ directory, to override them # - ignored by git by default -# +# # Example: add custom/shortcuts.zsh for shortcuts to your local projects -# +# # brainstormr=~/Projects/development/planetargon/brainstormr # cd $brainstormr diff --git a/custom/themes/example.zsh-theme b/custom/themes/example.zsh-theme index 494d029e8..5551207f8 100644 --- a/custom/themes/example.zsh-theme +++ b/custom/themes/example.zsh-theme @@ -1,6 +1,6 @@ # Put your custom themes in this folder. # See: https://github.com/ohmyzsh/ohmyzsh/wiki/Customization#overriding-and-adding-themes -# +# # Example: PROMPT="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m %{$fg[yellow]%}%~ %{$reset_color%}%% " diff --git a/lib/async_prompt.zsh b/lib/async_prompt.zsh new file mode 100644 index 000000000..db48446e7 --- /dev/null +++ b/lib/async_prompt.zsh @@ -0,0 +1,144 @@ +# The async code is taken from +# https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/async.zsh +# https://github.com/woefe/git-prompt.zsh/blob/master/git-prompt.zsh + +zmodload zsh/system +autoload -Uz is-at-least + +# For now, async prompt function handlers are set up like so: +# First, define the async function handler and register the handler +# with _omz_register_handler: +# +# function _git_prompt_status_async { +# # Do some expensive operation that outputs to stdout +# } +# _omz_register_handler _git_prompt_status_async +# +# Then add a stub prompt function in `$PROMPT` or similar prompt variables, +# which will show the output of "$_OMZ_ASYNC_OUTPUT[handler_name]": +# +# function git_prompt_status { +# echo -n $_OMZ_ASYNC_OUTPUT[_git_prompt_status_async] +# } +# +# RPROMPT='$(git_prompt_status)' +# +# This API is subject to change and optimization. Rely on it at your own risk. + +function _omz_register_handler { + setopt localoptions noksharrays + typeset -ga _omz_async_functions + # we want to do nothing if there's no $1 function or we already set it up + if [[ -z "$1" ]] || (( ! ${+functions[$1]} )) \ + || (( ${_omz_async_functions[(Ie)$1]} )); then + return + fi + _omz_async_functions+=("$1") + # let's add the hook to async_request if it's not there yet + if (( ! ${precmd_functions[(Ie)_omz_async_request]} )) \ + && (( ${+functions[_omz_async_request]})); then + autoload -Uz add-zsh-hook + add-zsh-hook precmd _omz_async_request + fi +} + +# Set up async handlers and callbacks +function _omz_async_request { + local -i ret=$? + typeset -gA _OMZ_ASYNC_FDS _OMZ_ASYNC_PIDS _OMZ_ASYNC_OUTPUT + + # executor runs a subshell for all async requests based on key + local handler + for handler in ${_omz_async_functions}; do + (( ${+functions[$handler]} )) || continue + + local fd=${_OMZ_ASYNC_FDS[$handler]:--1} + local pid=${_OMZ_ASYNC_PIDS[$handler]:--1} + + # If we've got a pending request, cancel it + if (( fd != -1 && pid != -1 )) && { true <&$fd } 2>/dev/null; then + # Close the file descriptor and remove the handler + exec {fd}<&- + zle -F $fd + + # Zsh will make a new process group for the child process only if job + # control is enabled (MONITOR option) + if [[ -o MONITOR ]]; then + # Send the signal to the process group to kill any processes that may + # have been forked by the async function handler + kill -TERM -$pid 2>/dev/null + else + # Kill just the child process since it wasn't placed in a new process + # group. If the async function handler forked any child processes they may + # be orphaned and left behind. + kill -TERM $pid 2>/dev/null + fi + fi + + # Define global variables to store the file descriptor, PID and output + _OMZ_ASYNC_FDS[$handler]=-1 + _OMZ_ASYNC_PIDS[$handler]=-1 + + # Fork a process to fetch the git status and open a pipe to read from it + exec {fd}< <( + # Tell parent process our PID + builtin echo ${sysparams[pid]} + # Set exit code for the handler if used + () { return $ret } + # Run the async function handler + $handler + ) + + # Save FD for handler + _OMZ_ASYNC_FDS[$handler]=$fd + + # There's a weird bug here where ^C stops working unless we force a fork + # See https://github.com/zsh-users/zsh-autosuggestions/issues/364 + # and https://github.com/zsh-users/zsh-autosuggestions/pull/612 + is-at-least 5.8 || command true + + # Save the PID from the handler child process + read -u $fd "_OMZ_ASYNC_PIDS[$handler]" + + # When the fd is readable, call the response handler + zle -F "$fd" _omz_async_callback + done +} + +# Called when new data is ready to be read from the pipe +function _omz_async_callback() { + emulate -L zsh + + local fd=$1 # First arg will be fd ready for reading + local err=$2 # Second arg will be passed in case of error + + if [[ -z "$err" || "$err" == "hup" ]]; then + # Get handler name from fd + local handler="${(k)_OMZ_ASYNC_FDS[(r)$fd]}" + + # Store old output which is supposed to be already printed + local old_output="${_OMZ_ASYNC_OUTPUT[$handler]}" + + # Read output from fd + IFS= read -r -u $fd -d '' "_OMZ_ASYNC_OUTPUT[$handler]" + + # Repaint prompt if output has changed + if [[ "$old_output" != "${_OMZ_ASYNC_OUTPUT[$handler]}" ]]; then + zle .reset-prompt + zle -R + fi + + # Close the fd + exec {fd}<&- + fi + + # Always remove the handler + zle -F "$fd" + + # Unset global FD variable to prevent closing user created FDs in the precmd hook + _OMZ_ASYNC_FDS[$handler]=-1 + _OMZ_ASYNC_PIDS[$handler]=-1 +} + +autoload -Uz add-zsh-hook +add-zsh-hook precmd _omz_async_request diff --git a/lib/cli.zsh b/lib/cli.zsh index 561c1b98b..383b0cfb0 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -241,10 +241,18 @@ function _omz::plugin::disable { # Remove plugins substitution awk script local awk_subst_plugins="\ - gsub(/[ \t]+(${(j:|:)dis_plugins})/, \"\") # with spaces before - gsub(/(${(j:|:)dis_plugins})[ \t]+/, \"\") # with spaces after - gsub(/\((${(j:|:)dis_plugins})\)/, \"\") # without spaces (only plugin) + gsub(/[ \t]+(${(j:|:)dis_plugins})[ \t]+/, \" \") # with spaces before or after + gsub(/[ \t]+(${(j:|:)dis_plugins})$/, \"\") # with spaces before and EOL + gsub(/^(${(j:|:)dis_plugins})[ \t]+/, \"\") # with BOL and spaces after + + gsub(/\((${(j:|:)dis_plugins})[ \t]+/, \"(\") # with parenthesis before and spaces after + gsub(/[ \t]+(${(j:|:)dis_plugins})\)/, \")\") # with spaces before or parenthesis after + gsub(/\((${(j:|:)dis_plugins})\)/, \"()\") # with only parentheses + + gsub(/^(${(j:|:)dis_plugins})\)/, \")\") # with BOL and closing parenthesis + gsub(/\((${(j:|:)dis_plugins})$/, \"(\") # with opening parenthesis and EOL " + # Disable plugins awk script local awk_script=" # if plugins=() is in oneline form, substitute disabled plugins and go to next line @@ -448,7 +456,7 @@ function _omz::plugin::load { if [[ ! -f "$base/_$plugin" && ! -f "$base/$plugin.plugin.zsh" ]]; then _omz::log warn "'$plugin' is not a valid plugin" continue - # It it is a valid plugin, add its directory to $fpath unless it is already there + # It is a valid plugin, add its directory to $fpath unless it is already there elif (( ! ${fpath[(Ie)$base]} )); then fpath=("$base" $fpath) fi @@ -773,7 +781,17 @@ function _omz::theme::use { } function _omz::update { - local last_commit=$(builtin cd -q "$ZSH"; git rev-parse HEAD) + # Check if git command is available + (( $+commands[git] )) || { + _omz::log error "git is not installed. Aborting..." + return 1 + } + + local last_commit=$(builtin cd -q "$ZSH"; git rev-parse HEAD 2>/dev/null) + [[ $? -eq 0 ]] || { + _omz::log error "\`$ZSH\` is not a git directory. Aborting..." + return 1 + } # Run update script zstyle -s ':omz:update' verbose verbose_mode || verbose_mode=default diff --git a/lib/clipboard.zsh b/lib/clipboard.zsh index 2f3b6bcad..5d149f056 100644 --- a/lib/clipboard.zsh +++ b/lib/clipboard.zsh @@ -62,7 +62,7 @@ function detect-clipboard() { function clippaste() { powershell.exe -noprofile -command Get-Clipboard; } elif [ -n "${WAYLAND_DISPLAY:-}" ] && (( ${+commands[wl-copy]} )) && (( ${+commands[wl-paste]} )); then function clipcopy() { cat "${1:-/dev/stdin}" | wl-copy &>/dev/null &|; } - function clippaste() { wl-paste; } + function clippaste() { wl-paste --no-newline; } elif [ -n "${DISPLAY:-}" ] && (( ${+commands[xsel]} )); then function clipcopy() { cat "${1:-/dev/stdin}" | xsel --clipboard --input; } function clippaste() { xsel --clipboard --output; } @@ -100,8 +100,8 @@ function detect-clipboard() { fi } -# Detect at startup. A non-zero exit here indicates that the dummy clipboards were set, -# which is not really an error. If the user calls them, they will attempt to redetect -# (for example, perhaps the user has now installed xclip) and then either print an error -# or proceed successfully. -detect-clipboard || true +function clipcopy clippaste { + unfunction clipcopy clippaste + detect-clipboard || true # let one retry + "$0" "$@" +} diff --git a/lib/compfix.zsh b/lib/compfix.zsh index b09b283f2..2fe9d9e64 100644 --- a/lib/compfix.zsh +++ b/lib/compfix.zsh @@ -13,7 +13,7 @@ function handle_completion_insecurities() { # /usr/share/zsh/5.0.6 # # Since the ignorable first line is printed to stderr and thus not captured, - # stderr is squelched to prevent this output from leaking to the user. + # stderr is squelched to prevent this output from leaking to the user. local -aU insecure_dirs insecure_dirs=( ${(f@):-"$(compaudit 2>/dev/null)"} ) diff --git a/lib/completion.zsh b/lib/completion.zsh index 63379b53f..5a233a322 100644 --- a/lib/completion.zsh +++ b/lib/completion.zsh @@ -49,7 +49,7 @@ zstyle ':completion:*:*:*:users' ignored-patterns \ adm amanda apache at avahi avahi-autoipd beaglidx bin cacti canna \ clamav daemon dbus distcache dnsmasq dovecot fax ftp games gdm \ gkrellmd gopher hacluster haldaemon halt hsqldb ident junkbust kdm \ - ldap lp mail mailman mailnull man messagebus mldonkey mysql nagios \ + ldap lp mail mailman mailnull man messagebus mldonkey mysql nagios \ named netdump news nfsnobody nobody nscd ntp nut nx obsrun openvpn \ operator pcap polkitd postfix postgres privoxy pulse pvm quagga radvd \ rpc rpcuser rpm rtkit scard shutdown squid sshd statd svn sync tftp \ diff --git a/lib/diagnostics.zsh b/lib/diagnostics.zsh index eaeba7d23..d67e6fab4 100644 --- a/lib/diagnostics.zsh +++ b/lib/diagnostics.zsh @@ -30,7 +30,7 @@ # # This is written in a defensive style so it still works (and can detect) cases when # basic functionality like echo and which have been redefined. In particular, almost -# everything is invoked with "builtin" or "command", to work in the face of user +# everything is invoked with "builtin" or "command", to work in the face of user # redefinitions. # # OPTIONS @@ -59,7 +59,7 @@ function omz_diagnostic_dump() { emulate -L zsh builtin echo "Generating diagnostic dump; please be patient..." - + local thisfcn=omz_diagnostic_dump local -A opts local opt_verbose opt_noverbose opt_outfile @@ -90,7 +90,7 @@ function omz_diagnostic_dump() { builtin echo builtin echo Diagnostic dump file created at: "$outfile" builtin echo - builtin echo To share this with OMZ developers, post it as a gist on GitHub + builtin echo To share this with OMZ developers, post it as a gist on GitHub builtin echo at "https://gist.github.com" and share the link to the gist. builtin echo builtin echo "WARNING: This dump file contains all your zsh and omz configuration files," @@ -105,8 +105,8 @@ function _omz_diag_dump_one_big_text() { builtin echo oh-my-zsh diagnostic dump builtin echo builtin echo $outfile - builtin echo - + builtin echo + # Basic system and zsh information command date command uname -a @@ -151,7 +151,7 @@ function _omz_diag_dump_one_big_text() { # Core command definitions _omz_diag_dump_check_core_commands || return 1 - builtin echo + builtin echo # ZSH Process state builtin echo Process state: @@ -167,7 +167,7 @@ function _omz_diag_dump_one_big_text() { #TODO: Should this include `env` instead of or in addition to `export`? builtin echo Exported: builtin echo $(builtin export | command sed 's/=.*//') - builtin echo + builtin echo builtin echo Locale: command locale builtin echo @@ -181,7 +181,7 @@ function _omz_diag_dump_one_big_text() { builtin echo builtin echo 'compaudit output:' compaudit - builtin echo + builtin echo builtin echo '$fpath directories:' command ls -lad $fpath builtin echo @@ -224,7 +224,7 @@ function _omz_diag_dump_one_big_text() { local cfgfile cfgfiles # Some files for bash that zsh does not use are intentionally included # to help with diagnosing behavior differences between bash and zsh - cfgfiles=( /etc/zshenv /etc/zprofile /etc/zshrc /etc/zlogin /etc/zlogout + cfgfiles=( /etc/zshenv /etc/zprofile /etc/zshrc /etc/zlogin /etc/zlogout $zdotdir/.zshenv $zdotdir/.zprofile $zdotdir/.zshrc $zdotdir/.zlogin $zdotdir/.zlogout ~/.zsh.pre-oh-my-zsh /etc/bashrc /etc/profile ~/.bashrc ~/.profile ~/.bash_profile ~/.bash_logout ) @@ -258,8 +258,8 @@ function _omz_diag_dump_check_core_commands() { # (For back-compatibility, if any of these are newish, they should be removed, # or at least made conditional on the version of the current running zsh.) # "history" is also excluded because OMZ is known to redefine that - reserved_words=( do done esac then elif else fi for case if while function - repeat time until select coproc nocorrect foreach end '!' '[[' '{' '}' + reserved_words=( do done esac then elif else fi for case if while function + repeat time until select coproc nocorrect foreach end '!' '[[' '{' '}' ) builtins=( alias autoload bg bindkey break builtin bye cd chdir command comparguments compcall compctl compdescribe compfiles compgroups compquote comptags @@ -331,7 +331,7 @@ function _omz_diag_dump_os_specific_version() { case "$OSTYPE" in darwin*) osname=$(command sw_vers -productName) - osver=$(command sw_vers -productVersion) + osver=$(command sw_vers -productVersion) builtin echo "OS Version: $osname $osver build $(sw_vers -buildVersion)" ;; cygwin) diff --git a/lib/functions.zsh b/lib/functions.zsh index a252d0a33..f5c671f9c 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -182,6 +182,8 @@ function omz_urlencode() { fi # Use LC_CTYPE=C to process text byte-by-byte + # Note that this doesn't work in Termux, as it only has UTF-8 locale. + # Characters will be processed as UTF-8, which is fine for URLs. local i byte ord LC_ALL=C export LC_ALL local reserved=';/?:@&=+$,' @@ -206,6 +208,9 @@ function omz_urlencode() { else if [[ "$byte" == " " && -n $spaces_as_plus ]]; then url_str+="+" + elif [[ "$PREFIX" = *com.termux* ]]; then + # Termux does not have non-UTF8 locales, so just send the UTF-8 character directly + url_str+="$byte" else ord=$(( [##16] #byte )) url_str+="%$ord" diff --git a/lib/git.zsh b/lib/git.zsh index f049f73c2..b257d01a4 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -1,3 +1,5 @@ +autoload -Uz is-at-least + # The git prompt's git commands are read-only and should not interfere with # other processes. This environment variable is equivalent to running with `git # --no-optional-locks`, but falls back gracefully for older versions of git. @@ -9,14 +11,18 @@ function __git_prompt_git() { GIT_OPTIONAL_LOCKS=0 command git "$@" } -function git_prompt_info() { +function _omz_git_prompt_info() { # If we are on a folder not tracked by git, get out. # Otherwise, check for hide-info at global and local repository level if ! __git_prompt_git rev-parse --git-dir &> /dev/null \ - || [[ "$(__git_prompt_git config --get oh-my-zsh.hide-info 2>/dev/null)" == 1 ]]; then + || [[ "$(__git_prompt_git config --get oh-my-zsh.hide-info 2>/dev/null)" == 1 ]]; then return 0 fi + # Get either: + # - the current branch name + # - the tag name if we are on a tag + # - the short SHA of the current commit local ref ref=$(__git_prompt_git symbolic-ref --short HEAD 2> /dev/null) \ || ref=$(__git_prompt_git describe --tags --exact-match HEAD 2> /dev/null) \ @@ -33,6 +39,52 @@ function git_prompt_info() { echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${ref:gs/%/%%}${upstream:gs/%/%%}$(parse_git_dirty)${ZSH_THEME_GIT_PROMPT_SUFFIX}" } +# Use async version if setting is enabled or undefined +if zstyle -T ':omz:alpha:lib:git' async-prompt; then + function git_prompt_info() { + if [[ -n "${_OMZ_ASYNC_OUTPUT[_omz_git_prompt_info]}" ]]; then + echo -n "${_OMZ_ASYNC_OUTPUT[_omz_git_prompt_info]}" + fi + } + + function git_prompt_status() { + if [[ -n "${_OMZ_ASYNC_OUTPUT[_omz_git_prompt_status]}" ]]; then + echo -n "${_OMZ_ASYNC_OUTPUT[_omz_git_prompt_status]}" + fi + } + + # Conditionally register the async handler, only if it's needed in $PROMPT + # or any of the other prompt variables + function _defer_async_git_register() { + # Check if git_prompt_info is used in a prompt variable + case "${PS1}:${PS2}:${PS3}:${PS4}:${RPROMPT}:${RPS1}:${RPS2}:${RPS3}:${RPS4}" in + *(\$\(git_prompt_info\)|\`git_prompt_info\`)*) + _omz_register_handler _omz_git_prompt_info + ;; + esac + + case "${PS1}:${PS2}:${PS3}:${PS4}:${RPROMPT}:${RPS1}:${RPS2}:${RPS3}:${RPS4}" in + *(\$\(git_prompt_status\)|\`git_prompt_status\`)*) + _omz_register_handler _omz_git_prompt_status + ;; + esac + + add-zsh-hook -d precmd _defer_async_git_register + unset -f _defer_async_git_register + } + + # Register the async handler first. This needs to be done before + # the async request prompt is run + precmd_functions=(_defer_async_git_register $precmd_functions) +else + function git_prompt_info() { + _omz_git_prompt_info + } + function git_prompt_status() { + _omz_git_prompt_status + } +fi + # Checks if working tree is dirty function parse_git_dirty() { local STATUS @@ -161,7 +213,7 @@ function git_prompt_long_sha() { SHA=$(__git_prompt_git rev-parse HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER" } -function git_prompt_status() { +function _omz_git_prompt_status() { [[ "$(__git_prompt_git config --get oh-my-zsh.hide-status 2>/dev/null)" = 1 ]] && return # Maps a git status prefix to an internal constant diff --git a/lib/history.zsh b/lib/history.zsh index 794076904..a8431fd5a 100644 --- a/lib/history.zsh +++ b/lib/history.zsh @@ -1,19 +1,20 @@ ## History wrapper function omz_history { - local clear list - zparseopts -E c=clear l=list + # parse arguments and remove from $@ + local clear list stamp + zparseopts -E -D c=clear l=list f=stamp E=stamp i=stamp t:=stamp if [[ -n "$clear" ]]; then # if -c provided, clobber the history file echo -n >| "$HISTFILE" fc -p "$HISTFILE" echo >&2 History file deleted. - elif [[ -n "$list" ]]; then - # if -l provided, run as if calling `fc' directly - builtin fc "$@" + elif [[ $# -eq 0 ]]; then + # if no arguments provided, show full history starting from 1 + builtin fc $stamp -l 1 else - # unless a number is provided, show all history events (starting from 1) - [[ ${@[-1]-} = *[0-9]* ]] && builtin fc -l "$@" || builtin fc -l "$@" 1 + # otherwise, run `fc -l` with a custom format + builtin fc $stamp -l "$@" fi } diff --git a/lib/key-bindings.zsh b/lib/key-bindings.zsh index aaa73046e..a5650dd81 100644 --- a/lib/key-bindings.zsh +++ b/lib/key-bindings.zsh @@ -32,19 +32,26 @@ if [[ -n "${terminfo[knp]}" ]]; then fi # Start typing + [Up-Arrow] - fuzzy find history forward -if [[ -n "${terminfo[kcuu1]}" ]]; then - autoload -U up-line-or-beginning-search - zle -N up-line-or-beginning-search +autoload -U up-line-or-beginning-search +zle -N up-line-or-beginning-search +bindkey -M emacs "^[[A" up-line-or-beginning-search +bindkey -M viins "^[[A" up-line-or-beginning-search +bindkey -M vicmd "^[[A" up-line-or-beginning-search +if [[ -n "${terminfo[kcuu1]}" ]]; then bindkey -M emacs "${terminfo[kcuu1]}" up-line-or-beginning-search bindkey -M viins "${terminfo[kcuu1]}" up-line-or-beginning-search bindkey -M vicmd "${terminfo[kcuu1]}" up-line-or-beginning-search fi -# Start typing + [Down-Arrow] - fuzzy find history backward -if [[ -n "${terminfo[kcud1]}" ]]; then - autoload -U down-line-or-beginning-search - zle -N down-line-or-beginning-search +# Start typing + [Down-Arrow] - fuzzy find history backward +autoload -U down-line-or-beginning-search +zle -N down-line-or-beginning-search + +bindkey -M emacs "^[[B" down-line-or-beginning-search +bindkey -M viins "^[[B" down-line-or-beginning-search +bindkey -M vicmd "^[[B" down-line-or-beginning-search +if [[ -n "${terminfo[kcud1]}" ]]; then bindkey -M emacs "${terminfo[kcud1]}" down-line-or-beginning-search bindkey -M viins "${terminfo[kcud1]}" down-line-or-beginning-search bindkey -M vicmd "${terminfo[kcud1]}" down-line-or-beginning-search diff --git a/lib/misc.zsh b/lib/misc.zsh index 132f33551..ff2017713 100644 --- a/lib/misc.zsh +++ b/lib/misc.zsh @@ -19,8 +19,13 @@ setopt multios # enable redirect to multiple streams: echo >file1 > setopt long_list_jobs # show long list format job notifications setopt interactivecomments # recognize comments -env_default 'PAGER' 'less' -env_default 'LESS' '-R' +# define pager dependant on what is available (less or more) +if (( ${+commands[less]} )); then + env_default 'PAGER' 'less' + env_default 'LESS' '-R' +elif (( ${+commands[more]} )); then + env_default 'PAGER' 'more' +fi ## super user alias alias _='sudo ' diff --git a/lib/prompt_info_functions.zsh b/lib/prompt_info_functions.zsh index 3dc9b6d10..29aca9b48 100644 --- a/lib/prompt_info_functions.zsh +++ b/lib/prompt_info_functions.zsh @@ -40,5 +40,5 @@ ZSH_THEME_RVM_PROMPT_OPTIONS="i v g" # use this to enable users to see their ruby version, no matter which # version management system they use function ruby_prompt_info() { - echo $(rvm_prompt_info || rbenv_prompt_info || chruby_prompt_info) + echo "$(rvm_prompt_info || rbenv_prompt_info || chruby_prompt_info)" } diff --git a/lib/spectrum.zsh b/lib/spectrum.zsh index 97f5c360a..31e37792c 100644 --- a/lib/spectrum.zsh +++ b/lib/spectrum.zsh @@ -7,6 +7,7 @@ typeset -AHg FX FG BG FX=( reset "%{%}" bold "%{%}" no-bold "%{%}" + dim "%{%}" no-dim "%{%}" italic "%{%}" no-italic "%{%}" underline "%{%}" no-underline "%{%}" blink "%{%}" no-blink "%{%}" diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh index 6d969503d..087bae9bb 100644 --- a/lib/termsupport.zsh +++ b/lib/termsupport.zsh @@ -17,7 +17,7 @@ function title { : ${2=$1} case "$TERM" in - cygwin|xterm*|putty*|rxvt*|konsole*|ansi|mlterm*|alacritty|st*|foot|contour*) + cygwin|xterm*|putty*|rxvt*|konsole*|ansi|mlterm*|alacritty*|st*|foot*|contour*) print -Pn "\e]2;${2:q}\a" # set window name print -Pn "\e]1;${1:q}\a" # set tab name ;; @@ -129,7 +129,7 @@ fi # Don't define the function if we're in an unsupported terminal case "$TERM" in # all of these either process OSC 7 correctly or ignore entirely - xterm*|putty*|rxvt*|konsole*|mlterm*|alacritty|screen*|tmux*) ;; + xterm*|putty*|rxvt*|konsole*|mlterm*|alacritty*|screen*|tmux*) ;; contour*|foot*) ;; *) # Terminal.app and iTerm2 process OSC 7 correctly @@ -151,7 +151,7 @@ function omz_termsupport_cwd { URL_PATH="$(omz_urlencode -P $PWD)" || return 1 # Konsole errors if the HOST is provided - [[ -z "$KONSOLE_VERSION" ]] || URL_HOST="" + [[ -z "$KONSOLE_PROFILE_NAME" && -z "$KONSOLE_DBUS_SESSION" ]] || URL_HOST="" # common control sequence (OSC 7) to set current host and path printf "\e]7;file://%s%s\e\\" "${URL_HOST}" "${URL_PATH}" diff --git a/lib/tests/cli.test.zsh b/lib/tests/cli.test.zsh new file mode 100644 index 000000000..9ee5cd219 --- /dev/null +++ b/lib/tests/cli.test.zsh @@ -0,0 +1,169 @@ +#!/usr/bin/zsh -df + +run_awk() { + local -a dis_plugins=(${=1}) + local input_text="$2" + + (( ! DEBUG )) || set -xv + + local awk_subst_plugins="\ + gsub(/[ \t]+(${(j:|:)dis_plugins})[ \t]+/, \" \") # with spaces before or after + gsub(/[ \t]+(${(j:|:)dis_plugins})$/, \"\") # with spaces before and EOL + gsub(/^(${(j:|:)dis_plugins})[ \t]+/, \"\") # with BOL and spaces after + + gsub(/\((${(j:|:)dis_plugins})[ \t]+/, \"(\") # with parenthesis before and spaces after + gsub(/[ \t]+(${(j:|:)dis_plugins})\)/, \")\") # with spaces before or parenthesis after + gsub(/\((${(j:|:)dis_plugins})\)/, \"()\") # with only parentheses + + gsub(/^(${(j:|:)dis_plugins})\)/, \")\") # with BOL and closing parenthesis + gsub(/\((${(j:|:)dis_plugins})$/, \"(\") # with opening parenthesis and EOL + " + # Disable plugins awk script + local awk_script=" + # if plugins=() is in oneline form, substitute disabled plugins and go to next line + /^[ \t]*plugins=\([^#]+\).*\$/ { + $awk_subst_plugins + print \$0 + next + } + + # if plugins=() is in multiline form, enable multi flag and disable plugins if they're there + /^[ \t]*plugins=\(/ { + multi=1 + $awk_subst_plugins + print \$0 + next + } + + # if multi flag is enabled and we find a valid closing parenthesis, remove plugins and disable multi flag + multi == 1 && /^[^#]*\)/ { + multi=0 + $awk_subst_plugins + print \$0 + next + } + + multi == 1 && length(\$0) > 0 { + $awk_subst_plugins + if (length(\$0) > 0) print \$0 + next + } + + { print \$0 } + " + + command awk "$awk_script" <<< "$input_text" + + (( ! DEBUG )) || set +xv +} + +# runs awk against stdin, checks if the resulting file is not empty and then checks if the file has valid zsh syntax +run_awk_and_test() { + local description="$1" + local plugins_to_disable="$2" + local input_text="$3" + local expected_output="$4" + + local tmpfile==(:) + + { + print -u2 "Test: $description" + DEBUG=0 run_awk "$plugins_to_disable" "$input_text" >| $tmpfile + + if [[ ! -s "$tmpfile" ]]; then + print -u2 "\e[31mError\e[0m: output file empty" + return 1 + fi + + if ! zsh -n $tmpfile; then + print -u2 "\e[31mError\e[0m: zsh syntax error" + diff -u $tmpfile <(echo "$expected_output") + return 1 + fi + + if ! diff -u --color=always $tmpfile <(echo "$expected_output"); then + if (( DEBUG )); then + print -u2 "" + DEBUG=1 run_awk "$plugins_to_disable" "$input_text" + print -u2 "" + fi + print -u2 "\e[31mError\e[0m: output file does not match expected output" + return 1 + fi + + print -u2 "\e[32mSuccess\e[0m" + } always { + print -u2 "" + command rm -f "$tmpfile" + } +} + +# These tests are for the `omz plugin disable` command +run_awk_and_test \ + "it should delete a single plugin in oneline format" \ + "git" \ + "plugins=(git)" \ + "plugins=()" + +run_awk_and_test \ + "it should delete a single plugin in multiline format" \ + "github" \ +"plugins=( + github +)" \ +"plugins=( +)" + +run_awk_and_test \ + "it should delete multiple plugins in oneline format" \ + "github git z" \ + "plugins=(github git z)" \ + "plugins=()" + +run_awk_and_test \ + "it should delete multiple plugins in multiline format" \ + "github git z" \ +"plugins=( + github + git + z +)" \ +"plugins=( +)" + +run_awk_and_test \ + "it should delete a single plugin among multiple in oneline format" \ + "git" \ + "plugins=(github git z)" \ + "plugins=(github z)" + +run_awk_and_test \ + "it should delete a single plugin among multiple in multiline format" \ + "git" \ +"plugins=( + github + git + z +)" \ +"plugins=( + github + z +)" + +run_awk_and_test \ + "it should delete multiple plugins in mixed format" \ + "git z" \ +"plugins=(github +git z)" \ +"plugins=(github +)" + +run_awk_and_test \ + "it should delete multiple plugins in mixed format 2" \ + "github z" \ +"plugins=(github + git +z)" \ +"plugins=( + git +)" diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index a577c1f41..2fb20298a 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -1,14 +1,14 @@ +# ANSI formatting function (\033[m) +# 0: reset, 1: bold, 4: underline, 22: no bold, 24: no underline, 31: red, 33: yellow +omz_f() { + [ $# -gt 0 ] || return + IFS=";" printf "\033[%sm" $* +} +# If stdout is not a terminal ignore all formatting +[ -t 1 ] || omz_f() { :; } + # Protect against non-zsh execution of Oh My Zsh (use POSIX syntax here) [ -n "$ZSH_VERSION" ] || { - # ANSI formatting function (\033[m) - # 0: reset, 1: bold, 4: underline, 22: no bold, 24: no underline, 31: red, 33: yellow - omz_f() { - [ $# -gt 0 ] || return - IFS=";" printf "\033[%sm" $* - } - # If stdout is not a terminal ignore all formatting - [ -t 1 ] || omz_f() { :; } - omz_ptree() { # Get process tree of the current process pid=$$; pids="$pid" @@ -38,6 +38,15 @@ return 1 } +# Check if in emulation mode, if so early return +# https://github.com/ohmyzsh/ohmyzsh/issues/11686 +[[ "$(emulate)" = zsh ]] || { + printf "$(omz_f 1 31)Error:$(omz_f 22) Oh My Zsh can't be loaded in \`$(emulate)\` emulation mode.$(omz_f 0)\n" >&2 + return 1 +} + +unset -f omz_f + # If ZSH is not defined, use the current script's directory. [[ -z "$ZSH" ]] && export ZSH="${${(%):-%x}:a:h}" @@ -143,7 +152,7 @@ unset zcompdump_revision zcompdump_fpath zcompdump_refresh # zcompile the completion dump file if the .zwc is older or missing. if command mkdir "${ZSH_COMPDUMP}.lock" 2>/dev/null; then zrecompile -q -p "$ZSH_COMPDUMP" - command rm -rf "$ZSH_COMPDUMP.zwc.old" "${ZSH_COMPDUMP}.lock" + command rm -rf "$ZSH_COMPDUMP.zwc.old" "${ZSH_COMPDUMP}.lock" fi _omz_source() { @@ -187,12 +196,12 @@ _omz_source() { fi } -# Load all of the config files in ~/oh-my-zsh that end in .zsh +# Load all of the lib files in ~/oh-my-zsh/lib that end in .zsh # TIP: Add files you don't want in git to .gitignore -for config_file ("$ZSH"/lib/*.zsh); do - _omz_source "lib/${config_file:t}" +for lib_file ("$ZSH"/lib/*.zsh); do + _omz_source "lib/${lib_file:t}" done -unset custom_config_file +unset lib_file # Load all of the plugins that were defined in ~/.zshrc for plugin ($plugins); do diff --git a/plugins/alias-finder/.zunit.yml b/plugins/alias-finder/.zunit.yml new file mode 100644 index 000000000..ae65f8ef2 --- /dev/null +++ b/plugins/alias-finder/.zunit.yml @@ -0,0 +1,9 @@ +tap: false +directories: + tests: tests + output: tests/_output + support: tests/_support +time_limit: 0 +fail_fast: false +allow_risky: false +verbose: true diff --git a/plugins/alias-finder/README.md b/plugins/alias-finder/README.md index 409f4b653..6c87c723a 100644 --- a/plugins/alias-finder/README.md +++ b/plugins/alias-finder/README.md @@ -2,45 +2,32 @@ This plugin searches the defined aliases and outputs any that match the command inputted. This makes learning new aliases easier. +## Usage + To use it, add `alias-finder` to the `plugins` array of your zshrc file: ``` plugins=(... alias-finder) ``` -## Usage -To see if there is an alias defined for the command, pass it as an argument to `alias-finder`. This can also run automatically before each command you input - add `ZSH_ALIAS_FINDER_AUTOMATIC=true` to your zshrc if you want this. +To enable it for every single command, set zstyle in your `~/.zshrc`. -## Options +```zsh +# ~/.zshrc + +zstyle ':omz:plugins:alias-finder' autoload yes # disabled by default +zstyle ':omz:plugins:alias-finder' longer yes # disabled by default +zstyle ':omz:plugins:alias-finder' exact yes # disabled by default +zstyle ':omz:plugins:alias-finder' cheaper yes # disabled by default +``` + +As you can see, options are also available with zstyle. + +### Options + +> In order to clarify, let's say `alias a=abc` has source 'abc' and destination 'a'. + +- Use `--longer` or `-l` to include aliases where the source is longer than the input (in other words, the source could contain the whole input). +- Use `--exact` or `-e` to avoid aliases where the source is shorter than the input (in other words, the source must be the same with the input). +- Use `--cheaper` or `-c` to avoid aliases where the destination is longer than the input (in other words, the destination must be the shorter than the input). -- Use `--longer` or `-l` to allow the aliases to be longer than the input (match aliases if they contain the input). -- Use `--exact` or `-e` to avoid matching aliases that are shorter than the input. -## Examples -``` -$ alias-finder "git pull" -gl='git pull' -g=git -``` -``` -$ alias-finder "web_search google oh my zsh" -google='web_search google' -``` -``` -$ alias-finder "git commit -v" -gc="git commit -v" -g=git -``` -``` -$ alias-finder -e "git commit -v" -gc='git commit -v' -``` -``` -$ alias-finder -l "git commit -v" -gc='git commit -v' -'gc!'='git commit -v --amend' -gca='git commit -v -a' -'gca!'='git commit -v -a --amend' -'gcan!'='git commit -v -a --no-edit --amend' -'gcans!'='git commit -v -a -s --no-edit --amend' -'gcn!'='git commit -v --no-edit --amend' -``` diff --git a/plugins/alias-finder/alias-finder.plugin.zsh b/plugins/alias-finder/alias-finder.plugin.zsh index caee9b5a3..5fdfbc835 100644 --- a/plugins/alias-finder/alias-finder.plugin.zsh +++ b/plugins/alias-finder/alias-finder.plugin.zsh @@ -1,44 +1,59 @@ alias-finder() { - local cmd="" exact="" longer="" wordStart="" wordEnd="" multiWordEnd="" - for i in $@; do - case $i in + local cmd=" " exact="" longer="" cheaper="" wordEnd="'{0,1}$" finder="" filter="" + + # build command and options + for c in "$@"; do + case $c in + # TODO: Remove backward compatibility (other than zstyle form) + # set options if exist -e|--exact) exact=true;; -l|--longer) longer=true;; - *) - if [[ -z $cmd ]]; then - cmd=$i - else - cmd="$cmd $i" - fi - ;; + -c|--cheaper) cheaper=true;; + # concatenate cmd + *) cmd="$cmd$c " ;; esac done - cmd=$(sed 's/[].\|$(){}?+*^[]/\\&/g' <<< $cmd) # adds escaping for grep - if (( $(wc -l <<< $cmd) == 1 )); then - while [[ $cmd != "" ]]; do - if [[ $longer = true ]]; then - wordStart="'{0,1}" - else - wordEnd="$" - multiWordEnd="'$" - fi - if [[ $cmd == *" "* ]]; then - local finder="'$cmd$multiWordEnd" - else - local finder=$wordStart$cmd$wordEnd - fi - alias | grep -E "=$finder" - if [[ $exact = true || $longer = true ]]; then - break - else - cmd=$(sed -E 's/ {0,1}[^ ]*$//' <<< $cmd) # removes last word - fi - done + + zstyle -t ':omz:plugins:alias-finder' longer && longer=true + zstyle -t ':omz:plugins:alias-finder' exact && exact=true + zstyle -t ':omz:plugins:alias-finder' cheaper && cheaper=true + + # format cmd for grep + ## - replace newlines with spaces + ## - trim both ends + ## - replace multiple spaces with one space + ## - add escaping character to special characters + cmd=$(echo -n "$cmd" | tr '\n' ' ' | xargs | tr -s '[:space:]' | sed 's/[].\|$(){}?+*^[]/\\&/g') + + if [[ $longer == true ]]; then + wordEnd="" # remove wordEnd to find longer aliases fi + + # find with alias and grep, removing last word each time until no more words + while [[ $cmd != "" ]]; do + finder="'{0,1}$cmd$wordEnd" + + # make filter to find only shorter results than current cmd + if [[ $cheaper == true ]]; then + cmdLen=$(echo -n "$cmd" | wc -c) + filter="^'{0,1}.{0,$((cmdLen - 1))}=" + fi + + alias | grep -E "$filter" | grep -E "=$finder" + + if [[ $exact == true ]]; then + break # because exact case is only one + elif [[ $longer = true ]]; then + break # because above grep command already found every longer aliases during first cycle + fi + + cmd=$(sed -E 's/ {0,}[^ ]*$//' <<< "$cmd") # remove last word + done } preexec_alias-finder() { - if [[ $ZSH_ALIAS_FINDER_AUTOMATIC = true ]]; then + # TODO: Remove backward compatibility (other than zstyle form) + zstyle -t ':omz:plugins:alias-finder' autoload && alias-finder $1 || if [[ $ZSH_ALIAS_FINDER_AUTOMATIC = true ]]; then alias-finder $1 fi } diff --git a/plugins/alias-finder/tests/_output/.gitkeep b/plugins/alias-finder/tests/_output/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/alias-finder/tests/_support/.gitkeep b/plugins/alias-finder/tests/_support/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/alias-finder/tests/_support/bootstrap b/plugins/alias-finder/tests/_support/bootstrap new file mode 100644 index 000000000..01076611e --- /dev/null +++ b/plugins/alias-finder/tests/_support/bootstrap @@ -0,0 +1,2 @@ +#!/usr/bin/env zsh +# Write your bootstrap code here diff --git a/plugins/alias-finder/tests/test_run.sh b/plugins/alias-finder/tests/test_run.sh new file mode 100644 index 000000000..6b7abebb6 --- /dev/null +++ b/plugins/alias-finder/tests/test_run.sh @@ -0,0 +1,107 @@ +#!/usr/bin/env zunit + +@setup { + load ../alias-finder.plugin.zsh + + set_git_aliases() { + unalias -a # all + alias g="git" + alias gc="git commit" + alias gcv="git commit -v" + alias gcvs="git commit -v -S" + } +} + +@test 'find aliases that contain input' { + set_git_aliases + + run alias-finder "git" + + assert "${#lines[@]}" equals 1 + assert "${lines[1]}" same_as "g=git" +} + +@test 'find aliases that contain input with whitespaces at ends' { + set_git_aliases + + run alias-finder " git " + + assert "${#lines[@]}" equals 1 + assert "${lines[1]}" same_as "g=git" +} + +@test 'find aliases that contain multiple words' { + set_git_aliases + + run alias-finder "git commit -v" + + assert "${#lines[@]}" equals 3 + assert "${lines[1]}" same_as "gcv='git commit -v'" + assert "${lines[2]}" same_as "gc='git commit'" + assert "${lines[3]}" same_as "g=git" +} + +@test 'find alias that is the same with input when --exact option is set' { + set_git_aliases + + run alias-finder -e "git" + + assert "${#lines[@]}" equals 1 + assert "${lines[1]}" same_as "g=git" +} + +@test 'find alias that is the same with multiple words input when --exact option is set' { + set_git_aliases + + run alias-finder -e "git commit -v" + + assert "${#lines[@]}" equals 1 + assert "${lines[1]}" same_as "gcv='git commit -v'" +} + +@test 'find alias that is the same with or longer than input when --longer option is set' { + set_git_aliases + + run alias-finder -l "git" + + assert "${#lines[@]}" equals 4 + assert "${lines[1]}" same_as "g=git" + assert "${lines[2]}" same_as "gc='git commit'" + assert "${lines[3]}" same_as "gcv='git commit -v'" + assert "${lines[4]}" same_as "gcvs='git commit -v -S'" +} + +@test 'find alias that is the same with or longer than multiple words input when --longer option is set' { + set_git_aliases + + run alias-finder -l "git commit -v" + + assert "${#lines[@]}" equals 2 + assert "${lines[1]}" same_as "gcv='git commit -v'" + assert "${lines[2]}" same_as "gcvs='git commit -v -S'" +} + +@test 'find aliases including expensive (longer) than input' { + set_git_aliases + alias expensiveCommands="git commit" + + run alias-finder "git commit -v" + + assert "${#lines[@]}" equals 4 + assert "${lines[1]}" same_as "gcv='git commit -v'" + assert "${lines[2]}" same_as "expensiveCommands='git commit'" + assert "${lines[3]}" same_as "gc='git commit'" + assert "${lines[4]}" same_as "g=git" +} + +@test 'find aliases excluding expensive (longer) than input when --cheap option is set' { + set_git_aliases + alias expensiveCommands="git commit" + + run alias-finder -c "git commit -v" + + assert "${#lines[@]}" equals 3 + assert "${lines[1]}" same_as "gcv='git commit -v'" + assert "${lines[2]}" same_as "gc='git commit'" + assert "${lines[3]}" same_as "g=git" +} diff --git a/plugins/aliases/README.md b/plugins/aliases/README.md index 6a2da3d74..14f9c5c53 100644 --- a/plugins/aliases/README.md +++ b/plugins/aliases/README.md @@ -15,14 +15,14 @@ Requirements: Python needs to be installed. ## Usage -- `acs`: show all aliases by group +- `als`: show all aliases by group -- `acs -h/--help`: print help mesage +- `als -h/--help`: print help message -- `acs `: filter and highlight aliases by `` +- `als `: filter and highlight aliases by `` -- `acs -g /--group `: show only aliases for group ``. Multiple uses of the flag show all groups +- `als -g /--group `: show only aliases for group ``. Multiple uses of the flag show all groups -- `acs --groups`: show only group names +- `als --groups`: show only group names - ![screenshot](https://cloud.githubusercontent.com/assets/3602957/11581913/cb54fb8a-9a82-11e5-846b-5a67f67ad9ad.png) + ![screenshot](https://github.com/ohmyzsh/ohmyzsh/assets/66907184/5bfa00ea-5fc3-4e97-8b22-2f74f6b948c7) diff --git a/plugins/aliases/aliases.plugin.zsh b/plugins/aliases/aliases.plugin.zsh index 9864de957..7f1ba83b8 100644 --- a/plugins/aliases/aliases.plugin.zsh +++ b/plugins/aliases/aliases.plugin.zsh @@ -4,7 +4,7 @@ 0="${${(M)0:#/*}:-$PWD/$0}" eval ' - function acs(){ + function als(){ (( $+commands[python3] )) || { echo "[error] No python executable detected" return diff --git a/plugins/aliases/cheatsheet.py b/plugins/aliases/cheatsheet.py index f742fba9e..61bf5f956 100644 --- a/plugins/aliases/cheatsheet.py +++ b/plugins/aliases/cheatsheet.py @@ -57,7 +57,7 @@ def pretty_print(cheatsheet, wfilter, group_list=None, groups_only=False): 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") + parser = argparse.ArgumentParser(description="Pretty print aliases.", prog="als") 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") diff --git a/plugins/ansible/README.md b/plugins/ansible/README.md index e0e6a19bb..dd0e1ce03 100644 --- a/plugins/ansible/README.md +++ b/plugins/ansible/README.md @@ -21,7 +21,6 @@ plugins=(... ansible) | `acon` | command `ansible-console` | | `ainv` | command `ansible-inventory` | | `aplaybook` | command `ansible-playbook` | -| `ainv` | command `ansible-inventory` | | `adoc` | command `ansible-doc` | | `agal` | command `ansible-galaxy` | | `apull` | command `ansible-pull` | @@ -29,6 +28,6 @@ plugins=(... ansible) ## Maintainer -### [Deepankumar](https://github.com/deepan10) +### [Deepankumar](https://github.com/deepan10) [https://github.com/deepan10/oh-my-zsh/tree/features/ansible-plugin](https://github.com/deepan10/oh-my-zsh/tree/features/ansible-plugin) diff --git a/plugins/archlinux/archlinux.plugin.zsh b/plugins/archlinux/archlinux.plugin.zsh index fca6548c0..e20a31156 100644 --- a/plugins/archlinux/archlinux.plugin.zsh +++ b/plugins/archlinux/archlinux.plugin.zsh @@ -179,8 +179,8 @@ fi # Check Arch Linux PGP Keyring before System Upgrade to prevent failure. function upgrade() { echo ":: Checking Arch Linux PGP Keyring..." - local installedver="$(sudo pacman -Qi archlinux-keyring | grep -Po '(?<=Version : ).*')" - local currentver="$(sudo pacman -Si archlinux-keyring | grep -Po '(?<=Version : ).*')" + local installedver="$(LANG= sudo pacman -Qi archlinux-keyring | grep -Po '(?<=Version : ).*')" + local currentver="$(LANG= sudo pacman -Si archlinux-keyring | grep -Po '(?<=Version : ).*')" if [ $installedver != $currentver ]; then echo " Arch Linux PGP Keyring is out of date." echo " Updating before full system upgrade." diff --git a/plugins/asdf/asdf.plugin.zsh b/plugins/asdf/asdf.plugin.zsh index 3016282c6..7635d20c3 100644 --- a/plugins/asdf/asdf.plugin.zsh +++ b/plugins/asdf/asdf.plugin.zsh @@ -2,26 +2,29 @@ ASDF_DIR="${ASDF_DIR:-$HOME/.asdf}" ASDF_COMPLETIONS="$ASDF_DIR/completions" -# If not found, check for archlinux/AUR package (/opt/asdf-vm/) -if [[ ! -f "$ASDF_DIR/asdf.sh" || ! -f "$ASDF_COMPLETIONS/asdf.bash" ]] && [[ -f "/opt/asdf-vm/asdf.sh" ]]; then - ASDF_DIR="/opt/asdf-vm" - ASDF_COMPLETIONS="$ASDF_DIR" -fi - -# If not found, check for Homebrew package -if [[ ! -f "$ASDF_DIR/asdf.sh" || ! -f "$ASDF_COMPLETIONS/asdf.bash" ]] && (( $+commands[brew] )); then - brew_prefix="$(brew --prefix asdf)" - ASDF_DIR="${brew_prefix}/libexec" - ASDF_COMPLETIONS="${brew_prefix}/etc/bash_completion.d" - unset brew_prefix +if [[ ! -f "$ASDF_DIR/asdf.sh" || ! -f "$ASDF_COMPLETIONS/_asdf" ]]; then + # If not found, check for archlinux/AUR package (/opt/asdf-vm/) + if [[ -f "/opt/asdf-vm/asdf.sh" ]]; then + ASDF_DIR="/opt/asdf-vm" + ASDF_COMPLETIONS="$ASDF_DIR" + # If not found, check for Homebrew package + elif (( $+commands[brew] )); then + _ASDF_PREFIX="$(brew --prefix asdf)" + ASDF_DIR="${_ASDF_PREFIX}/libexec" + ASDF_COMPLETIONS="${_ASDF_PREFIX}/share/zsh/site-functions" + unset _ASDF_PREFIX + else + return + fi fi # Load command if [[ -f "$ASDF_DIR/asdf.sh" ]]; then - . "$ASDF_DIR/asdf.sh" - + source "$ASDF_DIR/asdf.sh" # Load completions - if [[ -f "$ASDF_COMPLETIONS/asdf.bash" ]]; then - . "$ASDF_COMPLETIONS/asdf.bash" + if [[ -f "$ASDF_COMPLETIONS/_asdf" ]]; then + fpath+=("$ASDF_COMPLETIONS") + autoload -Uz _asdf + compdef _asdf asdf # compdef is already loaded before loading plugins fi fi diff --git a/plugins/autojump/autojump.plugin.zsh b/plugins/autojump/autojump.plugin.zsh index 1b868ee8d..e385a2de8 100644 --- a/plugins/autojump/autojump.plugin.zsh +++ b/plugins/autojump/autojump.plugin.zsh @@ -1,18 +1,21 @@ declare -a autojump_paths autojump_paths=( - $HOME/.autojump/etc/profile.d/autojump.zsh # manual installation - $HOME/.autojump/share/autojump/autojump.zsh # manual installation - $HOME/.nix-profile/etc/profile.d/autojump.sh # NixOS installation - /run/current-system/sw/share/autojump/autojump.zsh # NixOS installation - /usr/share/autojump/autojump.zsh # Debian and Ubuntu package - /etc/profile.d/autojump.zsh # manual installation - /etc/profile.d/autojump.sh # Gentoo installation - /usr/local/share/autojump/autojump.zsh # FreeBSD installation - /usr/pkg/share/autojump/autojump.zsh # NetBSD installation - /opt/local/etc/profile.d/autojump.sh # macOS with MacPorts - /usr/local/etc/profile.d/autojump.sh # macOS with Homebrew (default) - /opt/homebrew/etc/profile.d/autojump.sh # macOS with Homebrew (default on M1 macs) - /etc/profiles/per-user/$USER/etc/profile.d/autojump.sh # macOS Nix, Home Manager and flakes + $HOME/.autojump/etc/profile.d/autojump.zsh # manual installation + $HOME/.autojump/share/autojump/autojump.zsh # manual installation + $HOME/.nix-profile/etc/profile.d/autojump.sh # NixOS installation + /run/current-system/sw/share/autojump/autojump.zsh # NixOS installation + /etc/profiles/per-user/$USER/share/autojump/autojump.zsh # Home Manager, NixOS with user-scoped packages + /usr/share/autojump/autojump.zsh # Debian and Ubuntu package + /etc/profile.d/autojump.zsh # manual installation + /etc/profile.d/autojump.sh # Gentoo installation + /usr/local/share/autojump/autojump.zsh # FreeBSD installation + /usr/pkg/share/autojump/autojump.zsh # NetBSD installation + /opt/local/etc/profile.d/autojump.sh # macOS with MacPorts + /usr/local/etc/profile.d/autojump.sh # macOS with Homebrew (default) + /opt/homebrew/etc/profile.d/autojump.sh # macOS with Homebrew (default on M1 macs) + /opt/pkg/share/autojump/autojump.zsh # macOS with pkgsrc + /etc/profiles/per-user/$USER/etc/profile.d/autojump.sh # macOS Nix, Home Manager and flakes + /nix/var/nix/gcroots/current-system/sw/share/zsh/site-functions/autojump.zsh # macOS Nix, nix-darwin ) for file in $autojump_paths; do diff --git a/plugins/aws/README.md b/plugins/aws/README.md index 9e1e055b8..0d0773f63 100644 --- a/plugins/aws/README.md +++ b/plugins/aws/README.md @@ -16,6 +16,8 @@ plugins=(... aws) 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. +* `asp [] login []`: In addition to `asp [] login`, if SSO session has been configured in your aws profile, it will run the `aws sso login --sso-session ` command following profile selection. +* `asp [] logout`: If AWS SSO has been configured in your aws profile, it will run the `aws sso logout` command following profile selection. * `asr []`: sets `$AWS_REGION` and `$AWS_DEFAULT_REGION` (legacy) to ``. Run `asr` without arguments to clear the profile. @@ -45,6 +47,11 @@ plugins=(... aws) 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/region prompt. +* Set `AWS_PROFILE_STATE_ENABLED=true` in your zshrc file if you want the aws profile to persist between shell sessions. + This option might slow down your shell startup time. + By default the state file path is `/tmp/.aws_current_profile`. This means that the state won't survive a reboot or otherwise GC. + You can control the state file path using the `AWS_STATE_FILE` environment variable. + ## Theme The plugin creates an `aws_prompt_info` function that you can use in your theme, which displays diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh index c946515be..0c43031df 100644 --- a/plugins/aws/aws.plugin.zsh +++ b/plugins/aws/aws.plugin.zsh @@ -6,10 +6,26 @@ function agr() { echo $AWS_REGION } +# Update state file if enabled +function _aws_update_state() { + if [[ "$AWS_PROFILE_STATE_ENABLED" == true ]]; then + test -d $(dirname ${AWS_STATE_FILE}) || exit 1 + echo "${AWS_PROFILE} ${AWS_REGION}" > "${AWS_STATE_FILE}" + fi +} + +function _aws_clear_state() { + if [[ "$AWS_PROFILE_STATE_ENABLED" == true ]]; then + test -d $(dirname ${AWS_STATE_FILE}) || exit 1 + echo -n > "${AWS_STATE_FILE}" + fi +} + # AWS profile selection function asp() { if [[ -z "$1" ]]; then unset AWS_DEFAULT_PROFILE AWS_PROFILE AWS_EB_PROFILE AWS_PROFILE_REGION + _aws_clear_state echo AWS profile cleared. return fi @@ -28,8 +44,16 @@ function asp() { export AWS_PROFILE_REGION=$(aws configure get region) + _aws_update_state + if [[ "$2" == "login" ]]; then - aws sso login + if [[ -n "$3" ]]; then + aws sso login --sso-session $3 + else + aws sso login + fi + elif [[ "$2" == "logout" ]]; then + aws sso logout fi } @@ -37,6 +61,7 @@ function asp() { function asr() { if [[ -z "$1" ]]; then unset AWS_DEFAULT_REGION AWS_REGION + _aws_update_state echo AWS region cleared. return fi @@ -50,6 +75,7 @@ function asr() { export AWS_REGION=$1 export AWS_DEFAULT_REGION=$1 + _aws_update_state } # AWS profile switch @@ -196,8 +222,17 @@ function aws_change_access_key() { } function aws_regions() { + local region + if [[ $AWS_DEFAULT_REGION ]];then + region="$AWS_DEFAULT_REGION" + elif [[ $AWS_REGION ]];then + region="$AWS_REGION" + else + region="us-west-1" + fi + if [[ $AWS_DEFAULT_PROFILE || $AWS_PROFILE ]];then - aws ec2 describe-regions |grep RegionName | awk -F ':' '{gsub(/"/, "", $2);gsub(/,/, "", $2);gsub(/ /, "", $2); print $2}' + aws ec2 describe-regions --region $region |grep RegionName | awk -F ':' '{gsub(/"/, "", $2);gsub(/,/, "", $2);gsub(/ /, "", $2); print $2}' else echo "You must specify a AWS profile." fi @@ -240,6 +275,22 @@ if [[ "$SHOW_AWS_PROMPT" != false && "$RPROMPT" != *'$(aws_prompt_info)'* ]]; th RPROMPT='$(aws_prompt_info)'"$RPROMPT" fi +if [[ "$AWS_PROFILE_STATE_ENABLED" == true ]]; then + AWS_STATE_FILE="${AWS_STATE_FILE:-/tmp/.aws_current_profile}" + test -s "${AWS_STATE_FILE}" || return + + aws_state=($(cat $AWS_STATE_FILE)) + + export AWS_DEFAULT_PROFILE="${aws_state[1]}" + export AWS_PROFILE="$AWS_DEFAULT_PROFILE" + export AWS_EB_PROFILE="$AWS_DEFAULT_PROFILE" + + test -z "${aws_state[2]}" && AWS_REGION=$(aws configure get region) + + export AWS_REGION=${AWS_REGION:-$aws_state[2]} + export AWS_DEFAULT_REGION="$AWS_REGION" +fi + # Load awscli completions # AWS CLI v2 comes with its own autocompletion. Check if that is there, otherwise fall back diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh index db5eeb93a..1d3d529a3 100644 --- a/plugins/battery/battery.plugin.zsh +++ b/plugins/battery/battery.plugin.zsh @@ -13,6 +13,10 @@ # Author: Avneet Singh (kalsi-avneet) # # Modified to add support for Android # ########################################### +# Author: Not Pua (im-notpua) # +# Modified to add support for OpenBSD # +########################################### + if [[ "$OSTYPE" = darwin* ]]; then function battery_is_charging() { @@ -139,6 +143,46 @@ elif [[ "$OSTYPE" = linux-android ]] && (( ${+commands[termux-battery-status]} ) echo "%{$fg[$color]%}${battery_pct}%%%{$reset_color%}" fi } +elif [[ "$OSTYPE" = openbsd* ]]; then + function battery_is_charging() { + [[ $(apm -b) -eq 3 ]] + } + function battery_pct() { + apm -l + } + function battery_pct_remaining() { + if ! battery_is_charging; then + battery_pct + else + echo "External Power" + fi + } + function battery_time_remaining() { + local remaining_time + remaining_time=$(apm -m) + if [[ $remaining_time -ge 0 ]]; then + ((hour = $remaining_time / 60 )) + ((minute = $remaining_time % 60 )) + printf %02d:%02d $hour $minute + fi + } + function battery_pct_prompt() { + local battery_pct color + battery_pct=$(battery_pct_remaining) + if battery_is_charging; then + echo "∞" + else + if [[ $battery_pct -gt 50 ]]; then + color='green' + elif [[ $battery_pct -gt 20 ]]; then + color='yellow' + else + color='red' + fi + echo "%{$fg[$color]%}${battery_pct}%%%{$reset_color%}" + fi + } + elif [[ "$OSTYPE" = linux* ]]; then function battery_is_charging() { if (( $+commands[acpitool] )); then diff --git a/plugins/bazel/README.md b/plugins/bazel/README.md index fc375d219..eba4175bc 100644 --- a/plugins/bazel/README.md +++ b/plugins/bazel/README.md @@ -1,7 +1,6 @@ # Bazel plugin -This plugin adds completion for [bazel](https://bazel.build), an open-source build and -test tool that scalably supports multi-language and multi-platform projects. +This plugin adds completion and aliases for [bazel](https://bazel.build), an open-source build and test tool that scalably supports multi-language and multi-platform projects. To use it, add `bazel` to the plugins array in your zshrc file: @@ -12,3 +11,12 @@ plugins=(... bazel) The plugin has a copy of [the completion script from the git repository][1]. [1]: https://github.com/bazelbuild/bazel/blob/master/scripts/zsh_completion/_bazel + +## Aliases + +| Alias | Command | Description | +| ------- | -------------------------------------- | ------------------------------------------------------ | +| bzb | `bazel build` | The `bazel build` command | +| bzt | `bazel test` | The `bazel test` command | +| bzr | `bazel run` | The `bazel run` command | +| bzq | `bazel query` | The `bazel query` command | diff --git a/plugins/bazel/_bazel b/plugins/bazel/_bazel index c34c572b0..ea1f4cace 100644 --- a/plugins/bazel/_bazel +++ b/plugins/bazel/_bazel @@ -1,4 +1,4 @@ -#compdef bazel +#compdef bazel bazelisk # Copyright 2015 The Bazel Authors. All rights reserved. # diff --git a/plugins/bazel/bazel.plugin.zsh b/plugins/bazel/bazel.plugin.zsh new file mode 100644 index 000000000..d239a06b5 --- /dev/null +++ b/plugins/bazel/bazel.plugin.zsh @@ -0,0 +1,5 @@ +# Aliases for bazel +alias bzb='bazel build' +alias bzt='bazel test' +alias bzr='bazel run' +alias bzq='bazel query' diff --git a/plugins/bgnotify/README.md b/plugins/bgnotify/README.md index 1d8fac54d..33d529f15 100644 --- a/plugins/bgnotify/README.md +++ b/plugins/bgnotify/README.md @@ -1,19 +1,19 @@ # bgnotify zsh plugin -cross-platform background notifications for long running commands! Supports OSX and Ubuntu linux. +cross-platform background notifications for long running commands! Supports OSX and Linux. Standalone homepage: [t413/zsh-background-notify](https://github.com/t413/zsh-background-notify) ----------------------------------- +--- -## How to use! +## How to use Just add bgnotify to your plugins list in your `.zshrc` - On OS X you'll need [terminal-notifier](https://github.com/alloy/terminal-notifier) * `brew install terminal-notifier` (or `gem install terminal-notifier`) -- On ubuntu you're already all set! -- On windows you can use [notifu](https://www.paralint.com/projects/notifu/) or the Cygwin Ports libnotify package +- On Linux, make sure you have `notify-send` or `kdialog` installed. If you're using Ubuntu you should already be all set! +- On Windows you can use [notifu](https://www.paralint.com/projects/notifu/) or the Cygwin Ports libnotify package ## Screenshots @@ -35,20 +35,29 @@ Just add bgnotify to your plugins list in your `.zshrc` One can configure a few things: +- `bgnotify_bell` enabled or disables the terminal bell (default true) - `bgnotify_threshold` sets the notification threshold time (default 6 seconds) -- `function bgnotify_formatted` lets you change the notification +- `function bgnotify_formatted` lets you change the notification. You can for instance customize the message and pass in an icon. Use these by adding a function definition before the your call to source. Example: -~~~ sh +```sh +bgnotify_bell=false ## disable terminal bell bgnotify_threshold=4 ## set your own notification threshold function bgnotify_formatted { ## $1=exit_status, $2=command, $3=elapsed_time - [ $1 -eq 0 ] && title="Holy Smokes Batman!" || title="Holy Graf Zeppelin!" - bgnotify "$title -- after $3 s" "$2"; + + # Humanly readable elapsed time + local elapsed="$(( $3 % 60 ))s" + (( $3 < 60 )) || elapsed="$((( $3 % 3600) / 60 ))m $elapsed" + (( $3 < 3600 )) || elapsed="$(( $3 / 3600 ))h $elapsed" + + [ $1 -eq 0 ] && title="Holy Smokes Batman" || title="Holy Graf Zeppelin" + [ $1 -eq 0 ] && icon="$HOME/icons/success.png" || icon="$HOME/icons/fail.png" + bgnotify "$title - took ${elapsed}" "$2" "$icon" } plugins=(git bgnotify) ## add to plugins list source $ZSH/oh-my-zsh.sh ## existing source call -~~~ +``` diff --git a/plugins/bgnotify/bgnotify.plugin.zsh b/plugins/bgnotify/bgnotify.plugin.zsh index ed2653aa8..0e3f2c640 100644 --- a/plugins/bgnotify/bgnotify.plugin.zsh +++ b/plugins/bgnotify/bgnotify.plugin.zsh @@ -21,13 +21,12 @@ function bgnotify_end { local elapsed=$(( EPOCHSECONDS - bgnotify_timestamp )) # check time elapsed - [[ $bgnotify_timestamp -gt 0 ]] || return - [[ $elapsed -ge $bgnotify_threshold ]] || return + [[ $bgnotify_timestamp -gt 0 ]] || return 0 + [[ $elapsed -ge $bgnotify_threshold ]] || return 0 # check if Terminal app is not active - [[ $(bgnotify_appid) != "$bgnotify_termid" ]] || return + [[ $(bgnotify_appid) != "$bgnotify_termid" ]] || return 0 - printf '\a' # beep sound bgnotify_formatted "$exit_status" "$bgnotify_lastcmd" "$elapsed" } always { bgnotify_timestamp=0 @@ -52,53 +51,89 @@ function bgnotify_formatted { (( $3 < 60 )) || elapsed="$((( $3 % 3600) / 60 ))m $elapsed" (( $3 < 3600 )) || elapsed="$(( $3 / 3600 ))h $elapsed" - if [[ $1 -eq 0 ]]; then - bgnotify "#win (took $elapsed)" "$2" + [[ $bgnotify_bell = true ]] && printf '\a' # beep sound + if [[ $exit_status -eq 0 ]]; then + bgnotify "#win (took $elapsed)" "$cmd" else - bgnotify "#fail (took $elapsed)" "$2" + bgnotify "#fail (took $elapsed)" "$cmd" fi } -# for macOS, output is "app ID, window ID" (com.googlecode.iterm2, 116) function bgnotify_appid { if (( ${+commands[osascript]} )); then - osascript -e 'tell application (path to frontmost application as text) to get the {id, id of front window}' 2>/dev/null - elif (( ${+commands[xprop]} )); then + osascript -e "tell application id \"$(bgnotify_programid)\" to get the {id, frontmost, id of front window, visible of front window}" 2>/dev/null + elif [[ -n $WAYLAND_DISPLAY ]] && (( ${+commands[swaymsg]} )); then # wayland+sway + local app_id=$(bgnotify_find_sway_appid) + [[ -n "$app_id" ]] && echo "$app_id" || echo $EPOCHSECONDS + elif [[ -z $WAYLAND_DISPLAY ]] && [[ -n $DISPLAY ]] && (( ${+commands[xprop]} )); then xprop -root _NET_ACTIVE_WINDOW 2>/dev/null | cut -d' ' -f5 else echo $EPOCHSECONDS fi } -function bgnotify { - # $1: title, $2: message - if (( ${+commands[terminal-notifier]} )); then # macOS - local term_id="${bgnotify_termid%%,*}" # remove window id - if [[ -z "$term_id" ]]; then - case "$TERM_PROGRAM" in - iTerm.app) term_id='com.googlecode.iterm2' ;; - Apple_Terminal) term_id='com.apple.terminal' ;; - esac - fi - if [[ -z "$term_id" ]]; then - terminal-notifier -message "$2" -title "$1" &>/dev/null - else - terminal-notifier -message "$2" -title "$1" -activate "$term_id" -sender "$term_id" &>/dev/null - fi +function bgnotify_find_sway_appid { + # output is "app_id,container_id", for example "Alacritty,1694" + # see example swaymsg output: https://github.com/ohmyzsh/ohmyzsh/files/13463939/output.json + if (( ${+commands[jq]} )); then + swaymsg -t get_tree | jq '.. | select(.type?) | select(.focused==true) | {app_id, id} | join(",")' + else + swaymsg -t get_tree | awk ' + BEGIN { Id = ""; Appid = ""; FocusNesting = -1; Nesting = 0 } + { + # Enter a block + if ($0 ~ /.*{$/) Nesting++ + + # Exit a block. If Nesting is now less than FocusNesting, we have the data we are looking for + if ($0 ~ /^[[:blank:]]*}.*/) { Nesting--; if (FocusNesting > 0 && Nesting < FocusNesting) exit 0 } + + # Save the Id, it is potentially what we are looking for + if ($0 ~ /^[[:blank:]]*"id": [0-9]*,?$/) { sub(/^[[:blank:]]*"id": /, ""); sub(/,$/, ""); Id = $0 } + + # Save the Appid, it is potentially what we are looking for + if ($0 ~ /^[[:blank:]]*"app_id": ".*",?$/) { sub(/^[[:blank:]]*"app_id": "/, ""); sub(/",$/, ""); Appid = $0 } + + # Window is focused, this nesting block contains the Id and Appid we want! + if ($0 ~ /^[[:blank:]]*"focused": true,?$/) { FocusNesting = Nesting } + } + END { + if (Appid != "" && Id != "" && FocusNesting != -1) print Appid "," Id + else print "" + }' + fi +} + +function bgnotify_programid { + case "$TERM_PROGRAM" in + iTerm.app) echo 'com.googlecode.iterm2' ;; + Apple_Terminal) echo 'com.apple.terminal' ;; + esac +} + +function bgnotify { + local title="$1" + local message="$2" + local icon="$3" + if (( ${+commands[terminal-notifier]} )); then # macOS + local term_id=$(bgnotify_programid) + terminal-notifier -message "$message" -title "$title" ${=icon:+-appIcon "$icon"} ${=term_id:+-activate "$term_id" -sender "$term_id"} &>/dev/null elif (( ${+commands[growlnotify]} )); then # macOS growl - growlnotify -m "$1" "$2" - elif (( ${+commands[notify-send]} )); then # GNOME - notify-send "$1" "$2" + growlnotify -m "$title" "$message" + elif (( ${+commands[notify-send]} )); then + notify-send "$title" "$message" ${=icon:+--icon "$icon"} elif (( ${+commands[kdialog]} )); then # KDE - kdialog --title "$1" --passivepopup "$2" 5 + kdialog --title "$title" --passivepopup "$message" 5 elif (( ${+commands[notifu]} )); then # cygwin - notifu /m "$2" /p "$1" + notifu /m "$message" /p "$title" ${=icon:+/i "$icon"} fi } ## Defaults +# enable terminal bell on notify by default +bgnotify_bell=${bgnotify_bell:-true} + # notify if command took longer than 5s by default bgnotify_threshold=${bgnotify_threshold:-5} diff --git a/plugins/branch/README.md b/plugins/branch/README.md index a15dd22df..2b6d12d29 100644 --- a/plugins/branch/README.md +++ b/plugins/branch/README.md @@ -39,7 +39,7 @@ index 2fd5f2cd..9d89a464 100644 PROMPT="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )" -PROMPT+=' %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)' +PROMPT+=' %{$fg[cyan]%}%c%{$reset_color%} $(branch_prompt_info)' - + ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}git:(%{$fg[red]%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} " ``` diff --git a/plugins/brew/README.md b/plugins/brew/README.md index 4730194bc..299393b28 100644 --- a/plugins/brew/README.md +++ b/plugins/brew/README.md @@ -10,10 +10,12 @@ plugins=(... brew) ## Shellenv -If `brew` is not found in the PATH, this plugin will attempt to find it in common -locations, and execute `brew shellenv` to set the environment appropriately. -This plugin will also export `HOMEBREW_PREFIX="$(brew --prefix)"` if not previously -defined for convenience. +If `brew` is not found in the PATH, this plugin will attempt to find it in common locations, and execute +`brew shellenv` to set the environment appropriately. This plugin will also export +`HOMEBREW_PREFIX="$(brew --prefix)"` if not previously defined for convenience. + +In case you installed `brew` in a non-common location, you can still set `BREW_LOCATION` variable pointing to +the `brew` binary before sourcing `oh-my-zsh.sh` and it'll set up the environment. ## Aliases @@ -33,9 +35,9 @@ defined for convenience. ## Completion -This plugin configures paths with Homebrew's completion functions automatically, so you don't need to do it manually. See: https://docs.brew.sh/Shell-Completion#configuring-completions-in-zsh. +This plugin configures paths with Homebrew's completion functions automatically, so you don't need to do it +manually. See: https://docs.brew.sh/Shell-Completion#configuring-completions-in-zsh. -With the release of Homebrew 1.0, they decided to bundle the zsh completion as part of the -brew installation, so we no longer ship it with the brew plugin; now it only has brew -aliases. If you find that brew completion no longer works, make sure you have your Homebrew -installation fully up to date. +With the release of Homebrew 1.0, they decided to bundle the zsh completion as part of the brew installation, +so we no longer ship it with the brew plugin; now it only has brew aliases. If you find that brew completion +no longer works, make sure you have your Homebrew installation fully up to date. diff --git a/plugins/brew/brew.plugin.zsh b/plugins/brew/brew.plugin.zsh index b52664a39..b15137e0f 100644 --- a/plugins/brew/brew.plugin.zsh +++ b/plugins/brew/brew.plugin.zsh @@ -1,5 +1,10 @@ if (( ! $+commands[brew] )); then - if [[ -x /opt/homebrew/bin/brew ]]; then + if [[ -n "$BREW_LOCATION" ]]; then + if [[ ! -x "$BREW_LOCATION" ]]; then + echo "[oh-my-zsh] $BREW_LOCATION is not executable" + return + fi + elif [[ -x /opt/homebrew/bin/brew ]]; then BREW_LOCATION="/opt/homebrew/bin/brew" elif [[ -x /usr/local/bin/brew ]]; then BREW_LOCATION="/usr/local/bin/brew" @@ -31,7 +36,6 @@ fi alias bcubc='brew upgrade --cask && brew cleanup' alias bcubo='brew update && brew outdated --cask' -alias bcubc='brew upgrade --cask && brew cleanup' alias brewp='brew pin' alias brewsp='brew list --pinned' alias bubc='brew upgrade && brew cleanup' diff --git a/plugins/bun/README.md b/plugins/bun/README.md new file mode 100644 index 000000000..5a312370f --- /dev/null +++ b/plugins/bun/README.md @@ -0,0 +1,20 @@ +# Bun Plugin + +This plugin sets up completion for [Bun](https://bun.sh). + +To use it, add `bun` to the plugins array in your zshrc file: + +```zsh +plugins=(... bun) +``` + +This plugin does not add any aliases. + +## Cache + +This plugin caches the completion script and is automatically updated when the +plugin is loaded, which is usually when you start up a new terminal emulator. + +The cache is stored at: + +- `$ZSH_CACHE_DIR/completions/_bun_` completions script diff --git a/plugins/bun/bun.plugin.zsh b/plugins/bun/bun.plugin.zsh new file mode 100644 index 000000000..9924faa84 --- /dev/null +++ b/plugins/bun/bun.plugin.zsh @@ -0,0 +1,14 @@ +# If Bun is not found, don't do the rest of the script +if (( ! $+commands[bun] )); then + return +fi + +# If the completion file doesn't exist yet, we need to autoload it and +# bind it to `bun`. Otherwise, compinit will have already done that. +if [[ ! -f "$ZSH_CACHE_DIR/completions/_bun" ]]; then + typeset -g -A _comps + autoload -Uz _bun + _comps[bun]=_bun +fi + +bun completions >| "$ZSH_CACHE_DIR/completions/_bun" &| diff --git a/plugins/catimg/README.md b/plugins/catimg/README.md index 8f2688050..68dc33c1f 100644 --- a/plugins/catimg/README.md +++ b/plugins/catimg/README.md @@ -1,6 +1,6 @@ # catimg -Plugin for displaying images on the terminal using the the `catimg.sh` script provided by [posva](https://github.com/posva/catimg) +Plugin for displaying images on the terminal using the `catimg.sh` script provided by [posva](https://github.com/posva/catimg) To use it, add `catimg` to the plugins array in your zshrc file: diff --git a/plugins/chruby/chruby.plugin.zsh b/plugins/chruby/chruby.plugin.zsh index d7a28d4e2..1210897c4 100644 --- a/plugins/chruby/chruby.plugin.zsh +++ b/plugins/chruby/chruby.plugin.zsh @@ -2,7 +2,7 @@ _source-from-omz-settings() { local _chruby_path _chruby_auto - + zstyle -s :omz:plugins:chruby path _chruby_path || return 1 zstyle -s :omz:plugins:chruby auto _chruby_auto || return 1 @@ -23,7 +23,7 @@ _source-from-homebrew() { if [[ -h /usr/local/opt/chruby ]];then _brew_prefix="/usr/local/opt/chruby" else - # ok , it is not default prefix + # ok , it is not default prefix # this call to brew is expensive ( about 400 ms ), so at least let's make it only once _brew_prefix=$(brew --prefix chruby) fi diff --git a/plugins/cloudfoundry/README.md b/plugins/cloudfoundry/README.md index 89dd9d1ce..567a9056b 100644 --- a/plugins/cloudfoundry/README.md +++ b/plugins/cloudfoundry/README.md @@ -50,7 +50,7 @@ Alternatively, seek out the [online documentation][3]. And don't forget, there a ## Contributors -Contributed to `oh_my_zsh` by [benwilcock][2]. +Contributed to `oh_my_zsh` by [benwilcock][2]. [1]: https://docs.cloudfoundry.org/cf-cli/install-go-cli.html [2]: https://github.com/benwilcock diff --git a/plugins/coffee/README.md b/plugins/coffee/README.md index 2baade844..c2ab192b6 100644 --- a/plugins/coffee/README.md +++ b/plugins/coffee/README.md @@ -24,7 +24,7 @@ Also provides the following aliases: * **cfc:** Copies the compiled JS to your clipboard. Very useful when you want to run the code in a JS console. -* **cfp:** Compiles from your currently copied clipboard. Useful when you want +* **cfp:** Compiles from your currently copied clipboard. Useful when you want to compile large/multi-line snippets * **cfpc:** Paste coffeescript from clipboard, compile to JS, then copy the diff --git a/plugins/colored-man-pages/colored-man-pages.plugin.zsh b/plugins/colored-man-pages/colored-man-pages.plugin.zsh index 981992d88..57facbb5c 100644 --- a/plugins/colored-man-pages/colored-man-pages.plugin.zsh +++ b/plugins/colored-man-pages/colored-man-pages.plugin.zsh @@ -36,6 +36,7 @@ function colored() { # Prefer `less` whenever available, since we specifically configured # environment for it. environment+=( PAGER="${commands[less]:-$PAGER}" ) + environment+=( GROFF_NO_SGR=1 ) # See ./nroff script. if [[ "$OSTYPE" = solaris* ]]; then diff --git a/plugins/command-not-found/command-not-found.plugin.zsh b/plugins/command-not-found/command-not-found.plugin.zsh index cb8a8989c..c741e18a2 100644 --- a/plugins/command-not-found/command-not-found.plugin.zsh +++ b/plugins/command-not-found/command-not-found.plugin.zsh @@ -3,9 +3,10 @@ for file ( # Arch Linux. Must have pkgfile installed: https://wiki.archlinux.org/index.php/Pkgfile#Command_not_found /usr/share/doc/pkgfile/command-not-found.zsh - # macOS (M1 and classic Homebrew): https://github.com/Homebrew/homebrew-command-not-found + # Homebrew: https://github.com/Homebrew/homebrew-command-not-found /opt/homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh /usr/local/Homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh + /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh ); do if [[ -r "$file" ]]; then source "$file" diff --git a/plugins/compleat/compleat.plugin.zsh b/plugins/compleat/compleat.plugin.zsh index 38f1b396a..7fbd2b953 100644 --- a/plugins/compleat/compleat.plugin.zsh +++ b/plugins/compleat/compleat.plugin.zsh @@ -7,7 +7,7 @@ if (( ${+commands[compleat]} )); then local prefix="${commands[compleat]:h:h}" - local setup="${prefix}/share/compleat-1.0/compleat_setup" + local setup="${prefix}/share/compleat-1.0/compleat_setup" if [[ -f "$setup" ]]; then if ! bashcompinit >/dev/null 2>&1; then @@ -15,6 +15,6 @@ if (( ${+commands[compleat]} )); then bashcompinit -i fi - source "$setup" + source "$setup" fi fi diff --git a/plugins/copybuffer/copybuffer.plugin.zsh b/plugins/copybuffer/copybuffer.plugin.zsh index e67f920f0..e636d9730 100644 --- a/plugins/copybuffer/copybuffer.plugin.zsh +++ b/plugins/copybuffer/copybuffer.plugin.zsh @@ -1,8 +1,8 @@ -# copy the active line from the command line buffer +# copy the active line from the command line buffer # onto the system clipboard copybuffer () { - if which clipcopy &>/dev/null; then + if builtin which clipcopy &>/dev/null; then printf "%s" "$BUFFER" | clipcopy else zle -M "clipcopy not found. Please make sure you have Oh My Zsh installed correctly." diff --git a/plugins/dash/README.md b/plugins/dash/README.md index 0ca3e4e44..970c6541f 100644 --- a/plugins/dash/README.md +++ b/plugins/dash/README.md @@ -19,7 +19,7 @@ dash - Query for something in dash app: `dash query` ``` -dash golang +dash golang ``` - You can optionally provide a keyword: `dash [keyword:]query` diff --git a/plugins/debian/README.md b/plugins/debian/README.md index c1ebe1c50..6835ad65c 100644 --- a/plugins/debian/README.md +++ b/plugins/debian/README.md @@ -13,7 +13,12 @@ plugins=(... debian) - `$apt_pref`: use aptitude or apt if installed, fallback is apt-get. - `$apt_upgr`: use upgrade or safe-upgrade (for aptitude). -Set `$apt_pref` and `$apt_upgr` to whatever command you want (before sourcing Oh My Zsh) to override this behavior. +Set **both** `$apt_pref` and `$apt_upgr` to whatever command you want (before sourcing Oh My Zsh) to override this behavior, e.g.: + +```sh +apt_pref='apt' +apt_upgr='full-upgrade' +``` ## Common Aliases @@ -21,7 +26,7 @@ Set `$apt_pref` and `$apt_upgr` to whatever command you want (before sourcing Oh | ------ | ---------------------------------------------------------------------- | ---------------------------------------------------------- | | `age` | `apt-get` | Command line tool for handling packages | | `api` | `aptitude` | Same functionality as `apt-get`, provides extra options | -| `acse` | `apt-cache search` | Command line tool for searching apt software package cache | +| `acs` | `apt-cache search` | Command line tool for searching apt software package cache | | `aps` | `aptitude search` | Searches installed packages using aptitude | | `as` | `aptitude -F '* %p -> %d \n(%v/%V)' --no-gui --disable-columns search` | Print searched packages using a custom format | | `afs` | `apt-file search --regexp` | Search file in packages | diff --git a/plugins/debian/debian.plugin.zsh b/plugins/debian/debian.plugin.zsh index bab1ae1c6..5ef4cfb67 100644 --- a/plugins/debian/debian.plugin.zsh +++ b/plugins/debian/debian.plugin.zsh @@ -26,7 +26,7 @@ alias age='apt-get' alias api='aptitude' # Some self-explanatory aliases -alias acse="apt-cache search" +alias acs="apt-cache search" alias aps='aptitude search' alias as="aptitude -F '* %p -> %d \n(%v/%V)' --no-gui --disable-columns search" diff --git a/plugins/direnv/direnv.plugin.zsh b/plugins/direnv/direnv.plugin.zsh index 5e32c4c23..0a33194dd 100644 --- a/plugins/direnv/direnv.plugin.zsh +++ b/plugins/direnv/direnv.plugin.zsh @@ -7,10 +7,10 @@ _direnv_hook() { trap - SIGINT; } typeset -ag precmd_functions; -if [[ -z ${precmd_functions[(r)_direnv_hook]} ]]; then +if [[ -z "${precmd_functions[(r)_direnv_hook]+1}" ]]; then precmd_functions=( _direnv_hook ${precmd_functions[@]} ) fi typeset -ag chpwd_functions; -if [[ -z ${chpwd_functions[(r)_direnv_hook]} ]]; then +if [[ -z "${chpwd_functions[(r)_direnv_hook]+1}" ]]; then chpwd_functions=( _direnv_hook ${chpwd_functions[@]} ) fi diff --git a/plugins/dnf/README.md b/plugins/dnf/README.md index dc0d1e0a0..f45c8778c 100644 --- a/plugins/dnf/README.md +++ b/plugins/dnf/README.md @@ -10,6 +10,9 @@ To use it, add `dnf` to the plugins array in your zshrc file: plugins=(... dnf) ``` +Classic `dnf` is getting superseded by `dnf5`; this plugin detects the presence +of `dnf5` and uses it as drop-in alternative to the slower `dnf`. + ## Aliases | Alias | Command | Description | diff --git a/plugins/dnf/dnf.plugin.zsh b/plugins/dnf/dnf.plugin.zsh index 653ce7dda..642422fe1 100644 --- a/plugins/dnf/dnf.plugin.zsh +++ b/plugins/dnf/dnf.plugin.zsh @@ -1,15 +1,19 @@ ## Aliases +local dnfprog="dnf" -alias dnfl="dnf list" # List packages -alias dnfli="dnf list installed" # List installed packages -alias dnfgl="dnf grouplist" # List package groups -alias dnfmc="dnf makecache" # Generate metadata cache -alias dnfp="dnf info" # Show package information -alias dnfs="dnf search" # Search package +# Prefer dnf5 if installed +command -v dnf5 > /dev/null && dnfprog=dnf5 -alias dnfu="sudo dnf upgrade" # Upgrade package -alias dnfi="sudo dnf install" # Install package -alias dnfgi="sudo dnf groupinstall" # Install package group -alias dnfr="sudo dnf remove" # Remove package -alias dnfgr="sudo dnf groupremove" # Remove package group -alias dnfc="sudo dnf clean all" # Clean cache +alias dnfl="${dnfprog} list" # List packages +alias dnfli="${dnfprog} list installed" # List installed packages +alias dnfgl="${dnfprog} grouplist" # List package groups +alias dnfmc="${dnfprog} makecache" # Generate metadata cache +alias dnfp="${dnfprog} info" # Show package information +alias dnfs="${dnfprog} search" # Search package + +alias dnfu="sudo ${dnfprog} upgrade" # Upgrade package +alias dnfi="sudo ${dnfprog} install" # Install package +alias dnfgi="sudo ${dnfprog} groupinstall" # Install package group +alias dnfr="sudo ${dnfprog} remove" # Remove package +alias dnfgr="sudo ${dnfprog} groupremove" # Remove package group +alias dnfc="sudo ${dnfprog} clean all" # Clean cache diff --git a/plugins/docker-compose/README.md b/plugins/docker-compose/README.md index bbcff2e0c..66d4e0521 100644 --- a/plugins/docker-compose/README.md +++ b/plugins/docker-compose/README.md @@ -11,23 +11,24 @@ plugins=(... docker-compose) ## Aliases -| Alias | Command | Description | -|-----------|--------------------------------|----------------------------------------------------------------------------------| -| dco | `docker-compose` | Docker-compose main command | -| dcb | `docker-compose build` | Build containers | -| dce | `docker-compose exec` | Execute command inside a container | -| dcps | `docker-compose ps` | List containers | -| dcrestart | `docker-compose restart` | Restart container | -| dcrm | `docker-compose rm` | Remove container | -| dcr | `docker-compose run` | Run a command in container | -| dcstop | `docker-compose stop` | Stop a container | -| dcup | `docker-compose up` | Build, (re)create, start, and attach to containers for a service | -| dcupb | `docker-compose up --build` | Same as `dcup`, but build images before starting containers | -| dcupd | `docker-compose up -d` | Same as `dcup`, but starts as daemon | -| dcupdb | `docker-compose up -d --build` | Same as `dcup`, but build images before starting containers and starts as daemon | -| dcdn | `docker-compose down` | Stop and remove containers | -| dcl | `docker-compose logs` | Show logs of container | -| dclf | `docker-compose logs -f` | Show logs and follow output | -| dcpull | `docker-compose pull` | Pull image of a service | -| dcstart | `docker-compose start` | Start a container | -| dck | `docker-compose kill` | Kills containers | +| Alias | Command | Description | +|-----------|----------------------------------|----------------------------------------------------------------------------------| +| dco | `docker-compose` | Docker-compose main command | +| dcb | `docker-compose build` | Build containers | +| dce | `docker-compose exec` | Execute command inside a container | +| dcps | `docker-compose ps` | List containers | +| dcrestart | `docker-compose restart` | Restart container | +| dcrm | `docker-compose rm` | Remove container | +| dcr | `docker-compose run` | Run a command in container | +| dcstop | `docker-compose stop` | Stop a container | +| dcup | `docker-compose up` | Build, (re)create, start, and attach to containers for a service | +| dcupb | `docker-compose up --build` | Same as `dcup`, but build images before starting containers | +| dcupd | `docker-compose up -d` | Same as `dcup`, but starts as daemon | +| dcupdb | `docker-compose up -d --build` | Same as `dcup`, but build images before starting containers and starts as daemon | +| dcdn | `docker-compose down` | Stop and remove containers | +| dcl | `docker-compose logs` | Show logs of container | +| dclf | `docker-compose logs -f` | Show logs and follow output | +| dclF | `docker-compose logs -f --tail0` | Just follow recent logs | +| dcpull | `docker-compose pull` | Pull image of a service | +| dcstart | `docker-compose start` | Start a container | +| dck | `docker-compose kill` | Kills containers | diff --git a/plugins/docker-compose/_docker-compose b/plugins/docker-compose/_docker-compose index c6b733500..d0ebfe515 100644 --- a/plugins/docker-compose/_docker-compose +++ b/plugins/docker-compose/_docker-compose @@ -128,7 +128,7 @@ __docker-compose_subcommand() { '--resolve-image-digests[Pin image tags to digests.]' \ '--services[Print the service names, one per line.]' \ '--volumes[Print the volume names, one per line.]' \ - '--hash[Print the service config hash, one per line. Set "service1,service2" for a list of specified services.]' \ && ret=0 + '--hash[Print the service config hash, one per line. Set "service1,service2" for a list of specified services.]' && ret=0 ;; (create) _arguments \ diff --git a/plugins/docker-compose/docker-compose.plugin.zsh b/plugins/docker-compose/docker-compose.plugin.zsh index 7a8bf4a03..d1823f535 100644 --- a/plugins/docker-compose/docker-compose.plugin.zsh +++ b/plugins/docker-compose/docker-compose.plugin.zsh @@ -16,6 +16,7 @@ alias dcupdb="$dccmd up -d --build" alias dcdn="$dccmd down" alias dcl="$dccmd logs" alias dclf="$dccmd logs -f" +alias dclF="$dccmd logs -f --tail 0" alias dcpull="$dccmd pull" alias dcstart="$dccmd start" alias dck="$dccmd kill" diff --git a/plugins/docker/README.md b/plugins/docker/README.md index 512b5d17c..0ab2e41fb 100644 --- a/plugins/docker/README.md +++ b/plugins/docker/README.md @@ -30,6 +30,15 @@ file**, but be aware of the side effects: > zstyle ':completion:*:*:docker-*:*' option-stacking yes > ``` +### Use old-style completion + +If the current completion does not work well for you, you can enable legacy completion instead with the +following setting. See https://github.com/ohmyzsh/ohmyzsh/issues/11789 for more information. + +```zsh +zstyle ':omz:plugins:docker' legacy-completion yes +``` + ## Aliases | Alias | Command | Description | @@ -58,7 +67,7 @@ file**, but be aware of the side effects: | drm | `docker container rm` | Remove the specified container(s) | | drm! | `docker container rm -f` | Force the removal of a running container (uses SIGKILL) | | dst | `docker container start` | Start one or more stopped containers | -| drs | `docker container restart` | Restart one or more containers +| drs | `docker container restart` | Restart one or more containers | | dsta | `docker stop $(docker ps -q)` | Stop all running containers | | dstp | `docker container stop` | Stop one or more running containers | | dtop | `docker top` | Display the running processes of a container | diff --git a/plugins/docker/completions/_docker b/plugins/docker/completions/_docker new file mode 100644 index 000000000..466b09d94 --- /dev/null +++ b/plugins/docker/completions/_docker @@ -0,0 +1,3126 @@ +#compdef docker dockerd +# +# zsh completion for docker (http://docker.com) +# +# version: 0.3.0 +# github: https://github.com/felixr/docker-zsh-completion +# +# contributors: +# - Felix Riedel +# - Steve Durrheimer +# - Vincent Bernat +# - Rohan Verma +# +# license: +# +# Copyright (c) 2013, Felix Riedel +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +# Short-option stacking can be enabled with: +# zstyle ':completion:*:*:docker:*' option-stacking yes +# zstyle ':completion:*:*:docker-*:*' option-stacking yes +__docker_arguments() { + if zstyle -t ":completion:${curcontext}:" option-stacking; then + print -- -s + fi +} + +__docker_get_containers() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local kind type line s + declare -a running stopped lines args names + + kind=$1; shift + type=$1; shift + [[ $kind = (stopped|all) ]] && args=($args -a) + + lines=(${(f)${:-"$(_call_program commands docker $docker_options ps --format 'table' --no-trunc $args)"$'\n'}}) + + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 # Last column, should go to the end of the line + lines=(${lines[2,-1]}) + + # Container ID + if [[ $type = (ids|all) ]]; then + for line in $lines; do + s="${${line[${begin[CONTAINER ID]},${end[CONTAINER ID]}]%% ##}[0,12]}" + s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}" + s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}" + if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = (Exit*|Created*) ]]; then + stopped=($stopped $s) + else + running=($running $s) + fi + done + fi + + # Names: we only display the one without slash. All other names + # are generated and may clutter the completion. However, with + # Swarm, all names may be prefixed by the swarm node name. + if [[ $type = (names|all) ]]; then + for line in $lines; do + names=(${(ps:,:)${${line[${begin[NAMES]},${end[NAMES]}]}%% *}}) + # First step: find a common prefix and strip it (swarm node case) + (( ${#${(u)names%%/*}} == 1 )) && names=${names#${names[1]%%/*}/} + # Second step: only keep the first name without a / + s=${${names:#*/*}[1]} + # If no name, well give up. + (( $#s != 0 )) || continue + s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}" + s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}" + if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = (Exit*|Created*) ]]; then + stopped=($stopped $s) + else + running=($running $s) + fi + done + fi + + [[ $kind = (running|all) ]] && _describe -t containers-running "running containers" running "$@" && ret=0 + [[ $kind = (stopped|all) ]] && _describe -t containers-stopped "stopped containers" stopped "$@" && ret=0 + return ret +} + +__docker_complete_stopped_containers() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_containers stopped all "$@" +} + +__docker_complete_running_containers() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_containers running all "$@" +} + +__docker_complete_containers() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_containers all all "$@" +} + +__docker_complete_containers_ids() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_containers all ids "$@" +} + +__docker_complete_containers_names() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_containers all names "$@" +} + +__docker_complete_info_plugins() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + emulate -L zsh + setopt extendedglob + local -a plugins + plugins=(${(ps: :)${(M)${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Plugins:}%%$'\n'^ *}}:# $1: *}## $1: }) + _describe -t plugins "$1 plugins" plugins && ret=0 + return ret +} + +__docker_complete_images() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a images + images=(${${${(f)${:-"$(_call_program commands docker $docker_options images)"$'\n'}}[2,-1]}/(#b)([^ ]##) ##([^ ]##) ##([^ ]##)*/${match[3]}:${(r:15:: :::)match[2]} in ${match[1]}}) + _describe -t docker-images "images" images && ret=0 + __docker_complete_repositories_with_tags && ret=0 + return ret +} + +__docker_complete_repositories() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a repos + repos=(${${${(f)${:-"$(_call_program commands docker $docker_options images)"$'\n'}}%% *}[2,-1]}) + repos=(${repos#}) + _describe -t docker-repos "repositories" repos && ret=0 + return ret +} + +__docker_complete_repositories_with_tags() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a repos onlyrepos matched + declare m + repos=(${${${${(f)${:-"$(_call_program commands docker $docker_options images)"$'\n'}}[2,-1]}/ ##/:::}%% *}) + repos=(${${repos%:::}#}) + # Check if we have a prefix-match for the current prefix. + onlyrepos=(${repos%::*}) + for m in $onlyrepos; do + [[ ${PREFIX##${~~m}} != ${PREFIX} ]] && { + # Yes, complete with tags + repos=(${${repos/:::/:}/:/\\:}) + _describe -t docker-repos-with-tags "repositories with tags" repos && ret=0 + return ret + } + done + # No, only complete repositories + onlyrepos=(${${repos%:::*}/:/\\:}) + _describe -t docker-repos "repositories" onlyrepos -qS : && ret=0 + + return ret +} + +__docker_search() { + [[ $PREFIX = -* ]] && return 1 + local cache_policy + zstyle -s ":completion:${curcontext}:" cache-policy cache_policy + if [[ -z "$cache_policy" ]]; then + zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy + fi + + local searchterm cachename + searchterm="${words[$CURRENT]%/}" + cachename=_docker-search-$searchterm + + local expl + local -a result + if ( [[ ${(P)+cachename} -eq 0 ]] || _cache_invalid ${cachename#_} ) \ + && ! _retrieve_cache ${cachename#_}; then + _message "Searching for ${searchterm}..." + result=(${${${(f)${:-"$(_call_program commands docker $docker_options search $searchterm)"$'\n'}}%% *}[2,-1]}) + _store_cache ${cachename#_} result + fi + _wanted dockersearch expl 'available images' compadd -a result +} + +__docker_get_log_options() { + [[ $PREFIX = -* ]] && return 1 + + integer ret=1 + local log_driver=${opt_args[--log-driver]:-"all"} + local -a common_options common_options2 awslogs_options fluentd_options gelf_options journald_options json_file_options logentries_options syslog_options splunk_options + + common_options=("max-buffer-size" "mode") + common_options2=("env" "env-regex" "labels") + awslogs_options=($common_options "awslogs-create-group" "awslogs-datetime-format" "awslogs-group" "awslogs-multiline-pattern" "awslogs-region" "awslogs-stream" "tag") + fluentd_options=($common_options $common_options2 "fluentd-address" "fluentd-async-connect" "fluentd-buffer-limit" "fluentd-retry-wait" "fluentd-max-retries" "fluentd-sub-second-precision" "tag") + gcplogs_options=($common_options $common_options2 "gcp-log-cmd" "gcp-meta-id" "gcp-meta-name" "gcp-meta-zone" "gcp-project") + gelf_options=($common_options $common_options2 "gelf-address" "gelf-compression-level" "gelf-compression-type" "tag") + journald_options=($common_options $common_options2 "tag") + json_file_options=($common_options $common_options2 "max-file" "max-size") + logentries_options=($common_options $common_options2 "logentries-token" "tag") + syslog_options=($common_options $common_options2 "syslog-address" "syslog-facility" "syslog-format" "syslog-tls-ca-cert" "syslog-tls-cert" "syslog-tls-key" "syslog-tls-skip-verify" "tag") + splunk_options=($common_options $common_options2 "splunk-caname" "splunk-capath" "splunk-format" "splunk-gzip" "splunk-gzip-level" "splunk-index" "splunk-insecureskipverify" "splunk-source" "splunk-sourcetype" "splunk-token" "splunk-url" "splunk-verify-connection" "tag") + + [[ $log_driver = (awslogs|all) ]] && _describe -t awslogs-options "awslogs options" awslogs_options "$@" && ret=0 + [[ $log_driver = (fluentd|all) ]] && _describe -t fluentd-options "fluentd options" fluentd_options "$@" && ret=0 + [[ $log_driver = (gcplogs|all) ]] && _describe -t gcplogs-options "gcplogs options" gcplogs_options "$@" && ret=0 + [[ $log_driver = (gelf|all) ]] && _describe -t gelf-options "gelf options" gelf_options "$@" && ret=0 + [[ $log_driver = (journald|all) ]] && _describe -t journald-options "journald options" journald_options "$@" && ret=0 + [[ $log_driver = (json-file|all) ]] && _describe -t json-file-options "json-file options" json_file_options "$@" && ret=0 + [[ $log_driver = (logentries|all) ]] && _describe -t logentries-options "logentries options" logentries_options "$@" && ret=0 + [[ $log_driver = (syslog|all) ]] && _describe -t syslog-options "syslog options" syslog_options "$@" && ret=0 + [[ $log_driver = (splunk|all) ]] && _describe -t splunk-options "splunk options" splunk_options "$@" && ret=0 + + return ret +} + +__docker_complete_log_drivers() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + drivers=(awslogs etwlogs fluentd gcplogs gelf journald json-file none splunk syslog) + _describe -t log-drivers "log drivers" drivers && ret=0 + return ret +} + +__docker_complete_log_options() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (syslog-format) + local opts=('rfc3164' 'rfc5424' 'rfc5424micro') + _describe -t syslog-format-opts "syslog format options" opts && ret=0 + ;; + (mode) + local opts=('blocking' 'non-blocking') + _describe -t mode-opts "mode options" opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + __docker_get_log_options -qS "=" && ret=0 + fi + + return ret +} + +__docker_complete_detach_keys() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + compset -P "*," + keys=(${:-{a-z}}) + ctrl_keys=(${:-ctrl-{{a-z},{@,'[','\\','^',']',_}}}) + _describe -t detach_keys "[a-z]" keys -qS "," && ret=0 + _describe -t detach_keys-ctrl "'ctrl-' + 'a-z @ [ \\\\ ] ^ _'" ctrl_keys -qS "," && ret=0 +} + +__docker_complete_pid() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local -a opts vopts + + opts=('host') + vopts=('container') + + if compset -P '*:'; then + case "${${words[-1]%:*}#*=}" in + (container) + __docker_complete_running_containers && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + _describe -t pid-value-opts "PID Options with value" vopts -qS ":" && ret=0 + _describe -t pid-opts "PID Options" opts && ret=0 + fi + + return ret +} + +__docker_complete_runtimes() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + emulate -L zsh + setopt extendedglob + local -a runtimes_opts + runtimes_opts=(${(ps: :)${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Runtimes: }%%$'\n'^ *}}}) + _describe -t runtimes-opts "runtimes options" runtimes_opts && ret=0 +} + +__docker_complete_ps_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (ancestor) + __docker_complete_images && ret=0 + ;; + (before|since) + __docker_complete_containers && ret=0 + ;; + (health) + health_opts=('healthy' 'none' 'starting' 'unhealthy') + _describe -t health-filter-opts "health filter options" health_opts && ret=0 + ;; + (id) + __docker_complete_containers_ids && ret=0 + ;; + (is-task) + _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0 + ;; + (name) + __docker_complete_containers_names && ret=0 + ;; + (network) + __docker_complete_networks && ret=0 + ;; + (status) + status_opts=('created' 'dead' 'exited' 'paused' 'restarting' 'running' 'removing') + _describe -t status-filter-opts "status filter options" status_opts && ret=0 + ;; + (volume) + __docker_complete_volumes && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('ancestor' 'before' 'exited' 'expose' 'health' 'id' 'label' 'name' 'network' 'publish' 'since' 'status' 'volume') + _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_complete_search_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a boolean_opts opts + + boolean_opts=('true' 'false') + opts=('is-automated' 'is-official' 'stars') + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (is-automated|is-official) + _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_complete_images_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a boolean_opts opts + + boolean_opts=('true' 'false') + opts=('before' 'dangling' 'label' 'reference' 'since') + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (before|reference|since) + __docker_complete_images && ret=0 + ;; + (dangling) + _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_complete_events_filter() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a opts + + opts=('container' 'daemon' 'event' 'image' 'label' 'network' 'scope' 'type' 'volume') + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (container) + __docker_complete_containers && ret=0 + ;; + (daemon) + emulate -L zsh + setopt extendedglob + local -a daemon_opts + daemon_opts=( + ${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Name: }%%$'\n'^ *}} + ${${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'ID: }%%$'\n'^ *}}//:/\\:} + ) + _describe -t daemon-filter-opts "daemon filter options" daemon_opts && ret=0 + ;; + (event) + local -a event_opts + event_opts=('attach' 'commit' 'connect' 'copy' 'create' 'delete' 'destroy' 'detach' 'die' 'disable' 'disconnect' 'enable' 'exec_create' 'exec_detach' + 'exec_start' 'export' 'health_status' 'import' 'install' 'kill' 'load' 'mount' 'oom' 'pause' 'pull' 'push' 'reload' 'remove' 'rename' 'resize' + 'restart' 'save' 'start' 'stop' 'tag' 'top' 'unmount' 'unpause' 'untag' 'update') + _describe -t event-filter-opts "event filter options" event_opts && ret=0 + ;; + (image) + __docker_complete_images && ret=0 + ;; + (network) + __docker_complete_networks && ret=0 + ;; + (scope) + local -a scope_opts + scope_opts=('local' 'swarm') + _describe -t scope-filter-opts "scope filter options" scope_opts && ret=0 + ;; + (type) + local -a type_opts + type_opts=('container' 'daemon' 'image' 'network' 'volume') + _describe -t type-filter-opts "type filter options" type_opts && ret=0 + ;; + (volume) + __docker_complete_volumes && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_complete_prune_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a opts + + opts=('until') + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + *) + _message 'value' && ret=0 + ;; + esac + else + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +# BO checkpoint + +__docker_checkpoint_commands() { + local -a _docker_checkpoint_subcommands + _docker_checkpoint_subcommands=( + "create:Create a checkpoint from a running container" + "ls:List checkpoints for a container" + "rm:Remove a checkpoint" + ) + _describe -t docker-checkpoint-commands "docker checkpoint command" _docker_checkpoint_subcommands +} + +__docker_checkpoint_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (create) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--checkpoint-dir=[Use a custom checkpoint storage directory]:dir:_directories" \ + "($help)--leave-running[Leave the container running after checkpoint]" \ + "($help -)1:container:__docker_complete_running_containers" \ + "($help -)2:checkpoint: " && ret=0 + ;; + (ls|list) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--checkpoint-dir=[Use a custom checkpoint storage directory]:dir:_directories" \ + "($help -)1:container:__docker_complete_containers" && ret=0 + ;; + (rm|remove) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--checkpoint-dir=[Use a custom checkpoint storage directory]:dir:_directories" \ + "($help -)1:container:__docker_complete_containers" \ + "($help -)2:checkpoint: " && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_checkpoint_commands" && ret=0 + ;; + esac + + return ret +} + +# EO checkpoint + +# BO container + +__docker_container_commands() { + local -a _docker_container_subcommands + _docker_container_subcommands=( + "attach:Attach to a running container" + "commit:Create a new image from a container's changes" + "cp:Copy files/folders between a container and the local filesystem" + "create:Create a new container" + "diff:Inspect changes on a container's filesystem" + "exec:Execute a command in a running container" + "export:Export a container's filesystem as a tar archive" + "inspect:Display detailed information on one or more containers" + "kill:Kill one or more running containers" + "logs:Fetch the logs of a container" + "ls:List containers" + "pause:Pause all processes within one or more containers" + "port:List port mappings or a specific mapping for the container" + "prune:Remove all stopped containers" + "rename:Rename a container" + "restart:Restart one or more containers" + "rm:Remove one or more containers" + "run:Create and run a new container from an image" + "start:Start one or more stopped containers" + "stats:Display a live stream of container(s) resource usage statistics" + "stop:Stop one or more running containers" + "top:Display the running processes of a container" + "unpause:Unpause all processes within one or more containers" + "update:Update configuration of one or more containers" + "wait:Block until one or more containers stop, then print their exit codes" + ) + _describe -t docker-container-commands "docker container command" _docker_container_subcommands +} + +__docker_container_subcommand() { + local -a _command_args opts_help opts_attach_exec_run_start opts_create_run opts_create_run_update + local expl help="--help" + integer ret=1 + + opts_attach_exec_run_start=( + "($help)--detach-keys=[Escape key sequence used to detach a container]:sequence:__docker_complete_detach_keys" + ) + opts_create_run=( + "($help -a --attach)"{-a=,--attach=}"[Attach to stdin, stdout or stderr]:device:(STDIN STDOUT STDERR)" + "($help)*--add-host=[Add a custom host-to-IP mapping]:host\:ip mapping: " + "($help)*--annotation=[Add an annotation to the container (passed through to the OCI runtime)]:annotations: " + "($help)*--blkio-weight-device=[Block IO (relative device weight)]:device:Block IO weight: " + "($help)*--cap-add=[Add Linux capabilities]:capability: " + "($help)*--cap-drop=[Drop Linux capabilities]:capability: " + "($help)--cgroupns=[Cgroup namespace mode to use]:cgroup namespace mode: " + "($help)--cgroup-parent=[Parent cgroup for the container]:cgroup: " + "($help)--cidfile=[Write the container ID to the file]:CID file:_files" + "($help)--cpus=[Number of CPUs (default 0.000)]:cpus: " + "($help)*--device=[Add a host device to the container]:device:_files" + "($help)*--device-cgroup-rule=[Add a rule to the cgroup allowed devices list]:device:cgroup: " + "($help)*--device-read-bps=[Limit the read rate (bytes per second) from a device]:device:IO rate: " + "($help)*--device-read-iops=[Limit the read rate (IO per second) from a device]:device:IO rate: " + "($help)*--device-write-bps=[Limit the write rate (bytes per second) to a device]:device:IO rate: " + "($help)*--device-write-iops=[Limit the write rate (IO per second) to a device]:device:IO rate: " + "($help)--disable-content-trust[Skip image verification]" + "($help)*--dns=[Custom DNS servers]:DNS server: " + "($help)*--dns-option=[Custom DNS options]:DNS option: " + "($help)*--dns-search=[Custom DNS search domains]:DNS domains: " + "($help)*--domainname=[Container NIS domain name]:domainname:_hosts" + "($help)*"{-e=,--env=}"[Environment variables]:environment variable: " + "($help)--entrypoint=[Overwrite the default entrypoint of the image]:entry point: " + "($help)*--env-file=[Read environment variables from a file]:environment file:_files" + "($help)*--expose=[Expose a port from the container without publishing it]: " + "($help)*--gpus=[GPU devices to add to the container ('all' to pass all GPUs)]:device: " + "($help)*--group-add=[Set one or more supplementary user groups for the container]:group:_groups" + "($help -h --hostname)"{-h=,--hostname=}"[Container host name]:hostname:_hosts" + "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" + "($help)--init[Run an init inside the container that forwards signals and reaps processes]" + "($help)--ip=[IPv4 address]:IPv4: " + "($help)--ip6=[IPv6 address]:IPv6: " + "($help)--ipc=[IPC namespace to use]:IPC namespace: " + "($help)--isolation=[Container isolation technology]:isolation:(default hyperv process)" + "($help)*--link=[Add link to another container]:link:->link" + "($help)*--link-local-ip=[Container IPv4/IPv6 link-local addresses]:IPv4/IPv6: " + "($help)*"{-l=,--label=}"[Container metadata]:label: " + "($help)--log-driver=[Default driver for container logs]:logging driver:__docker_complete_log_drivers" + "($help)*--log-opt=[Log driver specific options]:log driver options:__docker_complete_log_options" + "($help)--mac-address=[Container MAC address]:MAC address: " + "($help)*--mount=[Attach a filesystem mount to the container]:mount: " + "($help)--name=[Container name]:name: " + "($help)--network=[Connect a container to a network]:network mode:(bridge none container host)" + "($help)*--network-alias=[Add network-scoped alias for the container]:alias: " + "($help)--oom-kill-disable[Disable OOM Killer]" + "($help)--oom-score-adj[Tune the host's OOM preferences for containers (accepts -1000 to 1000)]" + "($help)--pids-limit[Tune container pids limit (set -1 for unlimited)]" + "($help -P --publish-all)"{-P,--publish-all}"[Publish all exposed ports]" + "($help)*"{-p=,--publish=}"[Expose a container's port to the host]:port:_ports" + "($help)--pid=[PID namespace to use]:PID namespace:__docker_complete_pid" + "($help)--privileged[Give extended privileges to this container]" + "($help -q --quiet)"{-q,--quiet}"[Suppress the pull output]" + "($help)--read-only[Mount the container's root filesystem as read only]" + "($help)*--security-opt=[Security options]:security option: " + "($help)*--shm-size=[Size of '/dev/shm' (format is '')]:shm size: " + "($help)--stop-signal=[Signal to kill a container]:signal:_signals" + "($help)--stop-timeout=[Timeout (in seconds) to stop a container]:time: " + "($help)*--sysctl=-[sysctl options]:sysctl: " + "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" + "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" + "($help)*--ulimit=[ulimit options]:ulimit: " + "($help)--userns=[Container user namespace]:user namespace:(host)" + "($help)--tmpfs[mount tmpfs]" + "($help)*-v[Bind mount a volume]:volume:_directories -W / -P '/' -S '\:' -r '/ '" + "($help)--volume-driver=[Optional volume driver for the container]:volume driver:(local)" + "($help)*--volumes-from=[Mount volumes from the specified container]:volume: " + "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories" + ) + opts_create_run_update=( + "($help)--blkio-weight=[Block IO (relative weight), between 10 and 1000]:Block IO weight:(10 100 500 1000)" + "($help -c --cpu-shares)"{-c=,--cpu-shares=}"[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)" + "($help)--cpu-period=[Limit the CPU CFS (Completely Fair Scheduler) period]:CPU period: " + "($help)--cpu-quota=[Limit the CPU CFS (Completely Fair Scheduler) quota]:CPU quota: " + "($help)--cpu-rt-period=[Limit the CPU real-time period]:CPU real-time period in microseconds: " + "($help)--cpu-rt-runtime=[Limit the CPU real-time runtime]:CPU real-time runtime in microseconds: " + "($help)--cpuset-cpus=[CPUs in which to allow execution]:CPUs: " + "($help)--cpuset-mems=[MEMs in which to allow execution]:MEMs: " + "($help)--kernel-memory=[Kernel memory limit in bytes]:Memory limit: " + "($help -m --memory)"{-m=,--memory=}"[Memory limit]:Memory limit: " + "($help)--memory-reservation=[Memory soft limit]:Memory limit: " + "($help)--memory-swap=[Total memory limit with swap]:Memory limit: " + "($help)--pids-limit[Tune container pids limit (set -1 for unlimited)]" + "($help)--restart=[Restart policy]:restart policy:(no on-failure always unless-stopped)" + ) + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (attach) + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_attach_exec_run_start \ + "($help)--no-stdin[Do not attach stdin]" \ + "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \ + "($help -):containers:__docker_complete_running_containers" && ret=0 + ;; + (commit) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --author)"{-a=,--author=}"[Author]:author: " \ + "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \ + "($help -m --message)"{-m=,--message=}"[Commit message]:message: " \ + "($help -p --pause)"{-p,--pause}"[Pause container during commit]" \ + "($help -):container:__docker_complete_containers" \ + "($help -): :__docker_complete_repositories_with_tags" && ret=0 + ;; + (cp) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -L --follow-link)"{-L,--follow-link}"[Always follow symbol link]" \ + "($help -)1:container:->container" \ + "($help -)2:hostpath:_files" && ret=0 + case $state in + (container) + if compset -P "*:"; then + _files && ret=0 + else + __docker_complete_containers -qS ":" && ret=0 + fi + ;; + esac + ;; + (create) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_create_run \ + $opts_create_run_update \ + "($help -): :__docker_complete_images" \ + "($help -):command: _command_names -e" \ + "($help -)*::arguments: _normal" && ret=0 + case $state in + (link) + if compset -P "*:"; then + _wanted alias expl "Alias" compadd -E "" && ret=0 + else + __docker_complete_running_containers -qS ":" && ret=0 + fi + ;; + esac + ;; + (diff) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:containers:__docker_complete_containers" && ret=0 + ;; + (exec) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_attach_exec_run_start \ + "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \ + "($help)*"{-e=,--env=}"[Set environment variables]:environment variable: " \ + "($help)*--env-file=[Read environment variables from a file]:environment file:_files" \ + "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" \ + "($help)--privileged[Give extended Linux capabilities to the command]" \ + "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" \ + "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" \ + "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories" \ + "($help -):containers:__docker_complete_running_containers" \ + "($help -)*::command:->anycommand" && ret=0 + case $state in + (anycommand) + shift 1 words + (( CURRENT-- )) + _normal && ret=0 + ;; + esac + ;; + (export) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -o --output)"{-o=,--output=}"[Write to a file, instead of stdout]:output file:_files" \ + "($help -)*:containers:__docker_complete_containers" && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ + "($help -s --size)"{-s,--size}"[Display total file sizes]" \ + "($help -)*:containers:__docker_complete_containers" && ret=0 + ;; + (kill) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -s --signal)"{-s=,--signal=}"[Signal to send]:signal:_signals" \ + "($help -)*:containers:__docker_complete_running_containers" && ret=0 + ;; + (logs) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--details[Show extra details provided to logs]" \ + "($help -f --follow)"{-f,--follow}"[Follow log output]" \ + "($help -s --since)"{-s=,--since=}"[Show logs since this timestamp]:timestamp: " \ + "($help -t --timestamps)"{-t,--timestamps}"[Show timestamps]" \ + "($help -n --tail)"{-n=,--tail=}"[Number of lines to show from the end of the logs]:lines:(1 10 20 50 all)" \ + "($help -)*:containers:__docker_complete_containers" && ret=0 + ;; + (ls|list) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Show all containers]" \ + "($help)--before=[Show only container created before...]:containers:__docker_complete_containers" \ + "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_ps_filters" \ + "($help)--format=[Format the output using the given Go template]:template: " \ + "($help -l --latest)"{-l,--latest}"[Show only the latest created container]" \ + "($help -n --last)"{-n=,--last=}"[Show n last created containers (includes all states)]:n:(1 5 10 25 50)" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -q --quiet)"{-q,--quiet}"[Only show container IDs]" \ + "($help -s --size)"{-s,--size}"[Display total file sizes]" \ + "($help)--since=[Show only containers created since...]:containers:__docker_complete_containers" && ret=0 + ;; + (pause|unpause) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:containers:__docker_complete_running_containers" && ret=0 + ;; + (port) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)1:containers:__docker_complete_running_containers" \ + "($help -)2:port:_ports" && ret=0 + ;; + (prune) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ + "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 + ;; + (rename) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -):old name:__docker_complete_containers" \ + "($help -):new name: " && ret=0 + ;; + (restart) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -t --time)"{-t=,--time=}"[Number of seconds to try to stop for before killing the container]:seconds to before killing:(1 5 10 30 60)" \ + "($help -)*:containers:__docker_complete_containers" && ret=0 + ;; + (rm) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --force)"{-f,--force}"[Force removal]" \ + "($help -l --link)"{-l,--link}"[Remove the specified link and not the underlying container]" \ + "($help -v --volumes)"{-v,--volumes}"[Remove the volumes associated to the container]" \ + "($help -)*:containers:->values" && ret=0 + case $state in + (values) + if [[ ${words[(r)-f]} == -f || ${words[(r)--force]} == --force ]]; then + __docker_complete_containers && ret=0 + else + __docker_complete_stopped_containers && ret=0 + fi + ;; + esac + ;; + (run) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_create_run \ + $opts_create_run_update \ + $opts_attach_exec_run_start \ + "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \ + "($help)--health-cmd=[Command to run to check health]:command: " \ + "($help)--health-interval=[Time between running the check]:time: " \ + "($help)--health-retries=[Consecutive failures needed to report unhealthy]:retries:(1 2 3 4 5)" \ + "($help)--health-timeout=[Maximum time to allow one check to run]:time: " \ + "($help)--no-healthcheck[Disable any container-specified HEALTHCHECK]" \ + "($help)--rm[Remove intermediate containers when it exits]" \ + "($help)--runtime=[Name of the runtime to be used for that container]:runtime:__docker_complete_runtimes" \ + "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \ + "($help)--storage-opt=[Storage driver options for the container]:storage options:->storage-opt" \ + "($help -): :__docker_complete_images" \ + "($help -):command: _command_names -e" \ + "($help -)*::arguments: _normal" && ret=0 + case $state in + (link) + if compset -P "*:"; then + _wanted alias expl "Alias" compadd -E "" && ret=0 + else + __docker_complete_running_containers -qS ":" && ret=0 + fi + ;; + (storage-opt) + if compset -P "*="; then + _message "value" && ret=0 + else + opts=('size') + _describe -t filter-opts "storage options" opts -qS "=" && ret=0 + fi + ;; + esac + ;; + (start) + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_attach_exec_run_start \ + "($help -a --attach)"{-a,--attach}"[Attach container's stdout/stderr and forward all signals]" \ + "($help -i --interactive)"{-i,--interactive}"[Attach container's stdin]" \ + "($help -)*:containers:__docker_complete_stopped_containers" && ret=0 + ;; + (stats) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Show all containers (default shows just running)]" \ + "($help)--format=[Format the output using the given Go template]:template: " \ + "($help)--no-stream[Disable streaming stats and only pull the first result]" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -)*:containers:__docker_complete_running_containers" && ret=0 + ;; + (stop) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -t --time)"{-t=,--time=}"[Number of seconds to try to stop for before killing the container]:seconds to before killing:(1 5 10 30 60)" \ + "($help -)*:containers:__docker_complete_running_containers" && ret=0 + ;; + (top) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)1:containers:__docker_complete_running_containers" \ + "($help -)*:: :->ps-arguments" && ret=0 + case $state in + (ps-arguments) + _ps && ret=0 + ;; + esac + ;; + (update) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_create_run_update \ + "($help -)*: :->values" && ret=0 + case $state in + (values) + if [[ ${words[(r)--kernel-memory*]} = (--kernel-memory*) ]]; then + __docker_complete_stopped_containers && ret=0 + else + __docker_complete_containers && ret=0 + fi + ;; + esac + ;; + (wait) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:containers:__docker_complete_running_containers" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_container_commands" && ret=0 + ;; + esac + + return ret +} + +# EO container + +# BO image + +__docker_image_commands() { + local -a _docker_image_subcommands + _docker_image_subcommands=( + "build:Build an image from a Dockerfile" + "history:Show the history of an image" + "import:Import the contents from a tarball to create a filesystem image" + "inspect:Display detailed information on one or more images" + "load:Load an image from a tar archive or STDIN" + "ls:List images" + "prune:Remove unused images" + "pull:Download an image from a registry" + "push:Upload an image to a registry" + "rm:Remove one or more images" + "save:Save one or more images to a tar archive (streamed to STDOUT by default)" + "tag:Tag an image into a repository" + ) + _describe -t docker-image-commands "docker image command" _docker_image_subcommands +} + +__docker_image_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (build) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*--add-host=[Add a custom host-to-IP mapping]:host\:ip mapping: " \ + "($help)*--build-arg=[Build-time variables]:=: " \ + "($help)*--cache-from=[Images to consider as cache sources]: :__docker_complete_repositories_with_tags" \ + "($help -c --cpu-shares)"{-c=,--cpu-shares=}"[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)" \ + "($help)--cgroup-parent=[Parent cgroup for the container]:cgroup: " \ + "($help)--compress[Compress the build context using gzip]" \ + "($help)--cpu-period=[Limit the CPU CFS (Completely Fair Scheduler) period]:CPU period: " \ + "($help)--cpu-quota=[Limit the CPU CFS (Completely Fair Scheduler) quota]:CPU quota: " \ + "($help)--cpu-rt-period=[Limit the CPU real-time period]:CPU real-time period in microseconds: " \ + "($help)--cpu-rt-runtime=[Limit the CPU real-time runtime]:CPU real-time runtime in microseconds: " \ + "($help)--cpuset-cpus=[CPUs in which to allow execution]:CPUs: " \ + "($help)--cpuset-mems=[MEMs in which to allow execution]:MEMs: " \ + "($help)--disable-content-trust[Skip image verification]" \ + "($help -f --file)"{-f=,--file=}"[Name of the Dockerfile]:Dockerfile:_files" \ + "($help)--force-rm[Always remove intermediate containers]" \ + "($help)--isolation=[Container isolation technology]:isolation:(default hyperv process)" \ + "($help)*--label=[Set metadata for an image]:label=value: " \ + "($help -m --memory)"{-m=,--memory=}"[Memory limit]:Memory limit: " \ + "($help)--memory-swap=[Total memory limit with swap]:Memory limit: " \ + "($help)--network=[Connect a container to a network]:network mode:(bridge none container host)" \ + "($help)--no-cache[Do not use cache when building the image]" \ + "($help)--pull[Attempt to pull a newer version of the image]" \ + "($help -q --quiet)"{-q,--quiet}"[Suppress verbose build output]" \ + "($help)--rm[Remove intermediate containers after a successful build]" \ + "($help)*--shm-size=[Size of '/dev/shm' (format is '')]:shm size: " \ + "($help)--squash[Squash newly built layers into a single new layer]" \ + "($help -t --tag)*"{-t=,--tag=}"[Repository, name and tag for the image]: :__docker_complete_repositories_with_tags" \ + "($help)--target=[Set the target build stage to build.]" \ + "($help)*--ulimit=[ulimit options]:ulimit: " \ + "($help)--userns=[Container user namespace]:user namespace:(host)" \ + "($help -):path or URL:_directories" && ret=0 + ;; + (history) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -H --human)"{-H,--human}"[Print sizes and dates in human readable format]" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -q --quiet)"{-q,--quiet}"[Only show image IDs]" \ + "($help -)*: :__docker_complete_images" && ret=0 + ;; + (import) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \ + "($help -m --message)"{-m=,--message=}"[Commit message for imported image]:message: " \ + "($help -):URL:(- http:// file://)" \ + "($help -): :__docker_complete_repositories_with_tags" && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ + "($help -)*:images:__docker_complete_images" && ret=0 + ;; + (load) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -i --input)"{-i=,--input=}"[Read from tar archive file]:archive file:_files -g \"*.((tar|TAR)(.gz|.GZ|.Z|.bz2|.lzma|.xz|)|(tbz|tgz|txz))(-.)\"" \ + "($help -q --quiet)"{-q,--quiet}"[Suppress the load output]" && ret=0 + ;; + (ls|list) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Show all images]" \ + "($help)--digests[Show digests]" \ + "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_images_filters" \ + "($help)--format=[Format the output using the given Go template]:template: " \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -q --quiet)"{-q,--quiet}"[Only show image IDs]" \ + "($help -): :__docker_complete_repositories" && ret=0 + ;; + (prune) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Remove all unused images, not just dangling ones]" \ + "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ + "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 + ;; + (pull) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all-tags)"{-a,--all-tags}"[Download all tagged images]" \ + "($help)--disable-content-trust[Skip image verification]" \ + "($help -):name:__docker_search" && ret=0 + ;; + (push) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all-tags)"{-a,--all-tags}"[Push all tags of an image to the repository]" \ + "($help)--disable-content-trust[Skip image signing]" \ + "($help -): :__docker_complete_images" && ret=0 + ;; + (rm) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --force)"{-f,--force}"[Force removal]" \ + "($help)--no-prune[Do not delete untagged parents]" \ + "($help -)*: :__docker_complete_images" && ret=0 + ;; + (save) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -o --output)"{-o=,--output=}"[Write to file]:file:_files" \ + "($help -)*: :__docker_complete_images" && ret=0 + ;; + (tag) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -):source:__docker_complete_images"\ + "($help -):destination:__docker_complete_repositories_with_tags" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_container_commands" && ret=0 + ;; + esac + + return ret +} + +# EO image + +# BO network + +__docker_network_complete_ls_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (driver) + __docker_complete_info_plugins Network && ret=0 + ;; + (id) + __docker_complete_networks_ids && ret=0 + ;; + (name) + __docker_complete_networks_names && ret=0 + ;; + (scope) + opts=('global' 'local' 'swarm') + _describe -t scope-filter-opts "Scope filter options" opts && ret=0 + ;; + (type) + opts=('builtin' 'custom') + _describe -t type-filter-opts "Type filter options" opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('driver' 'id' 'label' 'name' 'scope' 'type') + _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_get_networks() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local line s + declare -a lines networks + + type=$1; shift + + lines=(${(f)${:-"$(_call_program commands docker $docker_options network ls)"$'\n'}}) + + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 + lines=(${lines[2,-1]}) + + # Network ID + if [[ $type = (ids|all) ]]; then + for line in $lines; do + s="${line[${begin[NETWORK ID]},${end[NETWORK ID]}]%% ##}" + s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" + s="$s, ${${line[${begin[SCOPE]},${end[SCOPE]}]}%% ##}" + networks=($networks $s) + done + fi + + # Names + if [[ $type = (names|all) ]]; then + for line in $lines; do + s="${line[${begin[NAME]},${end[NAME]}]%% ##}" + s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" + s="$s, ${${line[${begin[SCOPE]},${end[SCOPE]}]}%% ##}" + networks=($networks $s) + done + fi + + _describe -t networks-list "networks" networks "$@" && ret=0 + return ret +} + +__docker_complete_networks() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_networks all "$@" +} + +__docker_complete_networks_ids() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_networks ids "$@" +} + +__docker_complete_networks_names() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_networks names "$@" +} + +__docker_network_commands() { + local -a _docker_network_subcommands + _docker_network_subcommands=( + "connect:Connect a container to a network" + "create:Creates a new network with a name specified by the user" + "disconnect:Disconnects a container from a network" + "inspect:Displays detailed information on a network" + "ls:Lists all the networks created by the user" + "prune:Remove all unused networks" + "rm:Deletes one or more networks" + ) + _describe -t docker-network-commands "docker network command" _docker_network_subcommands +} + +__docker_network_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (connect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*--alias=[Add network-scoped alias for the container]:alias: " \ + "($help)--ip=[IPv4 address]:IPv4: " \ + "($help)--ip6=[IPv6 address]:IPv6: " \ + "($help)*--link=[Add a link to another container]:link:->link" \ + "($help)*--link-local-ip=[Add a link-local address for the container]:IPv4/IPv6: " \ + "($help -)1:network:__docker_complete_networks" \ + "($help -)2:containers:__docker_complete_containers" && ret=0 + + case $state in + (link) + if compset -P "*:"; then + _wanted alias expl "Alias" compadd -E "" && ret=0 + else + __docker_complete_running_containers -qS ":" && ret=0 + fi + ;; + esac + ;; + (create) + _arguments $(__docker_arguments) -A '-*' \ + $opts_help \ + "($help)--attachable[Enable manual container attachment]" \ + "($help)*--aux-address[Auxiliary IPv4 or IPv6 addresses used by network driver]:key=IP: " \ + "($help -d --driver)"{-d=,--driver=}"[Driver to manage the Network]:driver:(null host bridge overlay)" \ + "($help)*--gateway=[IPv4 or IPv6 Gateway for the master subnet]:IP: " \ + "($help)--internal[Restricts external access to the network]" \ + "($help)*--ip-range=[Allocate container ip from a sub-range]:IP/mask: " \ + "($help)--ipam-driver=[IP Address Management Driver]:driver:(default)" \ + "($help)*--ipam-opt=[Custom IPAM plugin options]:opt=value: " \ + "($help)--ipv6[Enable IPv6 networking]" \ + "($help)*--label=[Set metadata on a network]:label=value: " \ + "($help)*"{-o=,--opt=}"[Driver specific options]:opt=value: " \ + "($help)*--subnet=[Subnet in CIDR format that represents a network segment]:IP/mask: " \ + "($help -)1:Network Name: " && ret=0 + ;; + (disconnect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)1:network:__docker_complete_networks" \ + "($help -)2:containers:__docker_complete_containers" && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ + "($help)--verbose[Show detailed information]" \ + "($help -)*:network:__docker_complete_networks" && ret=0 + ;; + (ls) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--no-trunc[Do not truncate the output]" \ + "($help)*"{-f=,--filter=}"[Provide filter values]:filter:__docker_network_complete_ls_filters" \ + "($help)--format=[Format the output using the given Go template]:template: " \ + "($help -q --quiet)"{-q,--quiet}"[Only display network IDs]" && ret=0 + ;; + (prune) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ + "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 + ;; + (rm) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:network:__docker_complete_networks" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0 + ;; + esac + + return ret +} + +# EO network + +# BO node + +__docker_node_complete_ls_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (id) + __docker_complete_nodes_ids && ret=0 + ;; + (membership) + membership_opts=('accepted' 'pending' 'rejected') + _describe -t membership-opts "membership options" membership_opts && ret=0 + ;; + (name) + __docker_complete_nodes_names && ret=0 + ;; + (role) + role_opts=('manager' 'worker') + _describe -t role-opts "role options" role_opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('id' 'label' 'membership' 'name' 'node.label' 'role') + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_node_complete_ps_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (desired-state) + state_opts=('accepted' 'running' 'shutdown') + _describe -t state-opts "desired state options" state_opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('desired-state' 'id' 'label' 'name') + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_nodes() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local line s + declare -a lines nodes args + + type=$1; shift + filter=$1; shift + [[ $filter != "none" ]] && args=("-f $filter") + + lines=(${(f)${:-"$(_call_program commands docker $docker_options node ls $args)"$'\n'}}) + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 + lines=(${lines[2,-1]}) + + # Node ID + if [[ $type = (ids|all) ]]; then + for line in $lines; do + s="${line[${begin[ID]},${end[ID]}]%% ##}" + nodes=($nodes $s) + done + fi + + # Names + if [[ $type = (names|all) ]]; then + for line in $lines; do + s="${line[${begin[HOSTNAME]},${end[HOSTNAME]}]%% ##}" + nodes=($nodes $s) + done + fi + + _describe -t nodes-list "nodes" nodes "$@" && ret=0 + return ret +} + +__docker_complete_nodes() { + [[ $PREFIX = -* ]] && return 1 + __docker_nodes all none "$@" +} + +__docker_complete_nodes_ids() { + [[ $PREFIX = -* ]] && return 1 + __docker_nodes ids none "$@" +} + +__docker_complete_nodes_names() { + [[ $PREFIX = -* ]] && return 1 + __docker_nodes names none "$@" +} + +__docker_complete_pending_nodes() { + [[ $PREFIX = -* ]] && return 1 + __docker_nodes all "membership=pending" "$@" +} + +__docker_complete_manager_nodes() { + [[ $PREFIX = -* ]] && return 1 + __docker_nodes all "role=manager" "$@" +} + +__docker_complete_worker_nodes() { + [[ $PREFIX = -* ]] && return 1 + __docker_nodes all "role=worker" "$@" +} + +__docker_node_commands() { + local -a _docker_node_subcommands + _docker_node_subcommands=( + "demote:Demote a node as manager in the swarm" + "inspect:Display detailed information on one or more nodes" + "ls:List nodes in the swarm" + "promote:Promote a node as manager in the swarm" + "rm:Remove one or more nodes from the swarm" + "ps:List tasks running on one or more nodes, defaults to current node" + "update:Update a node" + ) + _describe -t docker-node-commands "docker node command" _docker_node_subcommands +} + +__docker_node_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (rm|remove) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --force)"{-f,--force}"[Force remove a node from the swarm]" \ + "($help -)*:node:__docker_complete_pending_nodes" && ret=0 + ;; + (demote) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:node:__docker_complete_manager_nodes" && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ + "($help)--pretty[Print the information in a human friendly format]" \ + "($help -)*:node:__docker_complete_nodes" && ret=0 + ;; + (ls|list) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Provide filter values]:filter:__docker_node_complete_ls_filters" \ + "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 + ;; + (promote) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:node:__docker_complete_worker_nodes" && ret=0 + ;; + (ps) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Display all instances]" \ + "($help)*"{-f=,--filter=}"[Provide filter values]:filter:__docker_node_complete_ps_filters" \ + "($help)--format=[Format the output using the given go template]:template: " \ + "($help)--no-resolve[Do not map IDs to Names]" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" \ + "($help -)*:node:__docker_complete_nodes" && ret=0 + ;; + (update) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--availability=[Availability of the node]:availability:(active pause drain)" \ + "($help)*--label-add=[Add or update a node label]:key=value: " \ + "($help)*--label-rm=[Remove a node label if exists]:label: " \ + "($help)--role=[Role of the node]:role:(manager worker)" \ + "($help -)1:node:__docker_complete_nodes" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_node_commands" && ret=0 + ;; + esac + + return ret +} + +# EO node + +# BO plugin + +__docker_plugin_complete_ls_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (capability) + opts=('authz' 'ipamdriver' 'logdriver' 'metricscollector' 'networkdriver' 'volumedriver') + _describe -t capability-opts "capability options" opts && ret=0 + ;; + (enabled) + opts=('false' 'true') + _describe -t enabled-opts "enabled options" opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('capability' 'enabled') + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_plugins() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local line s + declare -a lines plugins args + + filter=$1; shift + [[ $filter != "none" ]] && args=("-f $filter") + + lines=(${(f)${:-"$(_call_program commands docker $docker_options plugin ls $args)"$'\n'}}) + + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 + lines=(${lines[2,-1]}) + + # Name + for line in $lines; do + s="${line[${begin[NAME]},${end[NAME]}]%% ##}" + s="$s:${(l:7:: :::)${${line[${begin[TAG]},${end[TAG]}]}%% ##}}" + plugins=($plugins $s) + done + + _describe -t plugins-list "plugins" plugins "$@" && ret=0 + return ret +} + +__docker_complete_plugins() { + [[ $PREFIX = -* ]] && return 1 + __docker_plugins none "$@" +} + +__docker_complete_enabled_plugins() { + [[ $PREFIX = -* ]] && return 1 + __docker_plugins enabled=true "$@" +} + +__docker_complete_disabled_plugins() { + [[ $PREFIX = -* ]] && return 1 + __docker_plugins enabled=false "$@" +} + +__docker_plugin_commands() { + local -a _docker_plugin_subcommands + _docker_plugin_subcommands=( + "disable:Disable a plugin" + "enable:Enable a plugin" + "inspect:Return low-level information about a plugin" + "install:Install a plugin" + "ls:List plugins" + "push:Push a plugin" + "rm:Remove a plugin" + "set:Change settings for a plugin" + "upgrade:Upgrade an existing plugin" + ) + _describe -t docker-plugin-commands "docker plugin command" _docker_plugin_subcommands +} + +__docker_plugin_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (disable) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --force)"{-f,--force}"[Force the disable of an active plugin]" \ + "($help -)1:plugin:__docker_complete_enabled_plugins" && ret=0 + ;; + (enable) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--timeout=[HTTP client timeout (in seconds)]:timeout: " \ + "($help -)1:plugin:__docker_complete_disabled_plugins" && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given Go template]:template: " \ + "($help -)*:plugin:__docker_complete_plugins" && ret=0 + ;; + (install) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--alias=[Local name for plugin]:alias: " \ + "($help)--disable[Do not enable the plugin on install]" \ + "($help)--disable-content-trust[Skip image verification (default true)]" \ + "($help)--grant-all-permissions[Grant all permissions necessary to run the plugin]" \ + "($help -)1:plugin:__docker_complete_plugins" \ + "($help -)*:key=value: " && ret=0 + ;; + (ls|list) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:__docker_plugin_complete_ls_filters" \ + "($help --format)--format=[Format the output using the given Go template]:template: " \ + "($help)--no-trunc[Don't truncate output]" \ + "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 + ;; + (push) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--disable-content-trust[Skip image verification (default true)]" \ + "($help -)1:plugin:__docker_complete_plugins" && ret=0 + ;; + (rm|remove) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --force)"{-f,--force}"[Force the removal of an active plugin]" \ + "($help -)*:plugin:__docker_complete_plugins" && ret=0 + ;; + (set) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)1:plugin:__docker_complete_plugins" \ + "($help -)*:key=value: " && ret=0 + ;; + (upgrade) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--disable-content-trust[Skip image verification (default true)]" \ + "($help)--grant-all-permissions[Grant all permissions necessary to run the plugin]" \ + "($help)--skip-remote-check[Do not check if specified remote plugin matches existing plugin image]" \ + "($help -)1:plugin:__docker_complete_plugins" \ + "($help -):remote: " && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_plugin_commands" && ret=0 + ;; + esac + + return ret +} + +# EO plugin + +# BO secret + +__docker_secrets() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local line s + declare -a lines secrets + + type=$1; shift + + lines=(${(f)${:-"$(_call_program commands docker $docker_options secret ls)"$'\n'}}) + + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 + lines=(${lines[2,-1]}) + + # ID + if [[ $type = (ids|all) ]]; then + for line in $lines; do + s="${line[${begin[ID]},${end[ID]}]%% ##}" + secrets=($secrets $s) + done + fi + + # Names + if [[ $type = (names|all) ]]; then + for line in $lines; do + s="${line[${begin[NAME]},${end[NAME]}]%% ##}" + secrets=($secrets $s) + done + fi + + _describe -t secrets-list "secrets" secrets "$@" && ret=0 + return ret +} + +__docker_complete_secrets() { + [[ $PREFIX = -* ]] && return 1 + __docker_secrets all "$@" +} + +__docker_secret_commands() { + local -a _docker_secret_subcommands + _docker_secret_subcommands=( + "create:Create a secret using stdin as content" + "inspect:Display detailed information on one or more secrets" + "ls:List secrets" + "rm:Remove one or more secrets" + ) + _describe -t docker-secret-commands "docker secret command" _docker_secret_subcommands +} + +__docker_secret_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (create) + _arguments $(__docker_arguments) -A '-*' \ + $opts_help \ + "($help)*"{-l=,--label=}"[Secret labels]:label: " \ + "($help -):secret: " && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given Go template]:template: " \ + "($help -)*:secret:__docker_complete_secrets" && ret=0 + ;; + (ls|list) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--format=[Format the output using the given go template]:template: " \ + "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 + ;; + (rm|remove) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:secret:__docker_complete_secrets" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_secret_commands" && ret=0 + ;; + esac + + return ret +} + +# EO secret + +# BO service + +__docker_service_complete_ls_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (id) + __docker_complete_services_ids && ret=0 + ;; + (mode) + opts=('global' 'replicated') + _describe -t mode-opts "mode options" opts && ret=0 + ;; + (name) + __docker_complete_services_names && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('id' 'label' 'mode' 'name') + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_service_complete_ps_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (desired-state) + state_opts=('accepted' 'running' 'shutdown') + _describe -t state-opts "desired state options" state_opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('desired-state' 'id' 'label' 'name') + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_service_complete_placement_pref() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (spread) + opts=('engine.labels' 'node.labels') + _describe -t spread-opts "spread options" opts -qS "." && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('spread') + _describe -t pref-opts "placement pref options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_services() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local line s + declare -a lines services + + type=$1; shift + + lines=(${(f)${:-"$(_call_program commands docker $docker_options service ls)"$'\n'}}) + + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 + lines=(${lines[2,-1]}) + + # Service ID + if [[ $type = (ids|all) ]]; then + for line in $lines; do + s="${line[${begin[ID]},${end[ID]}]%% ##}" + s="$s:${(l:7:: :::)${${line[${begin[IMAGE]},${end[IMAGE]}]}%% ##}}" + services=($services $s) + done + fi + + # Names + if [[ $type = (names|all) ]]; then + for line in $lines; do + s="${line[${begin[NAME]},${end[NAME]}]%% ##}" + s="$s:${(l:7:: :::)${${line[${begin[IMAGE]},${end[IMAGE]}]}%% ##}}" + services=($services $s) + done + fi + + _describe -t services-list "services" services "$@" && ret=0 + return ret +} + +__docker_complete_services() { + [[ $PREFIX = -* ]] && return 1 + __docker_services all "$@" +} + +__docker_complete_services_ids() { + [[ $PREFIX = -* ]] && return 1 + __docker_services ids "$@" +} + +__docker_complete_services_names() { + [[ $PREFIX = -* ]] && return 1 + __docker_services names "$@" +} + +__docker_service_commands() { + local -a _docker_service_subcommands + _docker_service_subcommands=( + "create:Create a new service" + "inspect:Display detailed information on one or more services" + "logs:Fetch the logs of a service or task" + "ls:List services" + "rm:Remove one or more services" + "rollback:Revert changes to a service's configuration" + "scale:Scale one or multiple replicated services" + "ps:List the tasks of a service" + "update:Update a service" + ) + _describe -t docker-service-commands "docker service command" _docker_service_subcommands +} + +__docker_service_subcommand() { + local -a _command_args opts_help opts_create_update + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + opts_create_update=( + "($help)*--cap-add=[Add Linux capabilities]:capability: " + "($help)*--cap-drop=[Drop Linux capabilities]:capability: " + "($help)*--constraint=[Placement constraints]:constraint: " + "($help)--endpoint-mode=[Placement constraints]:mode:(dnsrr vip)" + "($help)*"{-e=,--env=}"[Set environment variables]:env: " + "($help)--health-cmd=[Command to run to check health]:command: " + "($help)--health-interval=[Time between running the check]:time: " + "($help)--health-retries=[Consecutive failures needed to report unhealthy]:retries:(1 2 3 4 5)" + "($help)--health-timeout=[Maximum time to allow one check to run]:time: " + "($help)--hostname=[Service container hostname]:hostname: " \ + "($help)--isolation=[Service container isolation mode]:isolation:(default process hyperv)" \ + "($help)*--label=[Service labels]:label: " + "($help)--limit-cpu=[Limit CPUs]:value: " + "($help)--limit-memory=[Limit Memory]:value: " + "($help)--limit-pids[Limit maximum number of processes (default 0 = unlimited)]" + "($help)--log-driver=[Logging driver for service]:logging driver:__docker_complete_log_drivers" + "($help)*--log-opt=[Logging driver options]:log driver options:__docker_complete_log_options" + "($help)*--mount=[Attach a filesystem mount to the service]:mount: " + "($help)*--network=[Network attachments]:network: " + "($help)--no-healthcheck[Disable any container-specified HEALTHCHECK]" + "($help)--read-only[Mount the container's root filesystem as read only]" + "($help)--replicas=[Number of tasks]:replicas: " + "($help)--reserve-cpu=[Reserve CPUs]:value: " + "($help)--reserve-memory=[Reserve Memory]:value: " + "($help)--restart-condition=[Restart when condition is met]:mode:(any none on-failure)" + "($help)--restart-delay=[Delay between restart attempts]:delay: " + "($help)--restart-max-attempts=[Maximum number of restarts before giving up]:max-attempts: " + "($help)--restart-window=[Window used to evaluate the restart policy]:duration: " + "($help)--rollback-delay=[Delay between task rollbacks]:duration: " + "($help)--rollback-failure-action=[Action on rollback failure]:action:(continue pause)" + "($help)--rollback-max-failure-ratio=[Failure rate to tolerate during a rollback]:failure rate: " + "($help)--rollback-monitor=[Duration after each task rollback to monitor for failure]:duration: " + "($help)--rollback-parallelism=[Maximum number of tasks rolled back simultaneously]:number: " + "($help)*--secret=[Specify secrets to expose to the service]:secret:__docker_complete_secrets" + "($help)--stop-grace-period=[Time to wait before force killing a container]:grace period: " + "($help)--stop-signal=[Signal to stop the container]:signal:_signals" + "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-TTY]" + "($help)--update-delay=[Delay between updates]:delay: " + "($help)--update-failure-action=[Action on update failure]:mode:(continue pause rollback)" + "($help)--update-max-failure-ratio=[Failure rate to tolerate during an update]:fraction: " + "($help)--update-monitor=[Duration after each task update to monitor for failure]:window: " + "($help)--update-parallelism=[Maximum number of tasks updated simultaneously]:number: " + "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" + "($help)--with-registry-auth[Send registry authentication details to swarm agents]" + "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories" + ) + + case "$words[1]" in + (create) + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_create_update \ + "($help)*--container-label=[Container labels]:label: " \ + "($help)*--dns=[Set custom DNS servers]:DNS: " \ + "($help)*--dns-option=[Set DNS options]:DNS option: " \ + "($help)*--dns-search=[Set custom DNS search domains]:DNS search: " \ + "($help)*--env-file=[Read environment variables from a file]:environment file:_files" \ + "($help)*--group=[Set one or more supplementary user groups for the container]:group: _groups " \ + "($help)--mode=[Service Mode]:mode:(global replicated)" \ + "($help)--name=[Service name]:name: " \ + "($help)*--placement-pref=[Add a placement preference]:pref:__docker_service_complete_placement_pref" \ + "($help)*"{-p=,--publish=}"[Publish a port as a node port]:port: " \ + "($help -): :__docker_complete_images" \ + "($help -):command: _command_names -e" \ + "($help -)*::arguments: _normal" && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ + "($help)--pretty[Print the information in a human friendly format]" \ + "($help -)*:service:__docker_complete_services" && ret=0 + ;; + (logs) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --follow)"{-f,--follow}"[Follow log output]" \ + "($help)--no-resolve[Do not map IDs to Names]" \ + "($help)--no-task-ids[Do not include task IDs]" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help)--since=[Show logs since timestamp]:timestamp: " \ + "($help -n --tail)"{-n=,--tail=}"[Number of lines to show from the end of the logs]:lines:(1 10 20 50 all)" \ + "($help -t --timestamps)"{-t,--timestamps}"[Show timestamps]" \ + "($help -)1:service:__docker_complete_services" && ret=0 + ;; + (ls|list) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:__docker_service_complete_ls_filters" \ + "($help)--format=[Format the output using the given Go template]:template: " \ + "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 + ;; + (rm|remove) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:service:__docker_complete_services" && ret=0 + ;; + (rollback) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -d --detach)"{-d=false,--detach=false}"[Disable detached mode]" \ + "($help -q --quiet)"{-q,--quiet}"[Suppress progress output]" \ + "($help -)*:service:__docker_complete_services" && ret=0 + ;; + (scale) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -d --detach)"{-d=false,--detach=false}"[Disable detached mode]" \ + "($help -)*:service:->values" && ret=0 + case $state in + (values) + if compset -P '*='; then + _message 'replicas' && ret=0 + else + __docker_complete_services -qS "=" + fi + ;; + esac + ;; + (ps) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Provide filter values]:filter:__docker_service_complete_ps_filters" \ + "($help)--format=[Format the output using the given go template]:template: " \ + "($help)--no-resolve[Do not map IDs to Names]" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -q --quiet)"{-q,--quiet}"[Only display task IDs]" \ + "($help -)*:service:__docker_complete_services" && ret=0 + ;; + (update) + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_create_update \ + "($help)--arg=[Service command args]:arguments: _normal" \ + "($help)*--container-label-add=[Add or update container labels]:label: " \ + "($help)*--container-label-rm=[Remove a container label by its key]:label: " \ + "($help)*--dns-add=[Add or update custom DNS servers]:DNS: " \ + "($help)*--dns-rm=[Remove custom DNS servers]:DNS: " \ + "($help)*--dns-option-add=[Add or update DNS options]:DNS option: " \ + "($help)*--dns-option-rm=[Remove DNS options]:DNS option: " \ + "($help)*--dns-search-add=[Add or update custom DNS search domains]:DNS search: " \ + "($help)*--dns-search-rm=[Remove DNS search domains]:DNS search: " \ + "($help)--force[Force update]" \ + "($help)*--group-add=[Add additional supplementary user groups to the container]:group:_groups" \ + "($help)*--group-rm=[Remove previously added supplementary user groups from the container]:group:_groups" \ + "($help)--image=[Service image tag]:image:__docker_complete_repositories" \ + "($help)*--placement-pref-add=[Add a placement preference]:pref:__docker_service_complete_placement_pref" \ + "($help)*--placement-pref-rm=[Remove a placement preference]:pref:__docker_service_complete_placement_pref" \ + "($help)*--publish-add=[Add or update a port]:port: " \ + "($help)*--publish-rm=[Remove a port(target-port mandatory)]:port: " \ + "($help)--rollback[Rollback to previous specification]" \ + "($help -)1:service:__docker_complete_services" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_service_commands" && ret=0 + ;; + esac + + return ret +} + +# EO service + +# BO stack + +__docker_stack_complete_ps_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (desired-state) + state_opts=('accepted' 'running' 'shutdown') + _describe -t state-opts "desired state options" state_opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('desired-state' 'id' 'name') + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_stack_complete_services_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('id' 'label' 'name') + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_stacks() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local line s + declare -a lines stacks + + lines=(${(f)${:-"$(_call_program commands docker $docker_options stack ls)"$'\n'}}) + + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 + lines=(${lines[2,-1]}) + + # Service NAME + for line in $lines; do + s="${line[${begin[NAME]},${end[NAME]}]%% ##}" + stacks=($stacks $s) + done + + _describe -t stacks-list "stacks" stacks "$@" && ret=0 + return ret +} + +__docker_complete_stacks() { + [[ $PREFIX = -* ]] && return 1 + __docker_stacks "$@" +} + +__docker_stack_commands() { + local -a _docker_stack_subcommands + _docker_stack_subcommands=( + "deploy:Deploy a new stack or update an existing stack" + "ls:List stacks" + "ps:List the tasks in the stack" + "rm:Remove the stack" + "services:List the services in the stack" + ) + _describe -t docker-stack-commands "docker stack command" _docker_stack_subcommands +} + +__docker_stack_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (deploy|up) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -c --compose-file)"{-c=,--compose-file=}"[Path to a Compose file, or '-' to read from stdin]:compose file:_files -g \"*.(yml|yaml)\"" \ + "($help)--with-registry-auth[Send registry authentication details to Swarm agents]" \ + "($help -):stack:__docker_complete_stacks" && ret=0 + ;; + (ls|list) + _arguments $(__docker_arguments) \ + $opts_help && ret=0 + ;; + (ps) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Display all tasks]" \ + "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:__docker_stack_complete_ps_filters" \ + "($help)--format=[Format the output using the given go template]:template: " \ + "($help)--no-resolve[Do not map IDs to Names]" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -q --quiet)"{-q,--quiet}"[Only display task IDs]" \ + "($help -):stack:__docker_complete_stacks" && ret=0 + ;; + (rm|remove|down) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -):stack:__docker_complete_stacks" && ret=0 + ;; + (services) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:__docker_stack_complete_services_filters" \ + "($help)--format=[Format the output using the given Go template]:template: " \ + "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" \ + "($help -):stack:__docker_complete_stacks" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_stack_commands" && ret=0 + ;; + esac + + return ret +} + +# EO stack + +# BO swarm + +__docker_swarm_commands() { + local -a _docker_swarm_subcommands + _docker_swarm_subcommands=( + "init:Initialize a swarm" + "join:Join a swarm as a node and/or manager" + "join-token:Manage join tokens" + "leave:Leave a swarm" + "unlock:Unlock swarm" + "unlock-key:Manage the unlock key" + "update:Update the swarm" + ) + _describe -t docker-swarm-commands "docker swarm command" _docker_swarm_subcommands +} + +__docker_swarm_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (init) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--advertise-addr=[Advertised address]:ip\:port: " \ + "($help)--data-path-addr=[Data path IP or interface]:ip " \ + "($help)--data-path-port=[Data Path Port]:port " \ + "($help)--default-addr-pool=[Default address pool]" \ + "($help)--default-addr-pool-mask-length=[Default address pool subnet mask length]" \ + "($help)--autolock[Enable manager autolocking]" \ + "($help)--availability=[Availability of the node]:availability:(active drain pause)" \ + "($help)--cert-expiry=[Validity period for node certificates]:duration: " \ + "($help)--dispatcher-heartbeat=[Dispatcher heartbeat period]:duration: " \ + "($help)*--external-ca=[Specifications of one or more certificate signing endpoints]:endpoint: " \ + "($help)--force-new-cluster[Force create a new cluster from current state]" \ + "($help)--listen-addr=[Listen address]:ip\:port: " \ + "($help)--max-snapshots[Number of additional Raft snapshots to retain]" \ + "($help)--snapshot-interval[Number of log entries between Raft snapshots]" \ + "($help)--task-history-limit=[Task history retention limit]:limit: " && ret=0 + ;; + (join) + _arguments $(__docker_arguments) -A '-*' \ + $opts_help \ + "($help)--advertise-addr=[Advertised address]:ip\:port: " \ + "($help)--data-path-addr=[Data path IP or interface]:ip " \ + "($help)--availability=[Availability of the node]:availability:(active drain pause)" \ + "($help)--listen-addr=[Listen address]:ip\:port: " \ + "($help)--token=[Token for entry into the swarm]:secret: " \ + "($help -):host\:port: " && ret=0 + ;; + (join-token) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -q --quiet)"{-q,--quiet}"[Only display token]" \ + "($help)--rotate[Rotate join token]" \ + "($help -):role:(manager worker)" && ret=0 + ;; + (leave) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --force)"{-f,--force}"[Force this node to leave the swarm, ignoring warnings]" && ret=0 + ;; + (unlock) + _arguments $(__docker_arguments) \ + $opts_help && ret=0 + ;; + (unlock-key) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -q --quiet)"{-q,--quiet}"[Only display token]" \ + "($help)--rotate[Rotate unlock token]" && ret=0 + ;; + (update) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--autolock[Enable manager autolocking]" \ + "($help)--cert-expiry=[Validity period for node certificates]:duration: " \ + "($help)--dispatcher-heartbeat=[Dispatcher heartbeat period]:duration: " \ + "($help)*--external-ca=[Specifications of one or more certificate signing endpoints]:endpoint: " \ + "($help)--max-snapshots[Number of additional Raft snapshots to retain]" \ + "($help)--snapshot-interval[Number of log entries between Raft snapshots]" \ + "($help)--task-history-limit=[Task history retention limit]:limit: " && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0 + ;; + esac + + return ret +} + +# EO swarm + +# BO system + +__docker_system_commands() { + local -a _docker_system_subcommands + _docker_system_subcommands=( + "df:Show docker filesystem usage" + "events:Get real time events from the server" + "info:Display system-wide information" + "prune:Remove unused data" + ) + _describe -t docker-system-commands "docker system command" _docker_system_subcommands +} + +__docker_system_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (df) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -v --verbose)"{-v,--verbose}"[Show detailed information on space usage]" && ret=0 + ;; + (events) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_events_filter" \ + "($help)--since=[Events created since this timestamp]:timestamp: " \ + "($help)--until=[Events created until this timestamp]:timestamp: " \ + "($help)--format=[Format the output using the given go template]:template: " && ret=0 + ;; + (info) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " && ret=0 + ;; + (prune) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Remove all unused data, not just dangling ones]" \ + "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ + "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" \ + "($help)--volumes=[Remove all unused volumes]" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_volume_commands" && ret=0 + ;; + esac + + return ret +} + +# EO system + +# BO volume + +__docker_volume_complete_ls_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (dangling) + dangling_opts=('true' 'false') + _describe -t dangling-filter-opts "Dangling Filter Options" dangling_opts && ret=0 + ;; + (driver) + __docker_complete_info_plugins Volume && ret=0 + ;; + (name) + __docker_complete_volumes && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('dangling' 'driver' 'label' 'name') + _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_complete_volumes() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a lines volumes + + lines=(${(f)${:-"$(_call_program commands docker $docker_options volume ls)"$'\n'}}) + + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 + lines=(${lines[2,-1]}) + + # Names + local line s + for line in $lines; do + s="${line[${begin[VOLUME NAME]},${end[VOLUME NAME]}]%% ##}" + s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" + volumes=($volumes $s) + done + + _describe -t volumes-list "volumes" volumes && ret=0 + return ret +} + +__docker_volume_commands() { + local -a _docker_volume_subcommands + _docker_volume_subcommands=( + "create:Create a volume" + "inspect:Display detailed information on one or more volumes" + "ls:List volumes" + "prune:Remove all unused volumes" + "rm:Remove one or more volumes" + ) + _describe -t docker-volume-commands "docker volume command" _docker_volume_subcommands +} + +__docker_volume_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (create) + _arguments $(__docker_arguments) -A '-*' \ + $opts_help \ + "($help -d --driver)"{-d=,--driver=}"[Volume driver name]:Driver name:(local)" \ + "($help)*--label=[Set metadata for a volume]:label=value: " \ + "($help)*"{-o=,--opt=}"[Driver specific options]:Driver option: " \ + "($help -)1:Volume name: " && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ + "($help -)1:volume:__docker_complete_volumes" && ret=0 + ;; + (ls) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Provide filter values]:filter:__docker_volume_complete_ls_filters" \ + "($help)--format=[Format the output using the given Go template]:template: " \ + "($help -q --quiet)"{-q,--quiet}"[Only display volume names]" && ret=0 + ;; + (prune) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Remove all unused local volumes, not just anonymous ones]" \ + "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ + "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 + ;; + (rm) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --force)"{-f,--force}"[Force the removal of one or more volumes]" \ + "($help -):volume:__docker_complete_volumes" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_volume_commands" && ret=0 + ;; + esac + + return ret +} + +# EO volume + +# BO context + +__docker_complete_contexts() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a contexts + + contexts=(${(f)${:-"$(_call_program commands docker $docker_options context ls -q)"$'\n'}}) + + _describe -t context-list "context" contexts && ret=0 + return ret +} + +__docker_context_commands() { + local -a _docker_context_subcommands + _docker_context_subcommands=( + "create:Create new context" + "inspect:Display detailed information on one or more contexts" + "list:List available contexts" + "rm:Remove one or more contexts" + "show:Print the current context" + "update:Update a context" + "use:Set the default context" + ) + _describe -t docker-context-commands "docker context command" _docker_context_subcommands +} + +__docker_context_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (create) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--description=[Description of the context]:description:" \ + "($help)--docker=[Set the docker endpoint]:docker:" \ + "($help)--from=[Create context from a named context]:from:__docker_complete_contexts" \ + "($help -):name: " && ret=0 + ;; + (use) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)1:context:__docker_complete_contexts" && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)1:context:__docker_complete_contexts" && ret=0 + ;; + (rm) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)1:context:__docker_complete_contexts" && ret=0 + ;; + (update) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--description=[Description of the context]:description:" \ + "($help)--docker=[Set the docker endpoint]:docker:" \ + "($help -):name:" && ret=0 + ;; + esac + + return ret +} + +# EO context + +__docker_caching_policy() { + oldp=( "$1"(Nmh+1) ) # 1 hour + (( $#oldp )) +} + +__docker_commands() { + local cache_policy + integer force_invalidation=0 + + zstyle -s ":completion:${curcontext}:" cache-policy cache_policy + if [[ -z "$cache_policy" ]]; then + zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy + fi + + if ( (( ! ${+_docker_hide_legacy_commands} )) || _cache_invalid docker_hide_legacy_commands ) \ + && ! _retrieve_cache docker_hide_legacy_commands; + then + _docker_hide_legacy_commands="${DOCKER_HIDE_LEGACY_COMMANDS}" + _store_cache docker_hide_legacy_commands _docker_hide_legacy_commands + fi + + if [[ "${_docker_hide_legacy_commands}" != "${DOCKER_HIDE_LEGACY_COMMANDS}" ]]; then + force_invalidation=1 + _docker_hide_legacy_commands="${DOCKER_HIDE_LEGACY_COMMANDS}" + _store_cache docker_hide_legacy_commands _docker_hide_legacy_commands + fi + + if ( [[ ${+_docker_subcommands} -eq 0 ]] || _cache_invalid docker_subcommands ) \ + && ! _retrieve_cache docker_subcommands || [[ ${force_invalidation} -eq 1 ]]; + then + local -a lines + lines=(${(f)"$(_call_program commands docker 2>&1)"}) + _docker_subcommands=(${${${(M)${lines[$((${lines[(i)*Commands:]} + 1)),-1]}:# *}## #}/\*# ##/:}) + _docker_subcommands=($_docker_subcommands 'daemon:Enable daemon mode' 'help:Show help for a command') + (( $#_docker_subcommands > 2 )) && _store_cache docker_subcommands _docker_subcommands + fi + _describe -t docker-commands "docker command" _docker_subcommands +} + +__docker_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (attach|commit|cp|create|diff|exec|export|kill|logs|pause|unpause|port|rename|restart|rm|run|start|stats|stop|top|update|wait) + __docker_container_subcommand && ret=0 + ;; + (build|history|import|load|pull|push|save|tag) + __docker_image_subcommand && ret=0 + ;; + (checkpoint) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_checkpoint_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_checkpoint_subcommand && ret=0 + ;; + esac + ;; + (container) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_container_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_container_subcommand && ret=0 + ;; + esac + ;; + (context) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_context_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_context_subcommand && ret=0 + ;; + esac + ;; + (daemon) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*--add-runtime=[Register an additional OCI compatible runtime]:runtime:__docker_complete_runtimes" \ + "($help)*--allow-nondistributable-artifacts=[Push nondistributable artifacts to specified registries]:registry: " \ + "($help)--api-cors-header=[CORS headers in the Engine API]:CORS headers: " \ + "($help)*--authorization-plugin=[Authorization plugins to load]" \ + "($help -b --bridge)"{-b=,--bridge=}"[Attach containers to a network bridge]:bridge:_net_interfaces" \ + "($help)--bip=[Network bridge IP]:IP address: " \ + "($help)--cgroup-parent=[Parent cgroup for all containers]:cgroup: " \ + "($help)--config-file=[Path to daemon configuration file]:Config File:_files" \ + "($help)--containerd=[Path to containerd socket]:socket:_files -g \"*.sock\"" \ + "($help)--containerd-namespace=[Containerd namespace to use]:containerd namespace:" \ + "($help)--containerd-plugins-namespace=[Containerd namespace to use for plugins]:containerd namespace:" \ + "($help)--data-root=[Root directory of persisted Docker data]:path:_directories" \ + "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \ + "($help)--default-gateway[Container default gateway IPv4 address]:IPv4 address: " \ + "($help)--default-gateway-v6[Container default gateway IPv6 address]:IPv6 address: " \ + "($help)--default-shm-size=[Default shm size for containers]:size:" \ + "($help)*--default-ulimit=[Default ulimits for containers]:ulimit: " \ + "($help)*--dns=[DNS server to use]:DNS: " \ + "($help)*--dns-opt=[DNS options to use]:DNS option: " \ + "($help)*--dns-search=[DNS search domains to use]:DNS search: " \ + "($help)*--exec-opt=[Runtime execution options]:runtime execution options: " \ + "($help)--exec-root=[Root directory for execution state files]:path:_directories" \ + "($help)--experimental[Enable experimental features]" \ + "($help)--fixed-cidr=[IPv4 subnet for fixed IPs]:IPv4 subnet: " \ + "($help)--fixed-cidr-v6=[IPv6 subnet for fixed IPs]:IPv6 subnet: " \ + "($help -G --group)"{-G=,--group=}"[Group for the unix socket]:group:_groups" \ + "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \ + "($help)--icc[Enable inter-container communication]" \ + "($help)--init[Run an init inside containers to forward signals and reap processes]" \ + "($help)--init-path=[Path to the docker-init binary]:docker-init binary:_files" \ + "($help)*--insecure-registry=[Enable insecure registry communication]:registry: " \ + "($help)--ip=[Default IP when binding container ports]" \ + "($help)--ip-forward[Enable net.ipv4.ip_forward]" \ + "($help)--ip-masq[Enable IP masquerading]" \ + "($help)--iptables[Enable addition of iptables rules]" \ + "($help)--ipv6[Enable IPv6 networking]" \ + "($help -l --log-level)"{-l=,--log-level=}"[Logging level]:level:(debug info warn error fatal)" \ + "($help)*--label=[Key=value labels]:label: " \ + "($help)--live-restore[Enable live restore of docker when containers are still running]" \ + "($help)--log-driver=[Default driver for container logs]:logging driver:__docker_complete_log_drivers" \ + "($help)*--log-opt=[Default log driver options for containers]:log driver options:__docker_complete_log_options" \ + "($help)--max-concurrent-downloads[Set the max concurrent downloads]" \ + "($help)--max-concurrent-uploads[Set the max concurrent uploads]" \ + "($help)--max-download-attempts[Set the max download attempts for each pull]" \ + "($help)--mtu=[Network MTU]:mtu:(0 576 1420 1500 9000)" \ + "($help)--oom-score-adjust=[Set the oom_score_adj for the daemon]:oom-score:(-500)" \ + "($help -p --pidfile)"{-p=,--pidfile=}"[Path to use for daemon PID file]:PID file:_files" \ + "($help)--raw-logs[Full timestamps without ANSI coloring]" \ + "($help)*--registry-mirror=[Preferred registry mirror]:registry mirror: " \ + "($help)--seccomp-profile=[Path to seccomp profile]:path:_files -g \"*.json\"" \ + "($help -s --storage-driver)"{-s=,--storage-driver=}"[Storage driver to use]:driver:(btrfs devicemapper overlay2 vfs zfs)" \ + "($help)--selinux-enabled[Enable selinux support]" \ + "($help)--shutdown-timeout=[Set the shutdown timeout value in seconds]:time: " \ + "($help)*--storage-opt=[Storage driver options]:storage driver options: " \ + "($help)--tls[Use TLS]" \ + "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g \"*.(pem|crt)\"" \ + "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g \"*.(pem|crt)\"" \ + "($help)--tlskey=[Path to TLS key file]:Key file:_files -g \"*.(pem|key)\"" \ + "($help)--tlsverify[Use TLS and verify the remote]" \ + "($help)--userns-remap=[User/Group setting for user namespaces]:user\:group:->users-groups" \ + "($help)--userland-proxy[Use userland proxy for loopback traffic]" \ + "($help)--userland-proxy-path=[Path to the userland proxy binary]:binary:_files" \ + "($help)--validate[Validate daemon configuration and exit]" && ret=0 + + case $state in + (users-groups) + if compset -P '*:'; then + _groups && ret=0 + else + _describe -t userns-default "default Docker user management" '(default)' && ret=0 + _users && ret=0 + fi + ;; + esac + ;; + (events|info) + __docker_system_subcommand && ret=0 + ;; + (image) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_image_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_image_subcommand && ret=0 + ;; + esac + ;; + (images) + words[1]='ls' + __docker_image_subcommand && ret=0 + ;; + (inspect) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ + "($help -s --size)"{-s,--size}"[Display total file sizes if the type is container]" \ + "($help)--type=[Return JSON for specified type]:type:(container image network node plugin service volume)" \ + "($help -)*: :->values" && ret=0 + + case $state in + (values) + if [[ ${words[(r)--type=container]} == --type=container ]]; then + __docker_complete_containers && ret=0 + elif [[ ${words[(r)--type=image]} == --type=image ]]; then + __docker_complete_images && ret=0 + elif [[ ${words[(r)--type=network]} == --type=network ]]; then + __docker_complete_networks && ret=0 + elif [[ ${words[(r)--type=node]} == --type=node ]]; then + __docker_complete_nodes && ret=0 + elif [[ ${words[(r)--type=plugin]} == --type=plugin ]]; then + __docker_complete_plugins && ret=0 + elif [[ ${words[(r)--type=service]} == --type=secrets ]]; then + __docker_complete_secrets && ret=0 + elif [[ ${words[(r)--type=service]} == --type=service ]]; then + __docker_complete_services && ret=0 + elif [[ ${words[(r)--type=volume]} == --type=volume ]]; then + __docker_complete_volumes && ret=0 + else + __docker_complete_containers + __docker_complete_images + __docker_complete_networks + __docker_complete_nodes + __docker_complete_plugins + __docker_complete_secrets + __docker_complete_services + __docker_complete_volumes && ret=0 + fi + ;; + esac + ;; + (login) + _arguments $(__docker_arguments) -A '-*' \ + $opts_help \ + "($help -p --password)"{-p=,--password=}"[Password]:password: " \ + "($help)--password-stdin[Read password from stdin]" \ + "($help -u --username)"{-u=,--username=}"[Username]:username: " \ + "($help -)1:server: " && ret=0 + ;; + (logout) + _arguments $(__docker_arguments) -A '-*' \ + $opts_help \ + "($help -)1:server: " && ret=0 + ;; + (network) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_network_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_network_subcommand && ret=0 + ;; + esac + ;; + (node) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_node_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_node_subcommand && ret=0 + ;; + esac + ;; + (plugin) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_plugin_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_plugin_subcommand && ret=0 + ;; + esac + ;; + (ps) + words[1]='ls' + __docker_container_subcommand && ret=0 + ;; + (rmi) + words[1]='rm' + __docker_image_subcommand && ret=0 + ;; + (search) + _arguments $(__docker_arguments) -A '-*' \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_search_filters" \ + "($help)--limit=[Maximum returned search results]:limit:(1 5 10 25 50)" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -):term: " && ret=0 + ;; + (secret) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_secret_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_secret_subcommand && ret=0 + ;; + esac + ;; + (service) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_service_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_service_subcommand && ret=0 + ;; + esac + ;; + (stack) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_stack_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_stack_subcommand && ret=0 + ;; + esac + ;; + (swarm) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_swarm_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_swarm_subcommand && ret=0 + ;; + esac + ;; + (system) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_system_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_system_subcommand && ret=0 + ;; + esac + ;; + (version) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " && ret=0 + ;; + (volume) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_volume_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_volume_subcommand && ret=0 + ;; + esac + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_commands" && ret=0 + ;; + esac + + return ret +} + +_docker() { + # Support for subservices, which allows for `compdef _docker docker-shell=_docker_containers`. + # Based on /usr/share/zsh/functions/Completion/Unix/_git without support for `ret`. + if [[ $service != docker ]]; then + _call_function - _$service + return + fi + + local curcontext="$curcontext" state line help="-h --help" + integer ret=1 + typeset -A opt_args + + _arguments $(__docker_arguments) -C \ + "(: -)"{-h,--help}"[Print usage]" \ + "($help)--config[Location of client config files]:path:_directories" \ + "($help -c --context)"{-c=,--context=}"[Execute the command in a docker context]:context:__docker_complete_contexts" \ + "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \ + "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \ + "($help -l --log-level)"{-l=,--log-level=}"[Logging level]:level:(debug info warn error fatal)" \ + "($help)--tls[Use TLS]" \ + "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g "*.(pem|crt)"" \ + "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g "*.(pem|crt)"" \ + "($help)--tlskey=[Path to TLS key file]:Key file:_files -g "*.(pem|key)"" \ + "($help)--tlsverify[Use TLS and verify the remote]" \ + "($help)--userland-proxy[Use userland proxy for loopback traffic]" \ + "($help -v --version)"{-v,--version}"[Print version information and quit]" \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + local host=${opt_args[-H]}${opt_args[--host]} + local config=${opt_args[--config]} + local context=${opt_args[-c]}${opt_args[--context]} + local docker_options="${host:+--host $host} ${config:+--config $config} ${context:+--context $context} " + + case $state in + (command) + __docker_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-$words[1]: + __docker_subcommand && ret=0 + ;; + esac + + return ret +} + +_dockerd() { + integer ret=1 + words[1]='daemon' + __docker_subcommand && ret=0 + return ret +} + +_docker "$@" + +# Local Variables: +# mode: Shell-Script +# sh-indentation: 4 +# indent-tabs-mode: nil +# sh-basic-offset: 4 +# End: +# vim: ft=zsh sw=4 ts=4 et diff --git a/plugins/docker/docker.plugin.zsh b/plugins/docker/docker.plugin.zsh index 434b1fc60..b429ae211 100644 --- a/plugins/docker/docker.plugin.zsh +++ b/plugins/docker/docker.plugin.zsh @@ -36,17 +36,27 @@ if (( ! $+commands[docker] )); then return fi +# Standarized $0 handling +# https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html +0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}" +0="${${(M)0:#/*}:-$PWD/$0}" + +# If the completion file doesn't exist yet, we need to autoload it and +# bind it to `docker`. Otherwise, compinit will have already done that. +if [[ ! -f "$ZSH_CACHE_DIR/completions/_docker" ]]; then + typeset -g -A _comps + autoload -Uz _docker + _comps[docker]=_docker +fi + { # `docker completion` is only available from 23.0.0 on - local _docker_version=$(command docker version --format '{{.Client.Version}}' 2>/dev/null) - if is-at-least 23.0.0 $_docker_version; then - # If the completion file doesn't exist yet, we need to autoload it and - # bind it to `docker`. Otherwise, compinit will have already done that. - if [[ ! -f "$ZSH_CACHE_DIR/completions/_docker" ]]; then - typeset -g -A _comps - autoload -Uz _docker - _comps[docker]=_docker - fi - command docker completion zsh >| "$ZSH_CACHE_DIR/completions/_docker" + # docker version returns `Docker version 24.0.2, build cb74dfcd85` + # with `s:,:` remove the comma after the version, and select third word of it + if zstyle -t ':omz:plugins:docker' legacy-completion || \ + ! is-at-least 23.0.0 ${${(s:,:z)"$(command docker --version)"}[3]}; then + command cp "${0:h}/completions/_docker" "$ZSH_CACHE_DIR/completions/_docker" + else + command docker completion zsh | tee "$ZSH_CACHE_DIR/completions/_docker" > /dev/null fi } &| diff --git a/plugins/dotnet/dotnet.plugin.zsh b/plugins/dotnet/dotnet.plugin.zsh index 89d464670..ed7c55024 100644 --- a/plugins/dotnet/dotnet.plugin.zsh +++ b/plugins/dotnet/dotnet.plugin.zsh @@ -1,25 +1,17 @@ # This scripts is copied from (MIT License): -# https://github.com/dotnet/toolset/blob/master/scripts/register-completions.zsh +# https://raw.githubusercontent.com/dotnet/sdk/main/scripts/register-completions.zsh -_dotnet_zsh_complete() -{ - local completions=("$(dotnet complete "$words")") - - # If the completion list is empty, just continue with filename selection - if [ -z "$completions" ] - then - _arguments '*::arguments: _normal' - return - fi - - # This is not a variable assignment, don't remove spaces! - _values = "${(ps:\n:)completions}" +#compdef dotnet +_dotnet_completion() { + local -a completions=("${(@f)$(dotnet complete "${words}")}") + compadd -a completions + _files } -compdef _dotnet_zsh_complete dotnet +compdef _dotnet_completion dotnet # Aliases bellow are here for backwards compatibility -# added by Shaun Tabone (https://github.com/xontab) +# added by Shaun Tabone (https://github.com/xontab) alias dn='dotnet new' alias dr='dotnet run' diff --git a/plugins/emacs/README.md b/plugins/emacs/README.md index 8ed4a1473..47c7644ab 100644 --- a/plugins/emacs/README.md +++ b/plugins/emacs/README.md @@ -27,4 +27,4 @@ The plugin uses a custom launcher (which we'll call here `$EMACS_LAUNCHER`) that | eeval | `$EMACS_LAUNCHER --eval` | Same as `M-x eval` but from outside Emacs | | eframe | `emacsclient --alternate-editor="" --create-frame` | Create new X frame | | efile | - | Print the path to the file open in the current buffer | -| ecd | - | Print the directory of the file open in the the current buffer | +| ecd | - | Print the directory of the file open in the current buffer | diff --git a/plugins/emacs/emacs.plugin.zsh b/plugins/emacs/emacs.plugin.zsh index 4747f035b..5aa621803 100644 --- a/plugins/emacs/emacs.plugin.zsh +++ b/plugins/emacs/emacs.plugin.zsh @@ -60,7 +60,7 @@ function efile { } # Write to standard output the directory of the file -# opened in the the current buffer +# opened in the current buffer function ecd { local file file="$(efile)" || return $? diff --git a/plugins/emoji/emoji.plugin.zsh b/plugins/emoji/emoji.plugin.zsh index f9e476ebf..f7be56cf7 100644 --- a/plugins/emoji/emoji.plugin.zsh +++ b/plugins/emoji/emoji.plugin.zsh @@ -24,7 +24,7 @@ unset _omz_emoji_plugin_dir # This is a combining character that can be placed after any other character to surround # it in a "keycap" symbol. -# The digits 0-9 are already in the emoji table as keycap_digit_, keycap_ten, etc. +# The digits 0-9 are already in the emoji table as keycap_digit_, keycap_ten, etc. # It's unclear whether this should be in the $emoji array, because those characters are all ones # which can be displayed on their own. @@ -63,9 +63,9 @@ function random_emoji() { [[ $list_size -eq 0 ]] && return 1 local random_index=$(( ( RANDOM % $list_size ) + 1 )) local name=${names[$random_index]} - if [[ "$group" == "flags" ]]; then + if [[ "$group" == "flags" ]]; then echo ${emoji_flags[$name]} - else + else echo ${emoji[$name]} fi } @@ -86,22 +86,22 @@ function display_emoji() { # terminals treat these emoji chars as single-width. local counter=1 for i in $names; do - if [[ "$group" == "flags" ]]; then + if [[ "$group" == "flags" ]]; then printf '%s ' "$emoji_flags[$i]" - else - printf '%s ' "$emoji[$i]" + else + printf '%s ' "$emoji[$i]" fi # New line every 20 emoji, to avoid weirdnesses if (($counter % 20 == 0)); then - printf "\n" + printf "\n" fi let counter=$counter+1 done print for i in $names; do - if [[ "$group" == "flags" ]]; then + if [[ "$group" == "flags" ]]; then echo "${emoji_flags[$i]} = $i" - else + else echo "${emoji[$i]} = $i" fi done diff --git a/plugins/emotty/emotty.plugin.zsh b/plugins/emotty/emotty.plugin.zsh index 661169a8b..b48d121dc 100644 --- a/plugins/emotty/emotty.plugin.zsh +++ b/plugins/emotty/emotty.plugin.zsh @@ -4,7 +4,7 @@ # AUTHOR: Alexis Hildebrandt (afh[at]surryhill.net) # VERSION: 1.0.0 # DEPENDS: emoji plugin -# +# # There are different sets of emoji characters available, to choose a different # set export emotty_set to the name of the set you would like to use, e.g.: # % export emotty_set=nature diff --git a/plugins/encode64/README.md b/plugins/encode64/README.md index 7cdf8c3f3..e3e25a742 100644 --- a/plugins/encode64/README.md +++ b/plugins/encode64/README.md @@ -40,7 +40,7 @@ plugins=(... encode64) ### Encoding a file -Encode a file's contents to base64 and save output to text file. +Encode a file's contents to base64 and save output to text file. **NOTE:** Takes provided file and saves encoded content as new file with `.txt` extension - From parameter diff --git a/plugins/extract/extract.plugin.zsh b/plugins/extract/extract.plugin.zsh index b7a823c9f..1c7599195 100644 --- a/plugins/extract/extract.plugin.zsh +++ b/plugins/extract/extract.plugin.zsh @@ -30,6 +30,11 @@ EOF local file="$1" full_path="${1:A}" local extract_dir="${1:t:r}" + # Remove the .tar extension if the file name is .tar.* + if [[ $extract_dir =~ '\.tar$' ]]; then + extract_dir="${extract_dir:r}" + fi + # If there's a file or directory with the same name as the archive # add a random string to the end of the extract directory if [[ -e "$extract_dir" ]]; then @@ -64,8 +69,8 @@ EOF (*.tar.lz) (( $+commands[lzip] )) && tar xvf "$full_path" ;; (*.tar.lz4) lz4 -c -d "$full_path" | tar xvf - ;; (*.tar.lrz) (( $+commands[lrzuntar] )) && lrzuntar "$full_path" ;; - (*.gz) (( $+commands[pigz] )) && pigz -dk "$full_path" || gunzip -k "$full_path" ;; - (*.bz2) bunzip2 "$full_path" ;; + (*.gz) (( $+commands[pigz] )) && pigz -cdk "$full_path" > "${file:t:r}" || gunzip -ck "$full_path" > "${file:t:r}" ;; + (*.bz2) (( $+commands[pbzip2] )) && pbzip2 -d "$full_path" || bunzip2 "$full_path" ;; (*.xz) unxz "$full_path" ;; (*.lrz) (( $+commands[lrunzip] )) && lrunzip "$full_path" ;; (*.lz4) lz4 -d "$full_path" ;; @@ -82,7 +87,7 @@ EOF builtin cd -q control; extract ../control.tar.* builtin cd -q ../data; extract ../data.tar.* builtin cd -q ..; command rm *.tar.* debian-binary ;; - (*.zst) unzstd "$full_path" ;; + (*.zst) unzstd --stdout "$full_path" > "${file:t:r}" ;; (*.cab|*.exe) cabextract "$full_path" ;; (*.cpio|*.obscpio) cpio -idmvF "$full_path" ;; (*.zpaq) zpaq x "$full_path" ;; @@ -106,19 +111,19 @@ EOF # - Y2: at most give 2 files local -a content content=("${extract_dir}"/*(DNY2)) - if [[ ${#content} -eq 1 && -d "${content[1]}" ]]; then - # The extracted folder (${content[1]}) may have the same name as $extract_dir + if [[ ${#content} -eq 1 && -e "${content[1]}" ]]; then + # The extracted file/folder (${content[1]}) may have the same name as $extract_dir # If so, we need to rename it to avoid conflicts in a 3-step process # - # 1. Move and rename the extracted folder to a temporary random name + # 1. Move and rename the extracted file/folder to a temporary random name # 2. Delete the empty folder - # 3. Rename the extracted folder to the original name + # 3. Rename the extracted file/folder to the original name if [[ "${content[1]:t}" == "$extract_dir" ]]; then # =(:) gives /tmp/zsh, with :t it gives zsh - local tmp_dir==(:); tmp_dir="${tmp_dir:t}" - command mv "${content[1]}" "$tmp_dir" \ + local tmp_name==(:); tmp_name="${tmp_name:t}" + command mv "${content[1]}" "$tmp_name" \ && command rmdir "$extract_dir" \ - && command mv "$tmp_dir" "$extract_dir" + && command mv "$tmp_name" "$extract_dir" # Otherwise, if the extracted folder name already exists in the current # directory (because of a previous file / folder), keep the extract_dir elif [[ ! -e "${content[1]:t}" ]]; then diff --git a/plugins/eza/README.md b/plugins/eza/README.md new file mode 100644 index 000000000..5de935c2c --- /dev/null +++ b/plugins/eza/README.md @@ -0,0 +1,101 @@ +# eza plugin + +This provides aliases that invoke the [`eza`](https://github.com/eza-community/eza) utility rather than `ls` + +To use it add `eza` to the plugins array in your zshrc file: + +```zsh +plugins=(... eza) +``` + +## Configuration + +All configurations are done using the `zstyle` command in the `:omz:plugins:eza` namespace. + +**NOTE:** The configuring needs to be done prior to OMZ loading the plugins. When the plugin is loaded, +changing the `zstyle` won't have any effect. + +### `dirs-first` + +```zsh +zstyle ':omz:plugins:eza' 'dirs-first' yes|no +``` + +If `yes`, directories will be grouped first. + +Default: `no` + +### `git-status` + +```zsh +zstyle ':omz:plugins:eza' 'git-status' yes|no +``` + +If `yes`, always add `--git` flag to indicate git status (if tracked / in a git repo). + +Default: `no` + +### `header` + +```zsh +zstyle ':omz:plugins:eza' 'header' yes|no +``` + +If `yes`, always add `-h` flag to add a header row for each column. + +Default: `no` + +### `show-group` + +```zsh +zstyle ':omz:plugins:eza' 'show-group' yes|no +``` + +If `yes` (default), always add `-g` flag to show the group ownership. + +Default: `yes` + +### `size-prefix` + +```zsh +zstyle ':omz:plugins:eza' 'size-prefix' (binary|none|si) +``` + +Choose the prefix to be used in displaying file size: + +- `binary` -- use [binary prefixes](https://en.wikipedia.org/wiki/Binary_prefix) such as "Ki", "Mi", "Gi" and + so on +- `none` -- don't use any prefix, show size in bytes +- `si` (default) -- use [Metric/S.I. prefixes](https://en.wikipedia.org/wiki/Metric_prefix) + +Default: `si` + +### `time-style` + +```zsh +zstyle ':omz:plugins:eza' 'time-style' $TIME_STYLE +``` + +Sets the `--time-style` option of `eza`. (See `man eza` for the options) + +Default: Not set, which means the default behavior of `eza` will take place. + +## Aliases + +**Notes:** + +- Aliases may be modified by Configuration +- The term "files" without "only" qualifier means both files & directories + +| Alias | Command | Description | +| ------ | ----------------- | -------------------------------------------------------------------------- | +| `la` | `eza -la` | List all files (except . and ..) as a long list | +| `ldot` | `eza -ld .*` | List dotfiles only (directories shown as entries instead of recursed into) | +| `lD` | `eza -lD` | List only directories (excluding dotdirs) as a long list | +| `lDD` | `eza -laD` | List only directories (including dotdirs) as a long list | +| `ll` | `eza -l` | List files as a long list | +| `ls` | `eza` | Plain eza call | +| `lsd` | `eza -d` | List specified files with directories as entries, in a grid | +| `lsdl` | `eza -dl` | List specified files with directories as entries, in a long list | +| `lS` | `eza -l -ssize` | List files as a long list, sorted by size | +| `lT` | `eza -l -snewest` | List files as a long list, sorted by date (newest last) | diff --git a/plugins/eza/eza.plugin.zsh b/plugins/eza/eza.plugin.zsh new file mode 100644 index 000000000..6d7f720bd --- /dev/null +++ b/plugins/eza/eza.plugin.zsh @@ -0,0 +1,62 @@ +if ! (( $+commands[eza] )); then + print "zsh eza plugin: eza not found. Please install eza before using this plugin." >&2 + return 1 +fi + +typeset -a _EZA_HEAD +typeset -a _EZA_TAIL + +function _configure_eza() { + local _val + # Get the head flags + if zstyle -T ':omz:plugins:eza' 'show-group'; then + _EZA_HEAD+=("g") + fi + if zstyle -t ':omz:plugins:eza' 'header'; then + _EZA_HEAD+=("h") + fi + zstyle -s ':omz:plugins:eza' 'size-prefix' _val + case "${_val:l}" in + binary) + _EZA_HEAD+=("b") + ;; + none) + _EZA_HEAD+=("B") + ;; + esac + # Get the tail long-options + if zstyle -t ':omz:plugins:eza' 'dirs-first'; then + _EZA_TAIL+=("--group-directories-first") + fi + if zstyle -t ':omz:plugins:eza' 'git-status'; then + _EZA_TAIL+=("--git") + fi + zstyle -s ':omz:plugins:eza' 'time-style' _val + if [[ $_val ]]; then + _EZA_TAIL+=("--time-style='$_val'") + fi +} + +_configure_eza + +function _alias_eza() { + local _head="${(j::)_EZA_HEAD}$2" + local _tail="${(j: :)_EZA_TAIL}" + alias "$1"="eza${_head:+ -}${_head}${_tail:+ }${_tail}${3:+ }$3" +} + +_alias_eza la la +_alias_eza ldot ld ".*" +_alias_eza lD lD +_alias_eza lDD lDa +_alias_eza ll l +_alias_eza ls +_alias_eza lsd d +_alias_eza lsdl dl +_alias_eza lS "l -ssize" +_alias_eza lT "l -snewest" + +unfunction _alias_eza +unfunction _configure_eza +unset _EZA_HEAD +unset _EZA_TAIL diff --git a/plugins/fancy-ctrl-z/README.md b/plugins/fancy-ctrl-z/README.md index f1b1dfa5c..82a4fd75e 100644 --- a/plugins/fancy-ctrl-z/README.md +++ b/plugins/fancy-ctrl-z/README.md @@ -1,14 +1,14 @@ # Use Ctrl-Z to switch back to Vim -I frequently need to execute random commands in my shell. To achieve it I pause +I frequently need to execute random commands in my shell. To achieve it I pause Vim by pressing Ctrl-z, type command and press fg to switch back to Vim. -The fg part really hurts me. I just wanted to hit Ctrl-z once again to get back -to Vim. I could not find a solution, so I developed one on my own that +The fg part really hurts me. I just wanted to hit Ctrl-z once again to get back +to Vim. I could not find a solution, so I developed one on my own that works wonderfully with ZSH. Source: http://sheerun.net/2014/03/21/how-to-boost-your-vim-productivity/ -Credits: +Credits: - original idea by @sheerun - added to OMZ by @mbologna diff --git a/plugins/fastfile/README.md b/plugins/fastfile/README.md index 32f619ffd..7291fde38 100644 --- a/plugins/fastfile/README.md +++ b/plugins/fastfile/README.md @@ -71,13 +71,13 @@ them, add `=` to your zshrc file, before Oh My Zsh is sourced. For example: `fastfile_var_prefix='@'`. - `fastfile_var_prefix`: prefix for the global aliases created. Controls the prefix of the - created global aliases. + created global aliases. **Default:** `§` (section sign), easy to type in a german keyboard via the combination [`⇧ Shift`+`3`](https://en.wikipedia.org/wiki/German_keyboard_layout#/media/File:KB_Germany.svg), or using `⌥ Option`+`6` in macOS. - `fastfile_dir`: directory where the fastfile shortcuts are stored. Needs to end - with a trailing slash. + with a trailing slash. **Default:** `$HOME/.fastfile/`. ## Author diff --git a/plugins/firewalld/firewalld.plugin.zsh b/plugins/firewalld/firewalld.plugin.zsh index 5b1090636..b2c0f64be 100644 --- a/plugins/firewalld/firewalld.plugin.zsh +++ b/plugins/firewalld/firewalld.plugin.zsh @@ -9,7 +9,7 @@ function fwl () { zones=("${(@f)$(sudo firewall-cmd --get-active-zones | grep -v 'interfaces\|sources')}") for i in $zones; do - sudo firewall-cmd --zone $i --list-all + sudo firewall-cmd --zone ${i/ \(default\)} --list-all done echo 'Direct Rules:' diff --git a/plugins/forklift/forklift.plugin.zsh b/plugins/forklift/forklift.plugin.zsh index 85889481b..848aedabf 100644 --- a/plugins/forklift/forklift.plugin.zsh +++ b/plugins/forklift/forklift.plugin.zsh @@ -58,7 +58,7 @@ function fl { tell application forkLiftSetapp activate set forkLiftVersion to version - end tell + end tell else if forkLift3 is not null and application forkLift3 is running then tell application forkLift3 activate @@ -84,7 +84,7 @@ function fl { else if forkLift is not null then set appName to forkLift end if - + tell application appName activate set forkLiftVersion to version diff --git a/plugins/frontend-search/README.md b/plugins/frontend-search/README.md index 050058931..920795060 100644 --- a/plugins/frontend-search/README.md +++ b/plugins/frontend-search/README.md @@ -60,12 +60,22 @@ Available search contexts are: | typescript | `https://google.com/search?as_sitesearch=www.typescriptlang.org/docs&as_q=` | | unheap | `http://www.unheap.com/?s=` | | vuejs | `https://www.google.com/search?as_sitesearch=vuejs.org&as_q=` | +| nextjs | `https://www.google.com/search?as_sitesearch=nextjs.org&as_q=` | If you want to have another context, open an Issue and tell us! ## Fallback search behaviour -The plugin will use Google as a fallback if the docs site for a search context does not have a search function. You can set the fallback search engine to DuckDuckGo by setting `FRONTEND_SEARCH_FALLBACK='duckduckgo'` in your `~/.zshrc` file before Oh My Zsh is sourced. +The plugin will use Google as a fallback if the docs site for a search context does not have a search +function. You can set the fallback search engine to DuckDuckGo by setting +`FRONTEND_SEARCH_FALLBACK='duckduckgo'` in your `~/.zshrc` file before Oh My Zsh is sourced. + +## DuckDuckGo Lucky Search + +Enable DuckDuckGo's "ducky" (lucky) search feature to automatically access the top search result. This feature +is optimized for DuckDuckGo, as Google redirects to an intermediate page. The FRONTEND_SEARCH_FALLBACK_LUCKY +environment variable triggers the use of DuckDuckGo's lucky search, rendering the FRONTEND_SEARCH_FALLBACK +setting unnecessary in this context. ## Author diff --git a/plugins/frontend-search/frontend-search.plugin.zsh b/plugins/frontend-search/frontend-search.plugin.zsh index b9e2fe95d..c96596eb9 100644 --- a/plugins/frontend-search/frontend-search.plugin.zsh +++ b/plugins/frontend-search/frontend-search.plugin.zsh @@ -27,12 +27,19 @@ alias stackoverflow='frontend stackoverflow' alias typescript='frontend typescript' alias unheap='frontend unheap' alias vuejs='frontend vuejs' +alias nextjs='frontend nextjs' function _frontend_fallback() { - case "$FRONTEND_SEARCH_FALLBACK" in - duckduckgo) echo "https://duckduckgo.com/?sites=$1&q=" ;; - *) echo "https://google.com/search?as_sitesearch=$1&as_q=" ;; - esac + if [[ "$FRONTEND_SEARCH_FALLBACK_LUCKY" == "true" ]]; then + case true in + *) echo "https://duckduckgo.com/?q=!ducky+site%3A$1+" ;; + esac + else + case "$FRONTEND_SEARCH_FALLBACK" in + duckduckgo) echo "https://duckduckgo.com/?sites=$1&q=" ;; + *) echo "https://google.com/search?as_sitesearch=$1&as_q=" ;; + esac + fi } function frontend() { @@ -70,6 +77,7 @@ function frontend() { typescript $(_frontend_fallback 'www.typescriptlang.org/docs') unheap 'http://www.unheap.com/?s=' vuejs $(_frontend_fallback 'vuejs.org') + nextjs $(_frontend_fallback 'nextjs.org') ) # show help for command list @@ -81,7 +89,7 @@ function frontend() { print -P "" print -P " angular, angularjs, bem, bootsnipp, caniuse, codepen, compassdoc, cssflow, packagephobia" print -P " dartlang, emberjs, fontello, flowtype, github, html5please, jestjs, jquery, lodash," - print -P " mdn, npmjs, nodejs, qunit, reactjs, smacss, stackoverflow, unheap, vuejs, bundlephobia" + print -P " mdn, npmjs, nodejs, qunit, reactjs, smacss, stackoverflow, unheap, vuejs, bundlephobia, nextjs" print -P "" print -P "For example: frontend npmjs mocha (or just: npmjs mocha)." print -P "" @@ -96,7 +104,7 @@ function frontend() { echo "" echo " angular, angularjs, bem, bootsnipp, caniuse, codepen, compassdoc, cssflow, packagephobia" echo " dartlang, emberjs, fontello, github, html5please, jest, jquery, lodash," - echo " mdn, npmjs, nodejs, qunit, reactjs, smacss, stackoverflow, unheap, vuejs, bundlephobia" + echo " mdn, npmjs, nodejs, qunit, reactjs, smacss, stackoverflow, unheap, vuejs, bundlephobia, nextjs" echo "" return 1 fi diff --git a/plugins/fzf/fzf.plugin.zsh b/plugins/fzf/fzf.plugin.zsh index b253a23d2..3d29f1762 100644 --- a/plugins/fzf/fzf.plugin.zsh +++ b/plugins/fzf/fzf.plugin.zsh @@ -1,3 +1,14 @@ +function fzf_setup_using_fzf() { + (( ${+commands[fzf]} )) || return 1 + + # we remove "fzf " prefix, this fixes really old fzf versions behaviour + # see https://github.com/ohmyzsh/ohmyzsh/issues/12387 + local fzf_ver=${"$(fzf --version)"#fzf } + is-at-least 0.48.0 ${${(s: :)fzf_ver}[1]} || return 1 + + eval "$(fzf --zsh)" +} + function fzf_setup_using_base_dir() { local fzf_base fzf_shell fzfdirs dir @@ -8,6 +19,7 @@ function fzf_setup_using_base_dir() { "${HOME}/.fzf" "${HOME}/.nix-profile/share/fzf" "${XDG_DATA_HOME:-$HOME/.local/share}/fzf" + "${MSYSTEM_PREFIX}/share/fzf" "/usr/local/opt/fzf" "/opt/homebrew/opt/fzf" "/usr/share/fzf" @@ -61,7 +73,7 @@ function fzf_setup_using_base_dir() { function fzf_setup_using_debian() { if (( ! $+commands[apt] && ! $+commands[apt-get] )); then - # Not a debian based distro + # Not a debian based distro return 1 fi @@ -216,7 +228,8 @@ Please add `export FZF_BASE=/path/to/fzf/install/dir` to your .zshrc EOF } -fzf_setup_using_openbsd \ +fzf_setup_using_fzf \ + || fzf_setup_using_openbsd \ || fzf_setup_using_debian \ || fzf_setup_using_opensuse \ || fzf_setup_using_cygwin \ diff --git a/plugins/gas/README.md b/plugins/gas/README.md index 47b3fb9df..a0a7a568f 100644 --- a/plugins/gas/README.md +++ b/plugins/gas/README.md @@ -1,6 +1,6 @@ # Gas plugin -This plugin adds autocompletion for the [gas](http://walle.github.com/gas) command, +This plugin adds autocompletion for the [gas](http://ramblingsby.me/gas/) command, a utility to manage Git authors. To use it, add `gas` to the plugins array of your zshrc file: diff --git a/plugins/gcloud/gcloud.plugin.zsh b/plugins/gcloud/gcloud.plugin.zsh index 5c57302d3..fa8f884a4 100644 --- a/plugins/gcloud/gcloud.plugin.zsh +++ b/plugins/gcloud/gcloud.plugin.zsh @@ -9,6 +9,7 @@ if [[ -z "${CLOUDSDK_HOME}" ]]; then "/usr/local/share/google-cloud-sdk" "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk" "/opt/homebrew/Caskroom/google-cloud-sdk/latest/google-cloud-sdk" + "/opt/homebrew/share/google-cloud-sdk" "/usr/share/google-cloud-sdk" "/snap/google-cloud-sdk/current" "/snap/google-cloud-cli/current" @@ -17,6 +18,7 @@ if [[ -z "${CLOUDSDK_HOME}" ]]; then "/opt/google-cloud-sdk" "/opt/google-cloud-cli" "/opt/local/libexec/google-cloud-sdk" + "$HOME/.asdf/installs/gcloud/*/" ) for gcloud_sdk_location in $search_locations; do @@ -29,11 +31,9 @@ if [[ -z "${CLOUDSDK_HOME}" ]]; then fi if (( ${+CLOUDSDK_HOME} )); then - # Only source this if gcloud isn't already on the path - if (( ! $+commands[gcloud] )); then - if [[ -f "${CLOUDSDK_HOME}/path.zsh.inc" ]]; then - source "${CLOUDSDK_HOME}/path.zsh.inc" - fi + # Source path file + if [[ -f "${CLOUDSDK_HOME}/path.zsh.inc" ]]; then + source "${CLOUDSDK_HOME}/path.zsh.inc" fi # Look for completion file in different paths diff --git a/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh b/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh index 2df34bb7b..f8dfec759 100644 --- a/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh +++ b/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh @@ -29,7 +29,7 @@ function git-fetch-all { date -R &>! "$gitdir/FETCH_LOG" GIT_SSH_COMMAND="command ssh -o BatchMode=yes" \ GIT_TERMINAL_PROMPT=0 \ - command git fetch --all 2>/dev/null &>> "$gitdir/FETCH_LOG" + command git fetch --all --recurse-submodules=yes 2>/dev/null &>> "$gitdir/FETCH_LOG" ) &| } diff --git a/plugins/git-commit/README.md b/plugins/git-commit/README.md new file mode 100644 index 000000000..f812ee23f --- /dev/null +++ b/plugins/git-commit/README.md @@ -0,0 +1,47 @@ +# git-commit plugin + +The git-commit plugin adds several +[git aliases](https://www.git-scm.com/docs/git-config#Documentation/git-config.txt-alias) for +[conventional commit](https://www.conventionalcommits.org/en/v1.0.0/#summary) messages. + +To use it, add `git-commit` to the plugins array in your zshrc file: + +```zsh +plugins=(... git-commit) +``` + +## Syntax + +```zsh +git [(-s, --scope) ""] [(-a, --attention)] "" +``` + +Where `type` is one of the following: + +- `build` +- `chore` +- `ci` +- `docs` +- `feat` +- `fix` +- `perf` +- `refactor` +- `rev` +- `style` +- `test` +- `wip` + +> NOTE: the alias for `revert` type is `rev`, as otherwise it conflicts with the git command of the same name. +> It will still generate a commit message in the format `revert: ` + +> ⚠️ Enabling this plugin will (potentially) overwrite all `alias.` that you manually set. Use with +> care! + +## Examples + +| Git alias | Command | +| --------------------------------------------- | ---------------------------------------------------- | +| `git style "remove trailing whitespace"` | `git commit -m "style: remove trailing whitespace"` | +| `git wip "work in progress"` | `git commit -m "work in progress"` | +| `git fix -s "router" "correct redirect link"` | `git commit -m "fix(router): correct redirect link"` | +| `git rev -s "api" "rollback v2"` | `git commit -m "revert(api): rollback v2"` | diff --git a/plugins/git-commit/git-commit.plugin.zsh b/plugins/git-commit/git-commit.plugin.zsh new file mode 100644 index 000000000..c4df77c80 --- /dev/null +++ b/plugins/git-commit/git-commit.plugin.zsh @@ -0,0 +1,58 @@ +local _rev="$(git -C $ZSH rev-parse HEAD 2> /dev/null)" +if [[ $_rev == $(git config --global --get oh-my-zsh.git-commit-alias 2> /dev/null) ]]; then + return +fi +git config --global oh-my-zsh.git-commit-alias "$_rev" + +local -a _git_commit_aliases +_git_commit_aliases=( + 'build' + 'chore' + 'ci' + 'docs' + 'feat' + 'fix' + 'perf' + 'refactor' + 'revert' + 'style' + 'test' + 'wip' +) + +local _alias _type +for _type in "${_git_commit_aliases[@]}"; do + # an alias can't be named "revert" because the git command takes precedence + # https://stackoverflow.com/a/3538791 + case "$_type" in + revert) _alias=rev ;; + *) _alias=$_type ;; + esac + + local _func='!a() { +local _scope _attention _message +while [ $# -ne 0 ]; do +case $1 in + -s | --scope ) + if [ -z $2 ]; then + echo "Missing scope!" + return 1 + fi + _scope="$2" + shift 2 + ;; + -a | --attention ) + _attention="!" + shift 1 + ;; + * ) + _message="${_message} $1" + shift 1 + ;; +esac +done +git commit -m "'$_type'${_scope:+(${_scope})}${_attention}:${_message}" +}; a' + + git config --global alias.$_alias "$_func" +done diff --git a/plugins/git-prompt/README.md b/plugins/git-prompt/README.md index 05208d72f..8f42c6842 100644 --- a/plugins/git-prompt/README.md +++ b/plugins/git-prompt/README.md @@ -9,6 +9,10 @@ To use it, add `git-prompt` to the plugins array in your zshrc file: plugins=(... git-prompt) ``` +You may also need to [customize your theme](https://github.com/ohmyzsh/ohmyzsh/issues/9395#issuecomment-1027130429) +to change the way the prompt is built. See the +[OMZ wiki on customizing themes](https://github.com/ohmyzsh/ohmyzsh/wiki/Customization#overriding-and-adding-themes). + See the [original repository](https://github.com/olivierverdier/zsh-git-prompt). ## Requirements diff --git a/plugins/git/README.md b/plugins/git/README.md index d18531955..4c005ad2f 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -10,254 +10,274 @@ plugins=(... git) ## Aliases -| Alias | Command | -| :------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| g | git | -| ga | git add | -| gaa | git add --all | -| gapa | git add --patch | -| gau | git add --update | -| gav | git add --verbose | -| gap | git apply | -| gapt | git apply --3way | -| gb | git branch | -| gba | git branch --all | -| gbd | git branch --delete | -| gbda | git branch --no-color --merged \| grep -vE "^([+*]\|\s*($(git_main_branch)\|$(git_develop_branch))\s*$)" \| xargs git branch --delete 2>/dev/null | -| gbD | git branch --delete --force | -| gbg | git branch -vv | grep ": gone\]" | -| gbgd | git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -d | -| gbgD | git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -D | -| gbl | git blame -b -w | -| gbnm | git branch --no-merged | -| gbr | git branch --remote | -| gbs | git bisect | -| gbsb | git bisect bad | -| gbsg | git bisect good | -| gbsr | git bisect reset | -| gbss | git bisect start | -| gc | git commit --verbose | -| gc! | git commit --verbose --amend | -| gcn! | git commit --verbose --no-edit --amend | -| gca | git commit --verbose --all | -| gca! | git commit --verbose --all --amend | -| gcan! | git commit --verbose --all --no-edit --amend | -| gcans! | git commit --verbose --all --signoff --no-edit --amend | -| gcam | git commit --all --message | -| gcas | git commit --all --signoff | -| gcasm | git commit --all --signoff --message | -| gcsm | git commit --signoff --message | -| gcb | git checkout -b | -| gcf | git config --list | -| gcl | git clone --recurse-submodules | -| gccd | git clone --recurse-submodules "$@" && cd "$(basename $\_ .git)" | -| gclean | git clean --interactive -d | -| gpristine | git reset --hard && git clean -dffx | -| gcm | git checkout $(git_main_branch) | -| gcd | git checkout $(git_develop_branch) | -| gcmsg | git commit --message | -| gco | git checkout | -| gcor | git checkout --recurse-submodules | -| gcount | git shortlog --summary -n | -| gcp | git cherry-pick | -| gcpa | git cherry-pick --abort | -| gcpc | git cherry-pick --continue | -| gcs | git commit -S | -| gcss | git commit -S -s | -| gcssm | git commit -S -s -m | -| gd | git diff | -| gdca | git diff --cached | -| gdcw | git diff --cached --word-diff | -| gdct | git describe --tags $(git rev-list --tags --max-count=1) | -| gds | git diff --staged | -| gdt | git diff-tree --no-commit-id --name-only -r | -| gdnolock | git diff $@ ":(exclude)package-lock.json" ":(exclude)\*.lock" | -| gdup | git diff @{upstream} | -| gdv | git diff -w $@ \| view - | -| gdw | git diff --word-diff | -| gf | git fetch | -| gfa | git fetch --all --prune | -| gfg | git ls-files \| grep | -| gfo | git fetch origin | -| gg | git gui citool | -| gga | git gui citool --amend | -| ggf | git push --force origin $(current_branch) | -| ggfl | git push --force-with-lease origin $(current_branch) | -| ggl | git pull origin $(current_branch) | -| ggp | git push origin $(current_branch) | -| ggpnp | ggl && ggp | -| ggpull | git pull origin "$(git_current_branch)" | -| ggpur | ggu | -| ggpush | git push origin "$(git_current_branch)" | -| ggsup | git branch --set-upstream-to=origin/$(git_current_branch) | -| ggu | git pull --rebase origin $(current_branch) | -| gpsup | git push --set-upstream origin $(git_current_branch) | -| gpsupf | git push --set-upstream origin $(git_current_branch) --force-with-lease --force-if-includes (git version >= 2.30) | -| gpsupf | git push --set-upstream origin $(git_current_branch) --force-with-lease (git version < 2.30) | -| ghh | git help | -| gignore | git update-index --assume-unchanged | -| gignored | git ls-files -v \| grep "^[[:lower:]]" | -| git-svn-dcommit-push | git svn dcommit && git push github $(git_main_branch):svntrunk | -| gk | gitk --all --branches &! | -| gke | gitk --all $(git log --walk-reflogs --pretty=%h) &! | -| gl | git pull | -| glg | git log --stat | -| glgp | git log --stat --patch | -| glgg | git log --graph | -| glgga | git log --graph --decorate --all | -| glgm | git log --graph --max-count=10 | -| glo | git log --oneline --decorate | -| glol | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' | -| glols | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --stat | -| glod | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' | -| glods | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --date=short | -| glola | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --all | -| glog | git log --oneline --decorate --graph | -| gloga | git log --oneline --decorate --graph --all | -| glp | git log --pretty=\ | -| gm | git merge | -| gms | git merge --squash | -| gmom | git merge origin/$(git_main_branch) | -| gmtl | git mergetool --no-prompt | -| gmtlvim | git mergetool --no-prompt --tool=vimdiff | -| gmum | git merge upstream/$(git_main_branch) | -| gma | git merge --abort | -| gp | git push | -| gpd | git push --dry-run | -| gpf | git push --force-with-lease --force-if-includes (git version >= 2.30) | -| gpf | git push --force-with-lease (git version < 2.30) | -| gpf! | git push --force | -| gpoat | git push origin --all && git push origin --tags | -| gpod | git push origin --delete | -| gpr | git pull --rebase | -| gpu | git push upstream | -| gpv | git push --verbose | -| gr | git remote | -| gra | git remote add | -| grb | git rebase | -| grba | git rebase --abort | -| grbc | git rebase --continue | -| grbd | git rebase $(git_develop_branch) | -| grbi | git rebase --interactive | -| grbm | git rebase $(git_main_branch) | -| grbom | git rebase origin/$(git_main_branch) | -| grbo | git rebase --onto | -| grbs | git rebase --skip | -| grev | git revert | -| grh | git reset | -| grhh | git reset --hard | -| groh | git reset origin/$(git_current_branch) --hard | -| grm | git rm | -| grmc | git rm --cached | -| grmv | git remote rename | -| grrm | git remote remove | -| grs | git restore | -| grset | git remote set-url | -| grss | git restore --source | -| grst | git restore --staged | -| grt | cd "$(git rev-parse --show-toplevel \|\| echo .)" | -| gru | git reset -- | -| grup | git remote update | -| grv | git remote --verbose | -| gsb | git status --short -b | -| gsd | git svn dcommit | -| gsh | git show | -| gsi | git submodule init | -| gsps | git show --pretty=short --show-signature | -| gsr | git svn rebase | -| gss | git status --short | -| gst | git status | -| gsta | git stash push (git version >= 2.13) | -| gsta | git stash save (git version < 2.13) | -| gstaa | git stash apply | -| gstc | git stash clear | -| gstd | git stash drop | -| gstl | git stash list | -| gstp | git stash pop | -| gsts | git stash show --text | -| gstu | git stash --include-untracked | -| gstall | git stash --all | -| gsu | git submodule update | -| gsw | git switch | -| gswc | git switch -c | -| gswm | git switch $(git_main_branch) | -| gswd | git switch $(git_develop_branch) | -| gts | git tag -s | -| gtv | git tag \| sort -V | -| gtl | gtl(){ git tag --sort=-v:refname -n --list ${1}\* }; noglob gtl | -| gunignore | git update-index --no-assume-unchanged | -| gunwip | git rev-list --max-count=1 --format="%s" HEAD \| grep -q "\-\-wip\-\-" && git reset HEAD~1 | -| gup | git pull --rebase | -| gupv | git pull --rebase --verbose | -| gupa | git pull --rebase --autostash | -| gupav | git pull --rebase --autostash --verbose | -| gupom | git pull --rebase origin $(git_main_branch) | -| gupomi | git pull --rebase=interactive origin $(git_main_branch) | -| glum | git pull upstream $(git_main_branch) | -| gluc | git pull upstream $(git_current_branch) | -| gwch | git whatchanged -p --abbrev-commit --pretty=medium | -| gwip | git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign --message "--wip-- [skip ci]" | -| gam | git am | -| gamc | git am --continue | -| gams | git am --skip | -| gama | git am --abort | -| gamscp | git am --show-current-patch | -| gwt | git worktree | -| gwtls | git worktree list | -| gwtmv | git worktree move | -| gwtrm | git worktree remove | +| Alias | Command | +| :--------------------- | :------------------------------------------------------------------------------------------------------------------------------ | +| `grt` | `cd "$(git rev-parse --show-toplevel \|\| echo .)"` | +| `ggpnp` | `ggl && ggp` | +| `ggpur` | `ggu` | +| `g` | `git` | +| `ga` | `git add` | +| `gaa` | `git add --all` | +| `gapa` | `git add --patch` | +| `gau` | `git add --update` | +| `gav` | `git add --verbose` | +| `gwip` | `git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign --message "--wip-- [skip ci]"` | +| `gam` | `git am` | +| `gama` | `git am --abort` | +| `gamc` | `git am --continue` | +| `gamscp` | `git am --show-current-patch` | +| `gams` | `git am --skip` | +| `gap` | `git apply` | +| `gapt` | `git apply --3way` | +| `gbs` | `git bisect` | +| `gbsb` | `git bisect bad` | +| `gbsg` | `git bisect good` | +| `gbsn` | `git bisect new` | +| `gbso` | `git bisect old` | +| `gbsr` | `git bisect reset` | +| `gbss` | `git bisect start` | +| `gbl` | `git blame -w` | +| `gb` | `git branch` | +| `gba` | `git branch --all` | +| `gbd` | `git branch --delete` | +| `gbD` | `git branch --delete --force` | +| `gbgd` | `LANG=C git branch --no-color -vv \| grep ": gone\]" \| awk '"'"'{print $1}'"'"' \| xargs git branch -d` | +| `gbgD` | `LANG=C git branch --no-color -vv \| grep ": gone\]" \| awk '"'"'{print $1}'"'"' \| xargs git branch -D` | +| `gbm` | `git branch --move` | +| `gbnm` | `git branch --no-merged` | +| `gbr` | `git branch --remote` | +| `ggsup` | `git branch --set-upstream-to=origin/$(git_current_branch)` | +| `gbg` | `LANG=C git branch -vv \| grep ": gone\]"` | +| `gco` | `git checkout` | +| `gcor` | `git checkout --recurse-submodules` | +| `gcb` | `git checkout -b` | +| `gcB` | `git checkout -B` | +| `gcd` | `git checkout $(git_develop_branch)` | +| `gcm` | `git checkout $(git_main_branch)` | +| `gcp` | `git cherry-pick` | +| `gcpa` | `git cherry-pick --abort` | +| `gcpc` | `git cherry-pick --continue` | +| `gclean` | `git clean --interactive -d` | +| `gcl` | `git clone --recurse-submodules` | +| `gccd` | `git clone --recurse-submodules "$@" && cd "$(basename $\_ .git)"` | +| `gcam` | `git commit --all --message` | +| `gcas` | `git commit --all --signoff` | +| `gcasm` | `git commit --all --signoff --message` | +| `gcmsg` | `git commit --message` | +| `gcsm` | `git commit --signoff --message` | +| `gc` | `git commit --verbose` | +| `gca` | `git commit --verbose --all` | +| `gca!` | `git commit --verbose --all --amend` | +| `gcan!` | `git commit --verbose --all --no-edit --amend` | +| `gcans!` | `git commit --verbose --all --signoff --no-edit --amend` | +| `gcann!` | `git commit --verbose --all --date=now --no-edit --amend` | +| `gc!` | `git commit --verbose --amend` | +| `gcn!` | `git commit --verbose --no-edit --amend` | +| `gcs` | `git commit -S` | +| `gcss` | `git commit -S -s` | +| `gcssm` | `git commit -S -s -m` | +| `gcf` | `git config --list` | +| `gdct` | `git describe --tags $(git rev-list --tags --max-count=1)` | +| `gd` | `git diff` | +| `gdca` | `git diff --cached` | +| `gdcw` | `git diff --cached --word-diff` | +| `gds` | `git diff --staged` | +| `gdw` | `git diff --word-diff` | +| `gdv` | `git diff -w "$@" \| view -` | +| `gdup` | `git diff @{upstream}` | +| `gdnolock` | `git diff $@ ":(exclude)package-lock.json" ":(exclude)\*.lock"` | +| `gdt` | `git diff-tree --no-commit-id --name-only -r` | +| `gf` | `git fetch` | +| `gfa` | `git fetch --all --prune` | +| `gfo` | `git fetch origin` | +| `gg` | `git gui citool` | +| `gga` | `git gui citool --amend` | +| `ghh` | `git help` | +| `glgg` | `git log --graph` | +| `glgga` | `git log --graph --decorate --all` | +| `glgm` | `git log --graph --max-count=10` | +| `glod` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset'` | +| `glods` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --date=short` | +| `glol` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset'` | +| `glola` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --all` | +| `glols` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --stat` | +| `glo` | `git log --oneline --decorate` | +| `glog` | `git log --oneline --decorate --graph` | +| `gloga` | `git log --oneline --decorate --graph --all` | +| `glp` | `git log --pretty=` | +| `glg` | `git log --stat` | +| `glgp` | `git log --stat --patch` | +| `gignored` | `git ls-files -v \| grep "^[[:lower:]]"` | +| `gfg` | `git ls-files \| grep` | +| `gm` | `git merge` | +| `gma` | `git merge --abort` | +| `gmc` | `git merge --continue` | +| `gms` | `git merge --squash` | +| `gmom` | `git merge origin/$(git_main_branch)` | +| `gmum` | `git merge upstream/$(git_main_branch)` | +| `gmtl` | `git mergetool --no-prompt` | +| `gmtlvim` | `git mergetool --no-prompt --tool=vimdiff` | +| `gl` | `git pull` | +| `gpr` | `git pull --rebase` | +| `gprv` | `git pull --rebase -v` | +| `gpra` | `git pull --rebase --autostash` | +| `gprav` | `git pull --rebase --autostash -v` | +| `gprom` | `git pull --rebase origin $(git_main_branch)` | +| `gpromi` | `git pull --rebase=interactive origin $(git_main_branch)` | +| `ggpull` | `git pull origin "$(git_current_branch)"` | +| `ggl` | `git pull origin $(current_branch)` | +| `gluc` | `git pull upstream $(git_current_branch)` | +| `glum` | `git pull upstream $(git_main_branch)` | +| `gp` | `git push` | +| `gpd` | `git push --dry-run` | +| `gpf!` | `git push --force` | +| `ggf` | `git push --force origin $(current_branch)` | +| `gpf` | On Git >= 2.30: `git push --force-with-lease --force-if-includes` | +| `gpf` | On Git < 2.30: `git push --force-with-lease` | +| `ggfl` | `git push --force-with-lease origin $(current_branch)` | +| `gpsup` | `git push --set-upstream origin $(git_current_branch)` | +| `gpsupf` | On Git >= 2.30: `git push --set-upstream origin $(git_current_branch) --force-with-lease --force-if-includes` | +| `gpsupf` | On Git < 2.30: `git push --set-upstream origin $(git_current_branch) --force-with-lease` | +| `gpv` | `git push --verbose` | +| `gpoat` | `git push origin --all && git push origin --tags` | +| `gpod` | `git push origin --delete` | +| `ggpush` | `git push origin "$(git_current_branch)"` | +| `ggp` | `git push origin $(current_branch)` | +| `gpu` | `git push upstream` | +| `grb` | `git rebase` | +| `grba` | `git rebase --abort` | +| `grbc` | `git rebase --continue` | +| `grbi` | `git rebase --interactive` | +| `grbo` | `git rebase --onto` | +| `grbs` | `git rebase --skip` | +| `grbd` | `git rebase $(git_develop_branch)` | +| `grbm` | `git rebase $(git_main_branch)` | +| `grbom` | `git rebase origin/$(git_main_branch)` | +| `grf` | `git reflog` | +| `gr` | `git remote` | +| `grv` | `git remote --verbose` | +| `gra` | `git remote add` | +| `grrm` | `git remote remove` | +| `grmv` | `git remote rename` | +| `grset` | `git remote set-url` | +| `grup` | `git remote update` | +| `grh` | `git reset` | +| `gru` | `git reset --` | +| `grhh` | `git reset --hard` | +| `grhk` | `git reset --keep` | +| `grhs` | `git reset --soft` | +| `gpristine` | `git reset --hard && git clean --force -dfx` | +| `gwipe` | `git reset --hard && git clean --force -df` | +| `groh` | `git reset origin/$(git_current_branch) --hard` | +| `grs` | `git restore` | +| `grss` | `git restore --source` | +| `grst` | `git restore --staged` | +| `gunwip` | `git rev-list --max-count=1 --format="%s" HEAD \| grep -q "--wip--" && git reset HEAD~1` | +| `grev` | `git revert` | +| `grm` | `git rm` | +| `grmc` | `git rm --cached` | +| `gcount` | `git shortlog --summary -n` | +| `gsh` | `git show` | +| `gsps` | `git show --pretty=short --show-signature` | +| `gstall` | `git stash --all` | +| `gstu` | `git stash --include-untracked` | +| `gstaa` | `git stash apply` | +| `gstc` | `git stash clear` | +| `gstd` | `git stash drop` | +| `gstl` | `git stash list` | +| `gstp` | `git stash pop` | +| `gsta` | On Git >= 2.13: `git stash push` | +| `gsta` | On Git < 2.13: `git stash save` | +| `gsts` | `git stash show --patch` | +| `gst` | `git status` | +| `gss` | `git status --short` | +| `gsb` | `git status --short -b` | +| `gsi` | `git submodule init` | +| `gsu` | `git submodule update` | +| `gsd` | `git svn dcommit` | +| `git-svn-dcommit-push` | `git svn dcommit && git push github $(git_main_branch):svntrunk` | +| `gsr` | `git svn rebase` | +| `gsw` | `git switch` | +| `gswc` | `git switch -c` | +| `gswd` | `git switch $(git_develop_branch)` | +| `gswm` | `git switch $(git_main_branch)` | +| `gta` | `git tag --annotate` | +| `gts` | `git tag -s` | +| `gtv` | `git tag \| sort -V` | +| `gignore` | `git update-index --assume-unchanged` | +| `gunignore` | `git update-index --no-assume-unchanged` | +| `gwch` | `git whatchanged -p --abbrev-commit --pretty=medium` | +| `gwt` | `git worktree` | +| `gwtls` | `git worktree list` | +| `gwtmv` | `git worktree move` | +| `gwtrm` | `git worktree remove` | +| `gk` | `gitk --all --branches &!` | +| `gke` | `gitk --all $(git log --walk-reflogs --pretty=%h) &!` | +| `gtl` | `gtl(){ git tag --sort=-v:refname -n --list ${1}\* }; noglob gtl` | ### Main branch preference -Following the recent push for removing racially-charged words from our technical vocabulary, the git plugin favors using -a branch name other than `master`. In this case, we favor the shorter, neutral and descriptive term `main`. This means -that any aliases and functions that previously used `master`, will use `main` if that branch exists. We do this via the -function `git_main_branch`. +Following the recent push for removing racially-charged words from our technical vocabulary, the git plugin +favors using a branch name other than `master`. In this case, we favor the shorter, neutral and descriptive +term `main`. This means that any aliases and functions that previously used `master`, will use `main` if that +branch exists. We do this via the function `git_main_branch`. ### Deprecated aliases -These are aliases that have been removed, renamed, or otherwise modified in a way that may, or may not, receive further support. +These are aliases that have been removed, renamed, or otherwise modified in a way that may, or may not, +receive further support. -| Alias | Command | Modification | -| :----- | :----------------------------------------------------- | :----------------------------------------------------- | -| gap | `git add --patch` | new alias `gapa` | -| gcl | `git config --list` | new alias `gcf` | -| gdc | `git diff --cached` | new alias `gdca` | -| gdt | `git difftool` | no replacement | -| ggpull | `git pull origin $(current_branch)` | new alias `ggl` (`ggpull` still exists for now though) | -| ggpur | `git pull --rebase origin $(current_branch)` | new alias `ggu` (`ggpur` still exists for now though) | -| ggpush | `git push origin $(current_branch)` | new alias `ggp` (`ggpush` still exists for now though) | -| gk | `gitk --all --branches` | now aliased to `gitk --all --branches` | -| glg | `git log --stat --max-count = 10` | now aliased to `git log --stat --color` | -| glgg | `git log --graph --max-count = 10` | now aliased to `git log --graph --color` | -| gwc | `git whatchanged -p --abbrev-commit --pretty = medium` | new alias `gwch` | +| Alias | Command | Modification | +| :------- | :-------------------------------------------------------- | :-------------------------------------------------------- | +| `gap` | `git add --patch` | New alias: `gapa`. | +| `gcl` | `git config --list` | New alias: `gcf`. | +| `gdc` | `git diff --cached` | New alias: `gdca`. | +| `gdt` | `git difftool` | No replacement. | +| `ggpull` | `git pull origin $(current_branch)` | New alias: `ggl`. (`ggpull` still exists for now though.) | +| `ggpur` | `git pull --rebase origin $(current_branch)` | New alias: `ggu`. (`ggpur` still exists for now though.) | +| `ggpush` | `git push origin $(current_branch)` | New alias: `ggp`. (`ggpush` still exists for now though.) | +| `gk` | `gitk --all --branches` | Now aliased to `gitk --all --branches`. | +| `glg` | `git log --stat --max-count=10` | Now aliased to `git log --stat --color`. | +| `glgg` | `git log --graph --max-count=10` | Now aliased to `git log --graph --color`. | +| `gwc` | `git whatchanged -p --abbrev-commit --pretty = medium` | New alias: `gwch`. | +| `gup` | `git pull --rebase` | now alias `gpr` | +| `gupv` | `git pull --rebase -v` | now alias `gprv` | +| `gupa` | `git pull --rebase --autostash` | now alias `gpra` | +| `gupav` | `git pull --rebase --autostash -v` | now alias `gprav` | +| `gupom` | `git pull --rebase origin $(git_main_branch)` | now alias `gprom` | +| `gupomi` | `git pull --rebase=interactive origin $(git_main_branch)` | now alias `gpromi` | ## Functions ### Current -| Command | Description | -| :--------------------- | :------------------------------------------------------------------------------------------------------- | -| `grename ` | Rename `old` branch to `new`, including in origin remote | -| current_branch | Return the name of the current branch | -| git_current_user_name | Returns the `user.name` config value | -| git_current_user_email | Returns the `user.email` config value | -| git_main_branch | Returns the name of the main branch: `main` if it exists, `master` otherwise | -| git_develop_branch | Returns the name of the develop branch: `dev`, `devel`, `development` if they exist, `develop` otherwise | +| Command | Description | +| :----------------------- | :-------------------------------------------------------------------------------------------------------------- | +| `current_branch` | Returns the name of the current branch. | +| `git_current_user_email` | Returns the `user.email` config value. (Lives in `lib/git.zsh`.) | +| `git_current_user_name` | Returns the `user.name` config value. (Lives in `lib/git.zsh`.) | +| `git_develop_branch` | Returns the name of the “development” branch: `dev`, `devel`, `development` if they exist, `develop` otherwise. | +| `git_main_branch` | Returns the name of the main branch: `main` if it exists, `master` otherwise. | +| `grename ` | Renames branch `` to ``, including on the origin remote. | +| `gbda` | Deletes all merged branches | +| `gbds` | Deletes all squash-merged branches (**Note: performance degrades with number of branches**) | ### Work in Progress (WIP) -These features allow to pause a branch development and switch to another one (_"Work in Progress"_, or wip). When you want to go back to work, just unwip it. +These features allow you to pause developing one branch and switch to another one (_"Work in Progress"_, or +“wip”). When you want to go back to work, just “unwip” it. -| Command | Description | -| :--------------- | :---------------------------------------------- | -| work_in_progress | Echoes a warning if the current branch is a wip | -| gwip | Commit wip branch | -| gunwip | Uncommit wip branch | -| gunwipall | Uncommit all recent `--wip--` commits | +| Command | Description | +| :----------------- | :---------------------------------------------- | +| `gwip` | Commit wip branch | +| `gunwip` | Uncommit wip branch | +| `gunwipall` | Uncommit all recent `--wip--` commits | +| `work_in_progress` | Echoes a warning if the current branch is a wip | + +Note that `gwip` and `gunwip` are aliases, but are also documented here to group all related WIP features. ### Deprecated functions -| Command | Description | Reason | -| :----------------- | :-------------------------------------- | :-------------------------------------------------------------- | -| current_repository | Return the names of the current remotes | Didn't work properly. Use `git remote -v` instead (`grv` alias) | +| Command | Description | Reason | +| :------------------- | :-------------------------------------- | :--------------------------------------------------------------- | +| `current_repository` | Return the names of the current remotes | Didn't work properly. Use `git remote -v` instead (`grv` alias). | diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index d04edea5e..146f4a512 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -3,7 +3,9 @@ autoload -Uz is-at-least git_version="${${(As: :)$(git version 2>/dev/null)}[3]}" # -# Functions +# Functions Current +# (sorted alphabetically by function name) +# (order should follow README) # # The name of the current branch @@ -14,339 +16,37 @@ function current_branch() { git_current_branch } -# Pretty log messages -function _git_log_prettily(){ - if ! [ -z $1 ]; then - git log --pretty=$1 - fi -} -compdef _git _git_log_prettily=git-log +# Check for develop and similarly named branches +function git_develop_branch() { + command git rev-parse --git-dir &>/dev/null || return + local branch + for branch in dev devel develop development; do + if command git show-ref -q --verify refs/heads/$branch; then + echo $branch + return 0 + fi + done -# Warn if the current branch is a WIP -function work_in_progress() { - command git -c log.showSignature=false log -n 1 2>/dev/null | grep -q -- "--wip--" && echo "WIP!!" -} - -# Similar to `gunwip` but recursive "Unwips" all recent `--wip--` commits not just the last one -function gunwipall() { - local _commit=$(git log --grep='--wip--' --invert-grep --max-count=1 --format=format:%H) - - # Check if a commit without "--wip--" was found and it's not the same as HEAD - if [[ "$_commit" != "$(git rev-parse HEAD)" ]]; then - git reset $_commit || return 1 - fi + echo develop + return 1 } # Check if main exists and use instead of master function git_main_branch() { command git rev-parse --git-dir &>/dev/null || return local ref - for ref in refs/{heads,remotes/{origin,upstream}}/{main,trunk,mainline,default}; do + for ref in refs/{heads,remotes/{origin,upstream}}/{main,trunk,mainline,default,master}; do if command git show-ref -q --verify $ref; then echo ${ref:t} - return + return 0 fi done + + # If no main branch was found, fall back to master but return error echo master + return 1 } -# Check for develop and similarly named branches -function git_develop_branch() { - command git rev-parse --git-dir &>/dev/null || return - local branch - for branch in dev devel development; do - if command git show-ref -q --verify refs/heads/$branch; then - echo $branch - return - fi - done - echo develop -} - -# -# Aliases -# (sorted alphabetically) -# - -alias g='git' - -alias ga='git add' -alias gaa='git add --all' -alias gapa='git add --patch' -alias gau='git add --update' -alias gav='git add --verbose' -alias gap='git apply' -alias gapt='git apply --3way' - -alias gb='git branch' -alias gba='git branch --all' -alias gbd='git branch --delete' -alias gbda='git branch --no-color --merged | command grep -vE "^([+*]|\s*($(git_main_branch)|$(git_develop_branch))\s*$)" | command xargs git branch --delete 2>/dev/null' -alias gbD='git branch --delete --force' -alias gbg='git branch -vv | grep ": gone\]"' -alias gbgd='git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -d' -alias gbgD='git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -D' -alias gbl='git blame -b -w' -alias gbnm='git branch --no-merged' -alias gbr='git branch --remote' -alias gbs='git bisect' -alias gbsb='git bisect bad' -alias gbsg='git bisect good' -alias gbsr='git bisect reset' -alias gbss='git bisect start' - -alias gc='git commit --verbose' -alias gc!='git commit --verbose --amend' -alias gcn!='git commit --verbose --no-edit --amend' -alias gca='git commit --verbose --all' -alias gca!='git commit --verbose --all --amend' -alias gcan!='git commit --verbose --all --no-edit --amend' -alias gcans!='git commit --verbose --all --signoff --no-edit --amend' -alias gcam='git commit --all --message' -alias gcsm='git commit --signoff --message' -alias gcas='git commit --all --signoff' -alias gcasm='git commit --all --signoff --message' -alias gcb='git checkout -b' -alias gcf='git config --list' - -function gccd() { - command git clone --recurse-submodules "$@" - [[ -d "$_" ]] && cd "$_" || cd "${${_:t}%.git}" -} -compdef _git gccd=git-clone - -alias gcl='git clone --recurse-submodules' -alias gclean='git clean --interactive -d' -alias gpristine='git reset --hard && git clean --force -dfx' -alias gcm='git checkout $(git_main_branch)' -alias gcd='git checkout $(git_develop_branch)' -alias gcmsg='git commit --message' -alias gco='git checkout' -alias gcor='git checkout --recurse-submodules' -alias gcount='git shortlog --summary --numbered' -alias gcp='git cherry-pick' -alias gcpa='git cherry-pick --abort' -alias gcpc='git cherry-pick --continue' -alias gcs='git commit --gpg-sign' -alias gcss='git commit --gpg-sign --signoff' -alias gcssm='git commit --gpg-sign --signoff --message' - -alias gd='git diff' -alias gdca='git diff --cached' -alias gdcw='git diff --cached --word-diff' -alias gdct='git describe --tags $(git rev-list --tags --max-count=1)' -alias gds='git diff --staged' -alias gdt='git diff-tree --no-commit-id --name-only -r' -alias gdup='git diff @{upstream}' -alias gdw='git diff --word-diff' - -function gdnolock() { - git diff "$@" ":(exclude)package-lock.json" ":(exclude)*.lock" -} -compdef _git gdnolock=git-diff - -function gdv() { git diff -w "$@" | view - } -compdef _git gdv=git-diff - -alias gf='git fetch' -# --jobs= was added in git 2.8 -is-at-least 2.8 "$git_version" \ - && alias gfa='git fetch --all --prune --jobs=10' \ - || alias gfa='git fetch --all --prune' -alias gfo='git fetch origin' - -alias gfg='git ls-files | grep' - -alias gg='git gui citool' -alias gga='git gui citool --amend' - -function ggf() { - [[ "$#" != 1 ]] && local b="$(git_current_branch)" - git push --force origin "${b:=$1}" -} -compdef _git ggf=git-checkout -function ggfl() { - [[ "$#" != 1 ]] && local b="$(git_current_branch)" - git push --force-with-lease origin "${b:=$1}" -} -compdef _git ggfl=git-checkout - -function ggl() { - if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then - git pull origin "${*}" - else - [[ "$#" == 0 ]] && local b="$(git_current_branch)" - git pull origin "${b:=$1}" - fi -} -compdef _git ggl=git-checkout - -function ggp() { - if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then - git push origin "${*}" - else - [[ "$#" == 0 ]] && local b="$(git_current_branch)" - git push origin "${b:=$1}" - fi -} -compdef _git ggp=git-checkout - -function ggpnp() { - if [[ "$#" == 0 ]]; then - ggl && ggp - else - ggl "${*}" && ggp "${*}" - fi -} -compdef _git ggpnp=git-checkout - -function ggu() { - [[ "$#" != 1 ]] && local b="$(git_current_branch)" - git pull --rebase origin "${b:=$1}" -} -compdef _git ggu=git-checkout - -alias ggpur='ggu' -alias ggpull='git pull origin "$(git_current_branch)"' -alias ggpush='git push origin "$(git_current_branch)"' - -alias ggsup='git branch --set-upstream-to=origin/$(git_current_branch)' -alias gpsup='git push --set-upstream origin $(git_current_branch)' -is-at-least 2.30 "$git_version" \ - && alias gpsupf='git push --set-upstream origin $(git_current_branch) --force-with-lease --force-if-includes' \ - || alias gpsupf='git push --set-upstream origin $(git_current_branch) --force-with-lease' - -alias ghh='git help' - -alias gignore='git update-index --assume-unchanged' -alias gignored='git ls-files -v | grep "^[[:lower:]]"' -alias git-svn-dcommit-push='git svn dcommit && git push github $(git_main_branch):svntrunk' - -alias gk='\gitk --all --branches &!' -alias gke='\gitk --all $(git log --walk-reflogs --pretty=%h) &!' - -alias gl='git pull' -alias glg='git log --stat' -alias glgp='git log --stat --patch' -alias glgg='git log --graph' -alias glgga='git log --graph --decorate --all' -alias glgm='git log --graph --max-count=10' -alias glo='git log --oneline --decorate' -alias glol="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset'" -alias glols="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --stat" -alias glod="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset'" -alias glods="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --date=short" -alias glola="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --all" -alias glog='git log --oneline --decorate --graph' -alias gloga='git log --oneline --decorate --graph --all' -alias glp="_git_log_prettily" - -alias gm='git merge' -alias gmom='git merge origin/$(git_main_branch)' -alias gmtl='git mergetool --no-prompt' -alias gmtlvim='git mergetool --no-prompt --tool=vimdiff' -alias gmum='git merge upstream/$(git_main_branch)' -alias gma='git merge --abort' -alias gms="git merge --squash" - -alias gp='git push' -alias gpd='git push --dry-run' -is-at-least 2.30 "$git_version" \ - && alias gpf='git push --force-with-lease --force-if-includes' \ - || alias gpf='git push --force-with-lease' -alias gpf!='git push --force' -alias gpoat='git push origin --all && git push origin --tags' -alias gpod='git push origin --delete' -alias gpr='git pull --rebase' -alias gpu='git push upstream' -alias gpv='git push --verbose' - -alias gr='git remote' -alias gra='git remote add' -alias grb='git rebase' -alias grba='git rebase --abort' -alias grbc='git rebase --continue' -alias grbd='git rebase $(git_develop_branch)' -alias grbi='git rebase --interactive' -alias grbm='git rebase $(git_main_branch)' -alias grbom='git rebase origin/$(git_main_branch)' -alias grbo='git rebase --onto' -alias grbs='git rebase --skip' -alias grev='git revert' -alias grh='git reset' -alias grhh='git reset --hard' -alias groh='git reset origin/$(git_current_branch) --hard' -alias grm='git rm' -alias grmc='git rm --cached' -alias grmv='git remote rename' -alias grrm='git remote remove' -alias grs='git restore' -alias grset='git remote set-url' -alias grss='git restore --source' -alias grst='git restore --staged' -alias grt='cd "$(git rev-parse --show-toplevel || echo .)"' -alias gru='git reset --' -alias grup='git remote update' -alias grv='git remote --verbose' - -alias gsb='git status --short --branch' -alias gsd='git svn dcommit' -alias gsh='git show' -alias gsi='git submodule init' -alias gsps='git show --pretty=short --show-signature' -alias gsr='git svn rebase' -alias gss='git status --short' -alias gst='git status' - -# use the default stash push on git 2.13 and newer -is-at-least 2.13 "$git_version" \ - && alias gsta='git stash push' \ - || alias gsta='git stash save' - -alias gstaa='git stash apply' -alias gstc='git stash clear' -alias gstd='git stash drop' -alias gstl='git stash list' -alias gstp='git stash pop' -alias gsts='git stash show --text' -alias gstu='gsta --include-untracked' -alias gstall='git stash --all' -alias gsu='git submodule update' -alias gsw='git switch' -alias gswc='git switch --create' -alias gswm='git switch $(git_main_branch)' -alias gswd='git switch $(git_develop_branch)' - -alias gts='git tag --sign' -alias gtv='git tag | sort -V' -alias gtl='gtl(){ git tag --sort=-v:refname -n --list "${1}*" }; noglob gtl' - -alias gunignore='git update-index --no-assume-unchanged' -alias gunwip='git rev-list --max-count=1 --format="%s" HEAD | grep -q "\--wip--" && git reset HEAD~1' -alias gup='git pull --rebase' -alias gupv='git pull --rebase --verbose' -alias gupa='git pull --rebase --autostash' -alias gupav='git pull --rebase --autostash --verbose' -alias gupom='git pull --rebase origin $(git_main_branch)' -alias gupomi='git pull --rebase=interactive origin $(git_main_branch)' -alias glum='git pull upstream $(git_main_branch)' -alias gluc='git pull upstream $(git_current_branch)' - -alias gwch='git whatchanged -p --abbrev-commit --pretty=medium' -alias gwip='git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign --message "--wip-- [skip ci]"' - -alias gwt='git worktree' -alias gwta='git worktree add' -alias gwtls='git worktree list' -alias gwtmv='git worktree move' -alias gwtrm='git worktree remove' - -alias gam='git am' -alias gamc='git am --continue' -alias gams='git am --skip' -alias gama='git am --abort' -alias gamscp='git am --show-current-patch' - function grename() { if [[ -z "$1" || -z "$2" ]]; then echo "Usage: $0 old_branch new_branch" @@ -361,4 +61,363 @@ function grename() { fi } +# +# Functions Work in Progress (WIP) +# (sorted alphabetically by function name) +# (order should follow README) +# + +# Similar to `gunwip` but recursive "Unwips" all recent `--wip--` commits not just the last one +function gunwipall() { + local _commit=$(git log --grep='--wip--' --invert-grep --max-count=1 --format=format:%H) + + # Check if a commit without "--wip--" was found and it's not the same as HEAD + if [[ "$_commit" != "$(git rev-parse HEAD)" ]]; then + git reset $_commit || return 1 + fi +} + +# Warn if the current branch is a WIP +function work_in_progress() { + command git -c log.showSignature=false log -n 1 2>/dev/null | grep -q -- "--wip--" && echo "WIP!!" +} + +# +# Aliases +# (sorted alphabetically by command) +# (order should follow README) +# (in some cases force the alisas order to match README, like for example gke and gk) +# + +alias grt='cd "$(git rev-parse --show-toplevel || echo .)"' + +function ggpnp() { + if [[ "$#" == 0 ]]; then + ggl && ggp + else + ggl "${*}" && ggp "${*}" + fi +} +compdef _git ggpnp=git-checkout + +alias ggpur='ggu' +alias g='git' +alias ga='git add' +alias gaa='git add --all' +alias gapa='git add --patch' +alias gau='git add --update' +alias gav='git add --verbose' +alias gwip='git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign --message "--wip-- [skip ci]"' +alias gam='git am' +alias gama='git am --abort' +alias gamc='git am --continue' +alias gamscp='git am --show-current-patch' +alias gams='git am --skip' +alias gap='git apply' +alias gapt='git apply --3way' +alias gbs='git bisect' +alias gbsb='git bisect bad' +alias gbsg='git bisect good' +alias gbsn='git bisect new' +alias gbso='git bisect old' +alias gbsr='git bisect reset' +alias gbss='git bisect start' +alias gbl='git blame -w' +alias gb='git branch' +alias gba='git branch --all' +alias gbd='git branch --delete' +alias gbD='git branch --delete --force' + +function gbda() { + git branch --no-color --merged | command grep -vE "^([+*]|\s*($(git_main_branch)|$(git_develop_branch))\s*$)" | command xargs git branch --delete 2>/dev/null +} + +# Copied and modified from James Roeder (jmaroeder) under MIT License +# https://github.com/jmaroeder/plugin-git/blob/216723ef4f9e8dde399661c39c80bdf73f4076c4/functions/gbda.fish +function gbds() { + local default_branch=$(git_main_branch) + (( ! $? )) || default_branch=$(git_develop_branch) + + git for-each-ref refs/heads/ "--format=%(refname:short)" | \ + while read branch; do + local merge_base=$(git merge-base $default_branch $branch) + if [[ $(git cherry $default_branch $(git commit-tree $(git rev-parse $branch\^{tree}) -p $merge_base -m _)) = -* ]]; then + git branch -D $branch + fi + done +} + +alias gbgd='LANG=C git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -d' +alias gbgD='LANG=C git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -D' +alias gbm='git branch --move' +alias gbnm='git branch --no-merged' +alias gbr='git branch --remote' +alias ggsup='git branch --set-upstream-to=origin/$(git_current_branch)' +alias gbg='LANG=C git branch -vv | grep ": gone\]"' +alias gco='git checkout' +alias gcor='git checkout --recurse-submodules' +alias gcb='git checkout -b' +alias gcB='git checkout -B' +alias gcd='git checkout $(git_develop_branch)' +alias gcm='git checkout $(git_main_branch)' +alias gcp='git cherry-pick' +alias gcpa='git cherry-pick --abort' +alias gcpc='git cherry-pick --continue' +alias gclean='git clean --interactive -d' +alias gcl='git clone --recurse-submodules' + +function gccd() { + setopt localoptions extendedglob + + # get repo URI from args based on valid formats: https://git-scm.com/docs/git-clone#URLS + local repo="${${@[(r)(ssh://*|git://*|ftp(s)#://*|http(s)#://*|*@*)(.git/#)#]}:-$_}" + + # clone repository and exit if it fails + command git clone --recurse-submodules "$@" || return + + # if last arg passed was a directory, that's where the repo was cloned + # otherwise parse the repo URI and use the last part as the directory + [[ -d "$_" ]] && cd "$_" || cd "${${repo:t}%.git/#}" +} +compdef _git gccd=git-clone + +alias gcam='git commit --all --message' +alias gcas='git commit --all --signoff' +alias gcasm='git commit --all --signoff --message' +alias gcs='git commit --gpg-sign' +alias gcss='git commit --gpg-sign --signoff' +alias gcssm='git commit --gpg-sign --signoff --message' +alias gcmsg='git commit --message' +alias gcsm='git commit --signoff --message' +alias gc='git commit --verbose' +alias gca='git commit --verbose --all' +alias gca!='git commit --verbose --all --amend' +alias gcan!='git commit --verbose --all --no-edit --amend' +alias gcans!='git commit --verbose --all --signoff --no-edit --amend' +alias gcann!='git commit --verbose --all --date=now --no-edit --amend' +alias gc!='git commit --verbose --amend' +alias gcn!='git commit --verbose --no-edit --amend' +alias gcf='git config --list' +alias gdct='git describe --tags $(git rev-list --tags --max-count=1)' +alias gd='git diff' +alias gdca='git diff --cached' +alias gdcw='git diff --cached --word-diff' +alias gds='git diff --staged' +alias gdw='git diff --word-diff' + +function gdv() { git diff -w "$@" | view - } +compdef _git gdv=git-diff + +alias gdup='git diff @{upstream}' + +function gdnolock() { + git diff "$@" ":(exclude)package-lock.json" ":(exclude)*.lock" +} +compdef _git gdnolock=git-diff + +alias gdt='git diff-tree --no-commit-id --name-only -r' +alias gf='git fetch' +# --jobs= was added in git 2.8 +is-at-least 2.8 "$git_version" \ + && alias gfa='git fetch --all --prune --jobs=10' \ + || alias gfa='git fetch --all --prune' +alias gfo='git fetch origin' +alias gg='git gui citool' +alias gga='git gui citool --amend' +alias ghh='git help' +alias glgg='git log --graph' +alias glgga='git log --graph --decorate --all' +alias glgm='git log --graph --max-count=10' +alias glods='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset" --date=short' +alias glod='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset"' +alias glola='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset" --all' +alias glols='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset" --stat' +alias glol='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset"' +alias glo='git log --oneline --decorate' +alias glog='git log --oneline --decorate --graph' +alias gloga='git log --oneline --decorate --graph --all' + +# Pretty log messages +function _git_log_prettily(){ + if ! [ -z $1 ]; then + git log --pretty=$1 + fi +} +compdef _git _git_log_prettily=git-log + +alias glp='_git_log_prettily' +alias glg='git log --stat' +alias glgp='git log --stat --patch' +alias gignored='git ls-files -v | grep "^[[:lower:]]"' +alias gfg='git ls-files | grep' +alias gm='git merge' +alias gma='git merge --abort' +alias gmc='git merge --continue' +alias gms="git merge --squash" +alias gmom='git merge origin/$(git_main_branch)' +alias gmum='git merge upstream/$(git_main_branch)' +alias gmtl='git mergetool --no-prompt' +alias gmtlvim='git mergetool --no-prompt --tool=vimdiff' + +alias gl='git pull' +alias gpr='git pull --rebase' +alias gprv='git pull --rebase -v' +alias gpra='git pull --rebase --autostash' +alias gprav='git pull --rebase --autostash -v' + +function ggu() { + [[ "$#" != 1 ]] && local b="$(git_current_branch)" + git pull --rebase origin "${b:=$1}" +} +compdef _git ggu=git-checkout + +alias gprom='git pull --rebase origin $(git_main_branch)' +alias gpromi='git pull --rebase=interactive origin $(git_main_branch)' +alias ggpull='git pull origin "$(git_current_branch)"' + +function ggl() { + if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then + git pull origin "${*}" + else + [[ "$#" == 0 ]] && local b="$(git_current_branch)" + git pull origin "${b:=$1}" + fi +} +compdef _git ggl=git-checkout + +alias gluc='git pull upstream $(git_current_branch)' +alias glum='git pull upstream $(git_main_branch)' +alias gp='git push' +alias gpd='git push --dry-run' + +function ggf() { + [[ "$#" != 1 ]] && local b="$(git_current_branch)" + git push --force origin "${b:=$1}" +} +compdef _git ggf=git-checkout + +alias gpf!='git push --force' +is-at-least 2.30 "$git_version" \ + && alias gpf='git push --force-with-lease --force-if-includes' \ + || alias gpf='git push --force-with-lease' + +function ggfl() { + [[ "$#" != 1 ]] && local b="$(git_current_branch)" + git push --force-with-lease origin "${b:=$1}" +} +compdef _git ggfl=git-checkout + +alias gpsup='git push --set-upstream origin $(git_current_branch)' +is-at-least 2.30 "$git_version" \ + && alias gpsupf='git push --set-upstream origin $(git_current_branch) --force-with-lease --force-if-includes' \ + || alias gpsupf='git push --set-upstream origin $(git_current_branch) --force-with-lease' +alias gpv='git push --verbose' +alias gpoat='git push origin --all && git push origin --tags' +alias gpod='git push origin --delete' +alias ggpush='git push origin "$(git_current_branch)"' + +function ggp() { + if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then + git push origin "${*}" + else + [[ "$#" == 0 ]] && local b="$(git_current_branch)" + git push origin "${b:=$1}" + fi +} +compdef _git ggp=git-checkout + +alias gpu='git push upstream' +alias grb='git rebase' +alias grba='git rebase --abort' +alias grbc='git rebase --continue' +alias grbi='git rebase --interactive' +alias grbo='git rebase --onto' +alias grbs='git rebase --skip' +alias grbd='git rebase $(git_develop_branch)' +alias grbm='git rebase $(git_main_branch)' +alias grbom='git rebase origin/$(git_main_branch)' +alias grf='git reflog' +alias gr='git remote' +alias grv='git remote --verbose' +alias gra='git remote add' +alias grrm='git remote remove' +alias grmv='git remote rename' +alias grset='git remote set-url' +alias grup='git remote update' +alias grh='git reset' +alias gru='git reset --' +alias grhh='git reset --hard' +alias grhk='git reset --keep' +alias grhs='git reset --soft' +alias gpristine='git reset --hard && git clean --force -dfx' +alias gwipe='git reset --hard && git clean --force -df' +alias groh='git reset origin/$(git_current_branch) --hard' +alias grs='git restore' +alias grss='git restore --source' +alias grst='git restore --staged' +alias gunwip='git rev-list --max-count=1 --format="%s" HEAD | grep -q "\--wip--" && git reset HEAD~1' +alias grev='git revert' +alias greva='git revert --abort' +alias grevc='git revert --continue' +alias grm='git rm' +alias grmc='git rm --cached' +alias gcount='git shortlog --summary --numbered' +alias gsh='git show' +alias gsps='git show --pretty=short --show-signature' +alias gstall='git stash --all' +alias gstaa='git stash apply' +alias gstc='git stash clear' +alias gstd='git stash drop' +alias gstl='git stash list' +alias gstp='git stash pop' +# use the default stash push on git 2.13 and newer +is-at-least 2.13 "$git_version" \ + && alias gsta='git stash push' \ + || alias gsta='git stash save' +alias gsts='git stash show --patch' +alias gst='git status' +alias gss='git status --short' +alias gsb='git status --short --branch' +alias gsi='git submodule init' +alias gsu='git submodule update' +alias gsd='git svn dcommit' +alias git-svn-dcommit-push='git svn dcommit && git push github $(git_main_branch):svntrunk' +alias gsr='git svn rebase' +alias gsw='git switch' +alias gswc='git switch --create' +alias gswd='git switch $(git_develop_branch)' +alias gswm='git switch $(git_main_branch)' +alias gta='git tag --annotate' +alias gts='git tag --sign' +alias gtv='git tag | sort -V' +alias gignore='git update-index --assume-unchanged' +alias gunignore='git update-index --no-assume-unchanged' +alias gwch='git whatchanged -p --abbrev-commit --pretty=medium' +alias gwt='git worktree' +alias gwta='git worktree add' +alias gwtls='git worktree list' +alias gwtmv='git worktree move' +alias gwtrm='git worktree remove' +alias gstu='gsta --include-untracked' +alias gtl='gtl(){ git tag --sort=-v:refname -n --list "${1}*" }; noglob gtl' +alias gk='\gitk --all --branches &!' +alias gke='\gitk --all $(git log --walk-reflogs --pretty=%h) &!' + unset git_version + +# Logic for adding warnings on deprecated aliases +local old_alias new_alias +for old_alias new_alias ( + # TODO(2023-10-19): remove deprecated `git pull --rebase` aliases + gup gpr + gupv gprv + gupa gpra + gupav gprav + gupom gprom + gupomi gpromi +); do + aliases[$old_alias]=" + print -Pu2 \"%F{yellow}[oh-my-zsh] '%F{red}${old_alias}%F{yellow}' is a deprecated alias, using '%F{green}${new_alias}%F{yellow}' instead.%f\" + $new_alias" +done +unset old_alias new_alias diff --git a/plugins/gitfast/README.md b/plugins/gitfast/README.md index fed4b120a..60b84a23c 100644 --- a/plugins/gitfast/README.md +++ b/plugins/gitfast/README.md @@ -7,9 +7,3 @@ To use it, add `gitfast` to the plugins array in your zshrc file: ```zsh plugins=(... gitfast) ``` - -## Aliases - -An earlier version of the plugin also loaded the git plugin. If you want to keep those -aliases enable the [git plugin](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/git) -as well. diff --git a/plugins/gitfast/git-completion.bash b/plugins/gitfast/git-completion.bash index dd06b5048..9a2045f26 100644 --- a/plugins/gitfast/git-completion.bash +++ b/plugins/gitfast/git-completion.bash @@ -58,6 +58,12 @@ # # When set to "1" suggest all options, including options which are # typically hidden (e.g. '--allow-empty' for 'git commit'). +# +# GIT_COMPLETION_IGNORE_CASE +# +# When set, uses for-each-ref '--ignore-case' to find refs that match +# case insensitively, even on systems with case sensitive file systems +# (e.g., completing tag name "FOO" on "git checkout f"). # The following functions are meant to modify COMPREPLY, which should not be # modified directly. The purpose is to localize the modifications so it's @@ -320,116 +326,6 @@ else unset $(compgen -v __gitcomp_builtin_) fi -__gitcomp_builtin_add_default=" --dry-run --verbose --interactive --patch --edit --force --update --renormalize --intent-to-add --all --ignore-removal --refresh --ignore-errors --ignore-missing --sparse --chmod= --pathspec-from-file= --pathspec-file-nul --no-dry-run -- --no-verbose --no-interactive --no-patch --no-edit --no-force --no-update --no-renormalize --no-intent-to-add --no-all --no-ignore-removal --no-refresh --no-ignore-errors --no-ignore-missing --no-sparse --no-chmod --no-pathspec-from-file --no-pathspec-file-nul" -__gitcomp_builtin_am_default=" --interactive --3way --quiet --signoff --utf8 --keep --keep-non-patch --message-id --keep-cr --no-keep-cr --scissors --quoted-cr= --whitespace= --ignore-space-change --ignore-whitespace --directory= --exclude= --include= --patch-format= --reject --resolvemsg= --continue --resolved --skip --abort --quit --show-current-patch --allow-empty --committer-date-is-author-date --ignore-date --rerere-autoupdate --gpg-sign --empty= -- --no-interactive --no-3way --no-quiet --no-signoff --no-utf8 --no-keep --no-keep-non-patch --no-message-id --no-scissors --no-whitespace --no-ignore-space-change --no-ignore-whitespace --no-directory --no-exclude --no-include --no-patch-format --no-reject --no-resolvemsg --no-committer-date-is-author-date --no-ignore-date --no-rerere-autoupdate --no-gpg-sign" -__gitcomp_builtin_apply_default=" --exclude= --include= --no-add --stat --numstat --summary --check --index --intent-to-add --cached --apply --3way --build-fake-ancestor= --whitespace= --ignore-space-change --ignore-whitespace --reverse --unidiff-zero --reject --allow-overlap --verbose --quiet --inaccurate-eof --recount --directory= --allow-empty --add -- --no-stat --no-numstat --no-summary --no-check --no-index --no-intent-to-add --no-cached --no-apply --no-3way --no-build-fake-ancestor --no-whitespace --no-ignore-space-change --no-ignore-whitespace --no-reverse --no-unidiff-zero --no-reject --no-allow-overlap --no-verbose --no-quiet --no-inaccurate-eof --no-recount --no-directory --no-allow-empty" -__gitcomp_builtin_archive_default=" --output= --remote= --exec= --no-output -- --no-remote --no-exec" -__gitcomp_builtin_bisect__helper_default=" --bisect-reset --bisect-next-check --bisect-terms --bisect-start --bisect-next --bisect-state --bisect-log --bisect-replay --bisect-skip --bisect-visualize --bisect-run --no-log --log" -__gitcomp_builtin_blame_default=" --incremental --root --show-stats --progress --score-debug --show-name --show-number --porcelain --line-porcelain --show-email --ignore-rev= --ignore-revs-file= --color-lines --color-by-age --minimal --contents= --abbrev --no-incremental -- --no-root --no-show-stats --no-progress --no-score-debug --no-show-name --no-show-number --no-porcelain --no-line-porcelain --no-show-email --no-ignore-rev --no-ignore-revs-file --no-color-lines --no-color-by-age --no-minimal --no-contents --no-abbrev" -__gitcomp_builtin_branch_default=" --verbose --quiet --track --set-upstream-to= --unset-upstream --color --remotes --contains --no-contains --abbrev --all --delete --move --copy --list --show-current --create-reflog --edit-description --merged --no-merged --column --sort= --points-at= --ignore-case --recurse-submodules --format= -- --no-verbose --no-quiet --no-track --no-set-upstream-to --no-unset-upstream --no-color --no-remotes --no-abbrev --no-all --no-delete --no-move --no-copy --no-list --no-show-current --no-create-reflog --no-edit-description --no-column --no-sort --no-points-at --no-ignore-case --no-recurse-submodules --no-format" -__gitcomp_builtin_bugreport_default=" --output-directory= --suffix= --no-output-directory -- --no-suffix" -__gitcomp_builtin_cat_file_default=" --allow-unknown-type --batch --batch-check --batch-command --batch-all-objects --buffer --follow-symlinks --unordered --textconv --filters --path= --no-allow-unknown-type -- --no-buffer --no-follow-symlinks --no-unordered --no-path" -__gitcomp_builtin_check_attr_default=" --all --cached --stdin --no-all -- --no-cached --no-stdin" -__gitcomp_builtin_check_ignore_default=" --quiet --verbose --stdin --non-matching --no-index --index -- --no-quiet --no-verbose --no-stdin --no-non-matching" -__gitcomp_builtin_check_mailmap_default=" --stdin --no-stdin" -__gitcomp_builtin_checkout_default=" --guess --overlay --quiet --recurse-submodules --progress --merge --conflict= --detach --track --orphan= --ignore-other-worktrees --ours --theirs --patch --ignore-skip-worktree-bits --pathspec-from-file= --pathspec-file-nul --no-guess -- --no-overlay --no-quiet --no-recurse-submodules --no-progress --no-merge --no-conflict --no-detach --no-track --no-orphan --no-ignore-other-worktrees --no-patch --no-ignore-skip-worktree-bits --no-pathspec-from-file --no-pathspec-file-nul" -__gitcomp_builtin_checkout__worker_default=" --prefix= --no-prefix" -__gitcomp_builtin_checkout_index_default=" --all --ignore-skip-worktree-bits --force --quiet --no-create --index --stdin --temp --prefix= --stage= --create -- --no-all --no-ignore-skip-worktree-bits --no-force --no-quiet --no-index --no-stdin --no-temp --no-prefix" -__gitcomp_builtin_cherry_default=" --abbrev --verbose --no-abbrev -- --no-verbose" -__gitcomp_builtin_cherry_pick_default=" --quit --continue --abort --skip --cleanup= --no-commit --edit --signoff --mainline= --rerere-autoupdate --strategy= --strategy-option= --gpg-sign --ff --allow-empty --allow-empty-message --keep-redundant-commits --commit -- --no-cleanup --no-edit --no-signoff --no-mainline --no-rerere-autoupdate --no-strategy --no-strategy-option --no-gpg-sign --no-ff --no-allow-empty --no-allow-empty-message --no-keep-redundant-commits" -__gitcomp_builtin_clean_default=" --quiet --dry-run --interactive --exclude= --no-quiet -- --no-dry-run --no-interactive" -__gitcomp_builtin_clone_default=" --verbose --quiet --progress --reject-shallow --no-checkout --bare --mirror --local --no-hardlinks --shared --recurse-submodules --jobs= --template= --reference= --reference-if-able= --dissociate --origin= --branch= --upload-pack= --depth= --shallow-since= --shallow-exclude= --single-branch --no-tags --shallow-submodules --separate-git-dir= --config= --server-option= --ipv4 --ipv6 --filter= --also-filter-submodules --remote-submodules --sparse --checkout --hardlinks --tags -- --no-verbose --no-quiet --no-progress --no-reject-shallow --no-bare --no-mirror --no-local --no-shared --no-recurse-submodules --no-recursive --no-jobs --no-template --no-reference --no-reference-if-able --no-dissociate --no-origin --no-branch --no-upload-pack --no-depth --no-shallow-since --no-shallow-exclude --no-single-branch --no-shallow-submodules --no-separate-git-dir --no-config --no-server-option --no-ipv4 --no-ipv6 --no-filter --no-also-filter-submodules --no-remote-submodules --no-sparse" -__gitcomp_builtin_column_default=" --command= --mode --raw-mode= --width= --indent= --nl= --padding= --no-command -- --no-mode --no-raw-mode --no-width --no-indent --no-nl --no-padding" -__gitcomp_builtin_commit_default=" --quiet --verbose --file= --author= --date= --message= --reedit-message= --reuse-message= --fixup= --squash= --reset-author --trailer= --signoff --template= --edit --cleanup= --status --gpg-sign --all --include --interactive --patch --only --no-verify --dry-run --short --branch --ahead-behind --porcelain --long --null --amend --no-post-rewrite --untracked-files --pathspec-from-file= --pathspec-file-nul --verify --post-rewrite -- --no-quiet --no-verbose --no-file --no-author --no-date --no-message --no-reedit-message --no-reuse-message --no-fixup --no-squash --no-reset-author --no-signoff --no-template --no-edit --no-cleanup --no-status --no-gpg-sign --no-all --no-include --no-interactive --no-patch --no-only --no-dry-run --no-short --no-branch --no-ahead-behind --no-porcelain --no-long --no-null --no-amend --no-untracked-files --no-pathspec-from-file --no-pathspec-file-nul" -__gitcomp_builtin_commit_graph_default=" --object-dir= --no-object-dir" -__gitcomp_builtin_config_default=" --global --system --local --worktree --file= --blob= --get --get-all --get-regexp --get-urlmatch --replace-all --add --unset --unset-all --rename-section --remove-section --list --fixed-value --edit --get-color --get-colorbool --type= --bool --int --bool-or-int --bool-or-str --path --expiry-date --null --name-only --includes --show-origin --show-scope --default= --no-global -- --no-system --no-local --no-worktree --no-file --no-blob --no-get --no-get-all --no-get-regexp --no-get-urlmatch --no-replace-all --no-add --no-unset --no-unset-all --no-rename-section --no-remove-section --no-list --no-fixed-value --no-edit --no-get-color --no-get-colorbool --no-type --no-null --no-name-only --no-includes --no-show-origin --no-show-scope --no-default" -__gitcomp_builtin_count_objects_default=" --verbose --human-readable --no-verbose -- --no-human-readable" -__gitcomp_builtin_credential_cache_default=" --timeout= --socket= --no-timeout -- --no-socket" -__gitcomp_builtin_credential_cache__daemon_default=" --debug --no-debug" -__gitcomp_builtin_credential_store_default=" --file= --no-file" -__gitcomp_builtin_describe_default=" --contains --debug --all --tags --long --first-parent --abbrev --exact-match --candidates= --match= --exclude= --always --dirty --broken --no-contains -- --no-debug --no-all --no-tags --no-long --no-first-parent --no-abbrev --no-exact-match --no-candidates --no-match --no-exclude --no-always --no-dirty --no-broken" -__gitcomp_builtin_difftool_default=" --gui --dir-diff --no-prompt --symlinks --tool= --tool-help --trust-exit-code --extcmd= --no-index --index -- --no-gui --no-dir-diff --no-symlinks --no-tool --no-tool-help --no-trust-exit-code --no-extcmd" -__gitcomp_builtin_env__helper_default=" --type= --default= --exit-code --no-default -- --no-exit-code" -__gitcomp_builtin_fast_export_default=" --progress= --signed-tags= --tag-of-filtered-object= --reencode= --export-marks= --import-marks= --import-marks-if-exists= --fake-missing-tagger --full-tree --use-done-feature --no-data --refspec= --anonymize --anonymize-map= --reference-excluded-parents --show-original-ids --mark-tags --data -- --no-progress --no-signed-tags --no-tag-of-filtered-object --no-reencode --no-export-marks --no-import-marks --no-import-marks-if-exists --no-fake-missing-tagger --no-full-tree --no-use-done-feature --no-refspec --no-anonymize --no-reference-excluded-parents --no-show-original-ids --no-mark-tags" -__gitcomp_builtin_fetch_default=" --verbose --quiet --all --set-upstream --append --atomic --upload-pack= --force --multiple --tags --jobs= --prefetch --prune --prune-tags --recurse-submodules --dry-run --write-fetch-head --keep --update-head-ok --progress --depth= --shallow-since= --shallow-exclude= --deepen= --unshallow --refetch --update-shallow --refmap= --server-option= --ipv4 --ipv6 --negotiation-tip= --negotiate-only --filter= --auto-maintenance --auto-gc --show-forced-updates --write-commit-graph --stdin --no-verbose -- --no-quiet --no-all --no-set-upstream --no-append --no-atomic --no-upload-pack --no-force --no-multiple --no-tags --no-jobs --no-prefetch --no-prune --no-prune-tags --no-recurse-submodules --no-dry-run --no-write-fetch-head --no-keep --no-update-head-ok --no-progress --no-depth --no-shallow-since --no-shallow-exclude --no-deepen --no-update-shallow --no-server-option --no-ipv4 --no-ipv6 --no-negotiation-tip --no-negotiate-only --no-filter --no-auto-maintenance --no-auto-gc --no-show-forced-updates --no-write-commit-graph --no-stdin" -__gitcomp_builtin_fmt_merge_msg_default=" --log --message= --into-name= --file= --no-log -- --no-message --no-into-name --no-file" -__gitcomp_builtin_for_each_ref_default=" --shell --perl --python --tcl --count= --format= --color --sort= --points-at= --merged --no-merged --contains --no-contains --ignore-case -- --no-shell --no-perl --no-python --no-tcl --no-count --no-format --no-color --no-sort --no-points-at --no-ignore-case" -__gitcomp_builtin_for_each_repo_default=" --config= --no-config" -__gitcomp_builtin_format_patch_default=" --numbered --no-numbered --signoff --stdout --cover-letter --numbered-files --suffix= --start-number= --reroll-count= --filename-max-length= --rfc --cover-from-description= --subject-prefix= --output-directory= --keep-subject --no-binary --zero-commit --ignore-if-in-upstream --no-stat --add-header= --to= --cc= --from --in-reply-to= --attach --inline --thread --signature= --base= --signature-file= --quiet --progress --interdiff= --range-diff= --creation-factor= --binary -- --no-numbered --no-signoff --no-stdout --no-cover-letter --no-numbered-files --no-suffix --no-start-number --no-reroll-count --no-filename-max-length --no-cover-from-description --no-zero-commit --no-ignore-if-in-upstream --no-add-header --no-to --no-cc --no-from --no-in-reply-to --no-attach --no-thread --no-signature --no-base --no-signature-file --no-quiet --no-progress --no-interdiff --no-range-diff --no-creation-factor" -__gitcomp_builtin_fsck_default=" --verbose --unreachable --dangling --tags --root --cache --reflogs --full --connectivity-only --strict --lost-found --progress --name-objects --no-verbose -- --no-unreachable --no-dangling --no-tags --no-root --no-cache --no-reflogs --no-full --no-connectivity-only --no-strict --no-lost-found --no-progress --no-name-objects" -__gitcomp_builtin_fsck_objects_default=" --verbose --unreachable --dangling --tags --root --cache --reflogs --full --connectivity-only --strict --lost-found --progress --name-objects --no-verbose -- --no-unreachable --no-dangling --no-tags --no-root --no-cache --no-reflogs --no-full --no-connectivity-only --no-strict --no-lost-found --no-progress --no-name-objects" -__gitcomp_builtin_fsmonitor__daemon_default="" -__gitcomp_builtin_gc_default=" --quiet --prune --aggressive --keep-largest-pack --no-quiet -- --no-prune --no-aggressive --no-keep-largest-pack" -__gitcomp_builtin_grep_default=" --cached --no-index --untracked --exclude-standard --recurse-submodules --invert-match --ignore-case --word-regexp --text --textconv --recursive --max-depth= --extended-regexp --basic-regexp --fixed-strings --perl-regexp --line-number --column --full-name --files-with-matches --name-only --files-without-match --only-matching --count --color --break --heading --context= --before-context= --after-context= --threads= --show-function --function-context --and --or --not --quiet --all-match --index -- --no-cached --no-untracked --no-exclude-standard --no-recurse-submodules --no-invert-match --no-ignore-case --no-word-regexp --no-text --no-textconv --no-recursive --no-extended-regexp --no-basic-regexp --no-fixed-strings --no-perl-regexp --no-line-number --no-column --no-full-name --no-files-with-matches --no-name-only --no-files-without-match --no-only-matching --no-count --no-color --no-break --no-heading --no-context --no-before-context --no-after-context --no-threads --no-show-function --no-function-context --no-or --no-quiet --no-all-match" -__gitcomp_builtin_hash_object_default=" --stdin --stdin-paths --no-filters --literally --path= --filters -- --no-stdin --no-stdin-paths --no-literally --no-path" -__gitcomp_builtin_help_default=" --all --external-commands --aliases --man --web --info --verbose --guides --config --no-external-commands -- --no-aliases --no-man --no-web --no-info --no-verbose" -__gitcomp_builtin_hook_default="" -__gitcomp_builtin_init_default=" --template= --bare --shared --quiet --separate-git-dir= --initial-branch= --object-format= --no-template -- --no-bare --no-quiet --no-separate-git-dir --no-initial-branch --no-object-format" -__gitcomp_builtin_init_db_default=" --template= --bare --shared --quiet --separate-git-dir= --initial-branch= --object-format= --no-template -- --no-bare --no-quiet --no-separate-git-dir --no-initial-branch --no-object-format" -__gitcomp_builtin_interpret_trailers_default=" --in-place --trim-empty --where= --if-exists= --if-missing= --only-trailers --only-input --unfold --parse --no-divider --trailer= --divider -- --no-in-place --no-trim-empty --no-where --no-if-exists --no-if-missing --no-only-trailers --no-only-input --no-unfold --no-trailer" -__gitcomp_builtin_log_default=" --quiet --source --use-mailmap --decorate-refs= --decorate-refs-exclude= --decorate --no-quiet -- --no-source --no-use-mailmap --no-mailmap --no-decorate-refs --no-decorate-refs-exclude --no-decorate" -__gitcomp_builtin_ls_files_default=" --cached --deleted --modified --others --ignored --stage --killed --directory --eol --empty-directory --unmerged --resolve-undo --exclude= --exclude-from= --exclude-per-directory= --exclude-standard --full-name --recurse-submodules --error-unmatch --with-tree= --abbrev --debug --deduplicate --sparse --no-cached -- --no-deleted --no-modified --no-others --no-ignored --no-stage --no-killed --no-directory --no-eol --no-empty-directory --no-unmerged --no-resolve-undo --no-exclude-per-directory --no-recurse-submodules --no-error-unmatch --no-with-tree --no-abbrev --no-debug --no-deduplicate --no-sparse" -__gitcomp_builtin_ls_remote_default=" --quiet --upload-pack= --tags --heads --refs --get-url --sort= --symref --server-option= --no-quiet -- --no-upload-pack --no-tags --no-heads --no-refs --no-get-url --no-sort --no-symref --no-server-option" -__gitcomp_builtin_ls_tree_default=" --long --name-only --name-status --object-only --full-name --full-tree --format= --abbrev --no-full-name -- --no-full-tree --no-abbrev" -__gitcomp_builtin_merge_default=" --stat --summary --log --squash --commit --edit --cleanup= --ff --ff-only --rerere-autoupdate --verify-signatures --strategy= --strategy-option= --message= --file --into-name= --verbose --quiet --abort --quit --continue --allow-unrelated-histories --progress --gpg-sign --autostash --overwrite-ignore --signoff --no-verify --verify -- --no-stat --no-summary --no-log --no-squash --no-commit --no-edit --no-cleanup --no-ff --no-rerere-autoupdate --no-verify-signatures --no-strategy --no-strategy-option --no-message --no-into-name --no-verbose --no-quiet --no-abort --no-quit --no-continue --no-allow-unrelated-histories --no-progress --no-gpg-sign --no-autostash --no-overwrite-ignore --no-signoff" -__gitcomp_builtin_merge_base_default=" --all --octopus --independent --is-ancestor --fork-point --no-all" -__gitcomp_builtin_merge_file_default=" --stdout --diff3 --zdiff3 --ours --theirs --union --marker-size= --quiet --no-stdout -- --no-diff3 --no-zdiff3 --no-ours --no-theirs --no-union --no-marker-size --no-quiet" -__gitcomp_builtin_mktree_default=" --missing --batch --no-missing -- --no-batch" -__gitcomp_builtin_multi_pack_index_default=" --object-dir= --no-object-dir" -__gitcomp_builtin_mv_default=" --verbose --dry-run --sparse --no-verbose -- --no-dry-run --no-sparse" -__gitcomp_builtin_name_rev_default=" --name-only --tags --refs= --exclude= --all --stdin --annotate-stdin --undefined --always --no-name-only -- --no-tags --no-refs --no-exclude --no-all --no-stdin --no-annotate-stdin --no-undefined --no-always" -__gitcomp_builtin_notes_default=" --ref= --no-ref" -__gitcomp_builtin_pack_objects_default=" --quiet --progress --all-progress --all-progress-implied --index-version= --max-pack-size= --local --incremental --window= --window-memory= --depth= --reuse-delta --reuse-object --delta-base-offset --threads= --non-empty --revs --unpacked --all --reflog --indexed-objects --stdin-packs --stdout --include-tag --keep-unreachable --pack-loose-unreachable --unpack-unreachable --sparse --thin --shallow --honor-pack-keep --keep-pack= --compression= --keep-true-parents --use-bitmap-index --write-bitmap-index --filter= --missing= --exclude-promisor-objects --delta-islands --uri-protocol= --no-quiet -- --no-progress --no-all-progress --no-all-progress-implied --no-local --no-incremental --no-window --no-depth --no-reuse-delta --no-reuse-object --no-delta-base-offset --no-threads --no-non-empty --no-revs --no-stdin-packs --no-stdout --no-include-tag --no-keep-unreachable --no-pack-loose-unreachable --no-unpack-unreachable --no-sparse --no-thin --no-shallow --no-honor-pack-keep --no-keep-pack --no-compression --no-keep-true-parents --no-use-bitmap-index --no-write-bitmap-index --no-filter --no-exclude-promisor-objects --no-delta-islands --no-uri-protocol" -__gitcomp_builtin_pack_refs_default=" --all --prune --no-all -- --no-prune" -__gitcomp_builtin_pickaxe_default=" --incremental --root --show-stats --progress --score-debug --show-name --show-number --porcelain --line-porcelain --show-email --ignore-rev= --ignore-revs-file= --color-lines --color-by-age --minimal --contents= --abbrev --no-incremental -- --no-root --no-show-stats --no-progress --no-score-debug --no-show-name --no-show-number --no-porcelain --no-line-porcelain --no-show-email --no-ignore-rev --no-ignore-revs-file --no-color-lines --no-color-by-age --no-minimal --no-contents --no-abbrev" -__gitcomp_builtin_prune_default=" --dry-run --verbose --progress --expire= --exclude-promisor-objects --no-dry-run -- --no-verbose --no-progress --no-expire --no-exclude-promisor-objects" -__gitcomp_builtin_prune_packed_default=" --dry-run --quiet --no-dry-run -- --no-quiet" -__gitcomp_builtin_pull_default=" --verbose --quiet --progress --recurse-submodules --rebase --stat --log --signoff --squash --commit --edit --cleanup= --ff --ff-only --verify --verify-signatures --autostash --strategy= --strategy-option= --gpg-sign --allow-unrelated-histories --all --append --upload-pack= --force --tags --prune --jobs --dry-run --keep --depth= --shallow-since= --shallow-exclude= --deepen= --unshallow --update-shallow --refmap= --server-option= --ipv4 --ipv6 --negotiation-tip= --show-forced-updates --set-upstream --no-verbose -- --no-quiet --no-progress --no-recurse-submodules --no-rebase --no-stat --no-log --no-signoff --no-squash --no-commit --no-edit --no-cleanup --no-ff --no-verify --no-verify-signatures --no-autostash --no-strategy --no-strategy-option --no-gpg-sign --no-allow-unrelated-histories --no-all --no-append --no-upload-pack --no-force --no-tags --no-prune --no-jobs --no-dry-run --no-keep --no-depth --no-shallow-since --no-shallow-exclude --no-deepen --no-update-shallow --no-server-option --no-ipv4 --no-ipv6 --no-negotiation-tip --no-show-forced-updates --no-set-upstream" -__gitcomp_builtin_push_default=" --verbose --quiet --repo= --all --mirror --delete --tags --dry-run --porcelain --force --force-with-lease --force-if-includes --recurse-submodules= --receive-pack= --exec= --set-upstream --progress --prune --no-verify --follow-tags --signed --atomic --push-option= --ipv4 --ipv6 --verify -- --no-verbose --no-quiet --no-repo --no-all --no-mirror --no-delete --no-tags --no-dry-run --no-porcelain --no-force --no-force-with-lease --no-force-if-includes --no-recurse-submodules --no-receive-pack --no-exec --no-set-upstream --no-progress --no-prune --no-follow-tags --no-signed --no-atomic --no-push-option --no-ipv4 --no-ipv6" -__gitcomp_builtin_range_diff_default=" --creation-factor= --no-dual-color --notes --left-only --right-only --patch --no-patch --unified --function-context --raw --patch-with-raw --patch-with-stat --numstat --shortstat --dirstat --cumulative --dirstat-by-file --check --summary --name-only --name-status --stat --stat-width= --stat-name-width= --stat-graph-width= --stat-count= --compact-summary --binary --full-index --color --ws-error-highlight= --abbrev --src-prefix= --dst-prefix= --line-prefix= --no-prefix --inter-hunk-context= --output-indicator-new= --output-indicator-old= --output-indicator-context= --break-rewrites --find-renames --irreversible-delete --find-copies --find-copies-harder --no-renames --rename-empty --follow --minimal --ignore-all-space --ignore-space-change --ignore-space-at-eol --ignore-cr-at-eol --ignore-blank-lines --ignore-matching-lines= --indent-heuristic --patience --histogram --diff-algorithm= --anchored= --word-diff --word-diff-regex= --color-words --color-moved --color-moved-ws= --relative --text --exit-code --quiet --ext-diff --textconv --ignore-submodules --submodule --ita-invisible-in-index --ita-visible-in-index --pickaxe-all --pickaxe-regex --rotate-to= --skip-to= --find-object= --diff-filter= --output= --dual-color -- --no-creation-factor --no-notes --no-left-only --no-right-only --no-function-context --no-compact-summary --no-full-index --no-color --no-abbrev --no-find-copies-harder --no-rename-empty --no-follow --no-minimal --no-ignore-matching-lines --no-indent-heuristic --no-color-moved --no-color-moved-ws --no-relative --no-text --no-exit-code --no-quiet --no-ext-diff --no-textconv" -__gitcomp_builtin_read_tree_default=" --index-output= --empty --verbose --trivial --aggressive --reset --prefix= --exclude-per-directory= --dry-run --no-sparse-checkout --debug-unpack --recurse-submodules --quiet --sparse-checkout -- --no-empty --no-verbose --no-trivial --no-aggressive --no-reset --no-dry-run --no-debug-unpack --no-recurse-submodules --no-quiet" -__gitcomp_builtin_rebase_default=" --onto= --keep-base --no-verify --quiet --verbose --no-stat --signoff --committer-date-is-author-date --reset-author-date --ignore-whitespace --whitespace= --force-rebase --no-ff --continue --skip --abort --quit --edit-todo --show-current-patch --apply --merge --interactive --rerere-autoupdate --empty= --autosquash --gpg-sign --autostash --exec= --rebase-merges --fork-point --strategy= --strategy-option= --root --reschedule-failed-exec --reapply-cherry-picks --verify --stat --ff -- --no-onto --no-keep-base --no-quiet --no-verbose --no-signoff --no-committer-date-is-author-date --no-reset-author-date --no-ignore-whitespace --no-whitespace --no-force-rebase --no-rerere-autoupdate --no-autosquash --no-gpg-sign --no-autostash --no-exec --no-rebase-merges --no-fork-point --no-strategy --no-strategy-option --no-root --no-reschedule-failed-exec --no-reapply-cherry-picks" -__gitcomp_builtin_receive_pack_default=" --quiet --no-quiet" -__gitcomp_builtin_reflog_default="" -__gitcomp_builtin_remote_default=" --verbose --no-verbose" -__gitcomp_builtin_repack_default=" --quiet --local --write-bitmap-index --delta-islands --unpack-unreachable= --keep-unreachable --window= --window-memory= --depth= --threads= --max-pack-size= --pack-kept-objects --keep-pack= --geometric= --write-midx --no-quiet -- --no-local --no-write-bitmap-index --no-delta-islands --no-unpack-unreachable --no-keep-unreachable --no-window --no-window-memory --no-depth --no-threads --no-max-pack-size --no-pack-kept-objects --no-keep-pack --no-geometric --no-write-midx" -__gitcomp_builtin_replace_default=" --list --delete --edit --graft --convert-graft-file --raw --format= --no-raw -- --no-format" -__gitcomp_builtin_rerere_default=" --rerere-autoupdate --no-rerere-autoupdate" -__gitcomp_builtin_reset_default=" --quiet --no-refresh --mixed --soft --hard --merge --keep --recurse-submodules --patch --intent-to-add --pathspec-from-file= --pathspec-file-nul --refresh -- --no-quiet --no-mixed --no-soft --no-hard --no-merge --no-keep --no-recurse-submodules --no-patch --no-intent-to-add --no-pathspec-from-file --no-pathspec-file-nul" -__gitcomp_builtin_restore_default=" --source= --staged --worktree --ignore-unmerged --overlay --quiet --recurse-submodules --progress --merge --conflict= --ours --theirs --patch --ignore-skip-worktree-bits --pathspec-from-file= --pathspec-file-nul --no-source -- --no-staged --no-worktree --no-ignore-unmerged --no-overlay --no-quiet --no-recurse-submodules --no-progress --no-merge --no-conflict --no-patch --no-ignore-skip-worktree-bits --no-pathspec-from-file --no-pathspec-file-nul" -__gitcomp_builtin_revert_default=" --quit --continue --abort --skip --cleanup= --no-commit --edit --signoff --mainline= --rerere-autoupdate --strategy= --strategy-option= --gpg-sign --commit -- --no-cleanup --no-edit --no-signoff --no-mainline --no-rerere-autoupdate --no-strategy --no-strategy-option --no-gpg-sign" -__gitcomp_builtin_rm_default=" --dry-run --quiet --cached --ignore-unmatch --sparse --pathspec-from-file= --pathspec-file-nul --no-dry-run -- --no-quiet --no-cached --no-ignore-unmatch --no-sparse --no-pathspec-from-file --no-pathspec-file-nul" -__gitcomp_builtin_send_pack_default=" --verbose --quiet --receive-pack= --exec= --remote= --all --dry-run --mirror --force --signed --push-option= --progress --thin --atomic --stateless-rpc --stdin --helper-status --force-with-lease --force-if-includes --no-verbose -- --no-quiet --no-receive-pack --no-exec --no-remote --no-all --no-dry-run --no-mirror --no-force --no-signed --no-push-option --no-progress --no-thin --no-atomic --no-stateless-rpc --no-stdin --no-helper-status --no-force-with-lease --no-force-if-includes" -__gitcomp_builtin_shortlog_default=" --committer --numbered --summary --email --group= --no-committer -- --no-numbered --no-summary --no-email --no-group" -__gitcomp_builtin_show_default=" --quiet --source --use-mailmap --decorate-refs= --decorate-refs-exclude= --decorate --no-quiet -- --no-source --no-use-mailmap --no-mailmap --no-decorate-refs --no-decorate-refs-exclude --no-decorate" -__gitcomp_builtin_show_branch_default=" --all --remotes --color --more --list --no-name --current --sha1-name --merge-base --independent --topo-order --topics --sparse --date-order --reflog --name -- --no-all --no-remotes --no-color --no-more --no-list --no-current --no-sha1-name --no-merge-base --no-independent --no-topo-order --no-topics --no-sparse --no-date-order" -__gitcomp_builtin_show_index_default=" --object-format= --no-object-format" -__gitcomp_builtin_show_ref_default=" --tags --heads --verify --head --dereference --hash --abbrev --quiet --exclude-existing --no-tags -- --no-heads --no-verify --no-head --no-dereference --no-hash --no-abbrev --no-quiet" -__gitcomp_builtin_sparse_checkout_default="" -__gitcomp_builtin_stage_default=" --dry-run --verbose --interactive --patch --edit --force --update --renormalize --intent-to-add --all --ignore-removal --refresh --ignore-errors --ignore-missing --sparse --chmod= --pathspec-from-file= --pathspec-file-nul --no-dry-run -- --no-verbose --no-interactive --no-patch --no-edit --no-force --no-update --no-renormalize --no-intent-to-add --no-all --no-ignore-removal --no-refresh --no-ignore-errors --no-ignore-missing --no-sparse --no-chmod --no-pathspec-from-file --no-pathspec-file-nul" -__gitcomp_builtin_stash_default="" -__gitcomp_builtin_status_default=" --verbose --short --branch --show-stash --ahead-behind --porcelain --long --null --untracked-files --ignored --ignore-submodules --column --no-renames --find-renames --renames -- --no-verbose --no-short --no-branch --no-show-stash --no-ahead-behind --no-porcelain --no-long --no-null --no-untracked-files --no-ignored --no-ignore-submodules --no-column" -__gitcomp_builtin_stripspace_default=" --strip-comments --comment-lines" -__gitcomp_builtin_switch_default=" --create= --force-create= --guess --discard-changes --quiet --recurse-submodules --progress --merge --conflict= --detach --track --orphan= --ignore-other-worktrees --no-create -- --no-force-create --no-guess --no-discard-changes --no-quiet --no-recurse-submodules --no-progress --no-merge --no-conflict --no-detach --no-track --no-orphan --no-ignore-other-worktrees" -__gitcomp_builtin_symbolic_ref_default=" --quiet --delete --short --no-quiet -- --no-delete --no-short" -__gitcomp_builtin_tag_default=" --list --delete --verify --annotate --message= --file= --edit --sign --cleanup= --local-user= --force --create-reflog --column --contains --no-contains --merged --no-merged --sort= --points-at --format= --color --ignore-case -- --no-annotate --no-file --no-edit --no-sign --no-cleanup --no-local-user --no-force --no-create-reflog --no-column --no-sort --no-points-at --no-format --no-color --no-ignore-case" -__gitcomp_builtin_update_index_default=" --ignore-submodules --add --replace --remove --unmerged --refresh --really-refresh --cacheinfo --chmod= --assume-unchanged --no-assume-unchanged --skip-worktree --no-skip-worktree --ignore-skip-worktree-entries --info-only --force-remove --stdin --index-info --unresolve --again --ignore-missing --verbose --clear-resolve-undo --index-version= --split-index --untracked-cache --test-untracked-cache --force-untracked-cache --force-write-index --fsmonitor --fsmonitor-valid --no-fsmonitor-valid -- --no-ignore-submodules --no-add --no-replace --no-remove --no-unmerged --no-ignore-skip-worktree-entries --no-info-only --no-force-remove --no-ignore-missing --no-verbose --no-index-version --no-split-index --no-untracked-cache --no-test-untracked-cache --no-force-untracked-cache --no-force-write-index --no-fsmonitor" -__gitcomp_builtin_update_ref_default=" --no-deref --stdin --create-reflog --deref -- --no-stdin --no-create-reflog" -__gitcomp_builtin_update_server_info_default=" --force --no-force" -__gitcomp_builtin_upload_pack_default=" --stateless-rpc --strict --timeout= --no-stateless-rpc -- --no-strict --no-timeout" -__gitcomp_builtin_verify_commit_default=" --verbose --raw --no-verbose -- --no-raw" -__gitcomp_builtin_verify_pack_default=" --verbose --stat-only --object-format= --no-verbose -- --no-stat-only --no-object-format" -__gitcomp_builtin_verify_tag_default=" --verbose --raw --format= --no-verbose -- --no-raw --no-format" -__gitcomp_builtin_version_default=" --build-options --no-build-options" -__gitcomp_builtin_whatchanged_default=" --quiet --source --use-mailmap --decorate-refs= --decorate-refs-exclude= --decorate --no-quiet -- --no-source --no-use-mailmap --no-mailmap --no-decorate-refs --no-decorate-refs-exclude --no-decorate" -__gitcomp_builtin_write_tree_default=" --missing-ok --prefix= --no-missing-ok -- --no-prefix" -__gitcomp_builtin_send_email_default="--sender= --from= --smtp-auth= --8bit-encoding= --no-format-patch --no-bcc --no-suppress-from --no-annotate --relogin-delay= --no-cc --no-signed-off-cc --no-signed-off-by-cc --no-chain-reply-to --smtp-debug= --smtp-domain= --chain-reply-to --dry-run --compose --bcc= --smtp-user= --thread --cc-cover --identity= --to= --reply-to= --no-cc-cover --suppress-cc= --to-cmd= --smtp-server= --smtp-ssl-cert-path= --no-thread --smtp-server-option= --quiet --batch-size= --envelope-sender= --smtp-ssl --no-to --validate --format-patch --suppress-from --cc= --compose-encoding= --to-cover --in-reply-to= --annotate --smtp-encryption= --cc-cmd= --smtp-server-port= --smtp-pass= --signed-off-cc --signed-off-by-cc --no-xmailer --subject= --no-to-cover --confirm= --transfer-encoding= --no-smtp-auth --sendmail-cmd= --no-validate --no-identity --dump-aliases --xmailer --force --numbered --no-numbered --signoff --stdout --cover-letter --numbered-files --suffix= --start-number= --reroll-count= --filename-max-length= --rfc --cover-from-description= --subject-prefix= --output-directory= --keep-subject --no-binary --zero-commit --ignore-if-in-upstream --no-stat --add-header= --from --attach --inline --signature= --base= --signature-file= --progress --interdiff= --range-diff= --creation-factor= --binary -- --no-signoff --no-stdout --no-cover-letter --no-numbered-files --no-suffix --no-start-number --no-reroll-count --no-filename-max-length --no-cover-from-description --no-zero-commit --no-ignore-if-in-upstream --no-add-header --no-from --no-in-reply-to --no-attach --no-signature --no-base --no-signature-file --no-quiet --no-progress --no-interdiff --no-range-diff --no-creation-factor" - -__gitcomp_builtin_get_default () -{ - eval "test -n \"\$${1}_default\" && echo \"\$${1}_default\"" -} - # This function is equivalent to # # __gitcomp_opts "$(git xxx --git-completion-helper) ..." @@ -457,11 +353,9 @@ __gitcomp_builtin () else completion_helper="--git-completion-helper" fi - completion="$(__git ${cmd/_/ } $completion_helper || - __gitcomp_builtin_get_default $var)" || return # leading and trailing spaces are significant to make # option removal work correctly. - options=" $incl $completion " + options=" $incl $(__git ${cmd/_/ } $completion_helper) " || return for i in $excl; do options="${options/ $i / }" @@ -604,6 +498,7 @@ __git_heads () local pfx="${1-}" cur_="${2-}" sfx="${3-}" __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \ + ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \ "refs/heads/$cur_*" "refs/heads/$cur_*/**" } @@ -617,6 +512,7 @@ __git_remote_heads () local pfx="${1-}" cur_="${2-}" sfx="${3-}" __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \ + ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \ "refs/remotes/$cur_*" "refs/remotes/$cur_*/**" } @@ -627,6 +523,7 @@ __git_tags () local pfx="${1-}" cur_="${2-}" sfx="${3-}" __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \ + ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \ "refs/tags/$cur_*" "refs/tags/$cur_*/**" } @@ -646,6 +543,7 @@ __git_dwim_remote_heads () # but only output if the branch name is unique __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \ --sort="refname:strip=3" \ + ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \ "refs/remotes/*/$cur_*" "refs/remotes/*/$cur_*/**" | \ uniq -u } @@ -670,6 +568,7 @@ __git_refs () local format refs local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}" local match="${4-}" + local umatch="${4-}" local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers __git_find_repo_path @@ -693,12 +592,19 @@ __git_refs () fi fi + if test "${GIT_COMPLETION_IGNORE_CASE:+1}" = "1" + then + # uppercase with tr instead of ${match,^^} for bash 3.2 compatibility + umatch=$(echo "$match" | tr a-z A-Z 2>/dev/null || echo "$match") + fi + if [ "$list_refs_from" = path ]; then if [[ "$cur_" == ^* ]]; then pfx="$pfx^" fer_pfx="$fer_pfx^" cur_=${cur_#^} match=${match#^} + umatch=${umatch#^} fi case "$cur_" in refs|refs/*) @@ -709,7 +615,7 @@ __git_refs () *) for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD CHERRY_PICK_HEAD; do case "$i" in - $match*) + $match*|$umatch*) if [ -e "$dir/$i" ]; then echo "$pfx$i$sfx" fi @@ -723,6 +629,7 @@ __git_refs () ;; esac __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \ + ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \ "${refs[@]}" if [ -n "$track" ]; then __git_dwim_remote_heads "$pfx" "$match" "$sfx" @@ -742,15 +649,16 @@ __git_refs () *) if [ "$list_refs_from" = remote ]; then case "HEAD" in - $match*) echo "${pfx}HEAD$sfx" ;; + $match*|$umatch*) echo "${pfx}HEAD$sfx" ;; esac __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \ + ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \ "refs/remotes/$remote/$match*" \ "refs/remotes/$remote/$match*/**" else local query_symref case "HEAD" in - $match*) query_symref="HEAD" ;; + $match*|$umatch*) query_symref="HEAD" ;; esac __git ls-remote "$remote" $query_symref \ "refs/tags/$match*" "refs/heads/$match*" \ @@ -888,7 +796,6 @@ __git_list_merge_strategies () }' } -__git_merge_strategies_default='octopus ours recursive resolve subtree' __git_merge_strategies= # 'git merge -s help' (and thus detection of the merge strategy # list) fails, unfortunately, if run outside of any git working @@ -898,8 +805,7 @@ __git_merge_strategies= __git_compute_merge_strategies () { test -n "$__git_merge_strategies" || - { __git_merge_strategies=$(__git_list_merge_strategies); - __git_merge_strategies="${__git_merge_strategies:-__git_merge_strategies_default}"; } + __git_merge_strategies=$(__git_list_merge_strategies) } __git_merge_strategy_options="ours theirs subtree subtree= patience @@ -2281,7 +2187,7 @@ _git_reflog () fi } -__git_send_email_options="--no-cc-cover --cc= --no-bcc --force --relogin-delay= --to= --suppress-cc= --no-annotate --no-chain-reply-to --sendmail-cmd= --no-identity --transfer-encoding= --validate --no-smtp-auth --confirm= --no-format-patch --reply-to= --smtp-pass= --smtp-server= --annotate --envelope-sender= --no-validate --dry-run --no-thread --smtp-debug= --no-to --thread --no-xmailer --identity= --no-signed-off-cc --no-signed-off-by-cc --smtp-domain= --to-cover --8bit-encoding= --bcc= --smtp-ssl-cert-path= --smtp-user= --cc-cmd= --to-cmd= --no-cc --smtp-server-option= --in-reply-to= --subject= --batch-size= --smtp-auth= --compose --smtp-server-port= --xmailer --no-to-cover --chain-reply-to --smtp-encryption= --dump-aliases --quiet --smtp-ssl --signed-off-cc --signed-off-by-cc --suppress-from --compose-encoding= --no-suppress-from --sender= --from= --format-patch --cc-cover --numbered --no-numbered --signoff --stdout --cover-letter --numbered-files --suffix= --start-number= --reroll-count= --filename-max-length= --rfc --cover-from-description= --subject-prefix= --output-directory= --keep-subject --no-binary --zero-commit --ignore-if-in-upstream --no-stat --add-header= --from --attach --inline --signature= --base= --signature-file= --progress --interdiff= --range-diff= --creation-factor= --binary -- --no-signoff --no-stdout --no-cover-letter --no-numbered-files --no-suffix --no-start-number --no-reroll-count --no-filename-max-length --no-cover-from-description --no-zero-commit --no-ignore-if-in-upstream --no-add-header --no-from --no-in-reply-to --no-attach --no-signature --no-base --no-signature-file --no-quiet --no-progress --no-interdiff --no-range-diff --no-creation-factor" +__gitcomp_builtin_send_email_default="--8bit-encoding= --add-header= --annotate --attach --base= --batch-size= --bcc= --binary --cc-cmd= --cc-cover --cc= --chain-reply-to --compose --compose-encoding= --confirm= --cover-from-description= --cover-letter --creation-factor= --dry-run --dump-aliases --envelope-sender= --filename-max-length= --force --force-in-body-from --format-patch --from --from= --identity= --ignore-if-in-upstream --in-reply-to= --inline --interdiff= --keep-subject --numbered --numbered-files --output-directory= --progress --quiet --range-diff= --relogin-delay= --reply-to= --reroll-count= --rfc --sender= --sendmail-cmd= --signature-file= --signature= --signed-off-by-cc --signed-off-cc --signoff --smtp-auth= --smtp-debug= --smtp-domain= --smtp-encryption= --smtp-pass= --smtp-server-option= --smtp-server-port= --smtp-server= --smtp-ssl --smtp-ssl-cert-path= --smtp-user= --start-number= --stdout --subject-prefix= --subject= --suffix= --suppress-cc= --suppress-from --thread --to-cmd= --to-cover --to= --transfer-encoding= --v= --validate --xmailer --zero-commit -- --no-add-header --no-annotate --no-attach --no-base --no-bcc --no-binary --no-cc --no-cc-cover --no-chain-reply-to --no-cover-from-description --no-cover-letter --no-creation-factor --no-filename-max-length --no-force-in-body-from --no-format-patch --no-from --no-identity --no-ignore-if-in-upstream --no-in-reply-to --no-interdiff --no-numbered --no-numbered-files --no-progress --no-quiet --no-range-diff --no-reroll-count --no-signature --no-signature-file --no-signed-off-by-cc --no-signed-off-cc --no-signoff --no-smtp-auth --no-start-number --no-stat --no-stdout --no-suffix --no-suppress-from --no-thread --no-to --no-to-cover --no-validate --no-xmailer --no-zero-commit" __git_send_email_confirm_options="always never auto cc compose" __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all" @@ -2321,7 +2227,11 @@ _git_send_email () return ;; --*) - __gitcomp_builtin send-email "$__git_send_email_options $__git_format_patch_extra_options" + # Older versions of git send-email don't have all the options + git send-email --git-completion-helper | grep -q annotate || + __gitcomp_builtin_send_email=$__gitcomp_builtin_send_email_default + + __gitcomp_builtin send-email "$__git_format_patch_extra_options" return ;; esac @@ -2456,7 +2366,25 @@ __git_config_vars= __git_compute_config_vars () { test -n "$__git_config_vars" || - __git_config_vars="$(git help --config-for-completion | sort -u)" + __git_config_vars="$(git help --config-for-completion)" +} + +__git_compute_config_sections_old () +{ + __git_compute_config_vars + echo "$__git_config_vars" | + awk -F . '{ dict[$1] = 1 } END { for (e in dict) print e }' +} + +__git_config_sections= +__git_compute_config_sections () +{ + test -n "$__git_config_sections" || + __git_config_sections="$( + git help --config-sections-for-completion > /dev/null 2>&1 && + git help --config-sections-for-completion || + __git_compute_config_sections_old + )" } # Completes possible values of various configuration variables. @@ -2670,16 +2598,8 @@ __git_complete_config_variable_name () __gitcomp "$__git_config_vars" "" "$cur_" "$sfx" ;; *) - __git_compute_config_vars - __gitcomp_nl "$(echo "$__git_config_vars" | - awk -F . '{ - sections[$1] = 1 - } - END { - for (s in sections) - print s "." - } - ')" "" "$cur_" "" + __git_compute_config_sections + __gitcomp_nl "$__git_config_sections" "" "$cur_" "." ;; esac } @@ -3628,43 +3548,6 @@ __git_complete () ___git_complete $1 $func } -if ! git --list-cmds=main >/dev/null 2>&1; then - - declare -A __git_cmds - __git_cmds[list-complete]="apply blame cherry config difftool fsck help instaweb mergetool prune reflog remote repack replace request-pull send-email show-branch stage whatchanged" - __git_cmds[list-guide]="attributes cli core-tutorial credentials cvs-migration diffcore everyday faq glossary hooks ignore mailmap modules namespaces remote-helpers repository-layout revisions submodules tutorial tutorial-2 workflows" - __git_cmds[list-mainporcelain]="add am archive bisect branch bundle checkout cherry-pick citool clean clone commit describe diff fetch format-patch gc grep gui init log maintenance merge mv notes pull push range-diff rebase reset restore revert rm shortlog show sparse-checkout stash status submodule switch tag worktree gitk" - __git_cmds[main]="add add--interactive am annotate apply archimport archive bisect bisect--helper blame branch bugreport bundle cat-file check-attr check-ignore check-mailmap check-ref-format checkout checkout--worker checkout-index cherry cherry-pick citool clean clone column commit commit-graph commit-tree config count-objects credential credential-cache credential-cache--daemon credential-store cvsexportcommit cvsimport cvsserver daemon describe diff diff-files diff-index diff-tree difftool difftool--helper env--helper fast-export fast-import fetch fetch-pack filter-branch fmt-merge-msg for-each-ref for-each-repo format-patch fsck fsck-objects fsmonitor--daemon gc get-tar-commit-id grep gui gui--askpass hash-object help hook http-backend http-fetch http-push imap-send index-pack init init-db instaweb interpret-trailers legacy-rebase legacy-stash log ls-files ls-remote ls-tree mailinfo mailsplit maintenance merge merge-base merge-file merge-index merge-octopus merge-one-file merge-ours merge-recursive merge-recursive-ours merge-recursive-theirs merge-resolve merge-subtree merge-tree mergetool mktag mktree multi-pack-index mv name-rev notes p4 pack-objects pack-redundant pack-refs patch-id pickaxe prune prune-packed pull push quiltimport range-diff read-tree rebase rebase--helper receive-pack reflog relink remote remote-ext remote-fd remote-ftp remote-ftps remote-http remote-https remote-testsvn repack replace request-pull rerere reset restore rev-list rev-parse revert rm send-email send-pack serve sh-i18n--envsubst shell shortlog show show-branch show-index show-ref sparse-checkout stage stash status stripspace submodule submodule--helper svn switch symbolic-ref tag unpack-file unpack-objects update-index update-ref update-server-info upload-archive upload-archive--writer upload-pack var verify-commit verify-pack verify-tag version web--browse whatchanged worktree write-tree" - __git_cmds[others]="" - __git_cmds[parseopt]="add am apply archive bisect--helper blame branch bugreport cat-file check-attr check-ignore check-mailmap checkout checkout--worker checkout-index cherry cherry-pick clean clone column commit commit-graph config count-objects credential-cache credential-cache--daemon credential-store describe difftool env--helper fast-export fetch fmt-merge-msg for-each-ref for-each-repo format-patch fsck fsck-objects fsmonitor--daemon gc grep hash-object help hook init init-db interpret-trailers log ls-files ls-remote ls-tree merge merge-base merge-file mktree multi-pack-index mv name-rev notes pack-objects pack-refs pickaxe prune prune-packed pull push range-diff read-tree rebase receive-pack reflog remote repack replace rerere reset restore revert rm send-pack shortlog show show-branch show-index show-ref sparse-checkout stage stash status stripspace switch symbolic-ref tag update-index update-ref update-server-info upload-pack verify-commit verify-pack verify-tag version whatchanged write-tree " - - # Override __git - __git () - { - case "$1" in - --list-cmds=*) - while read -r -d ',' x; do - case "$x" in - nohelpers) - ;; - alias) - ;; - config) - ;; - *) - echo ${__git_cmds[$x]} - ;; - esac - done <<< "${1##--list-cmds=}," - return - ;; - esac - git ${__git_C_args:+"${__git_C_args[@]}"} \ - ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null - } - -fi - ___git_complete git __git_main ___git_complete gitk __gitk_main diff --git a/plugins/gitfast/git-prompt.sh b/plugins/gitfast/git-prompt.sh index 1435548e0..76ee4ab1e 100644 --- a/plugins/gitfast/git-prompt.sh +++ b/plugins/gitfast/git-prompt.sh @@ -84,6 +84,10 @@ # single '?' character by setting GIT_PS1_COMPRESSSPARSESTATE, or omitted # by setting GIT_PS1_OMITSPARSESTATE. # +# If you would like to see a notification on the prompt when there are +# unresolved conflicts, set GIT_PS1_SHOWCONFLICTSTATE to "yes". The +# prompt will include "|CONFLICT". +# # If you would like to see more information about the identity of # commits checked out as a detached HEAD, set GIT_PS1_DESCRIBE_STYLE # to one of these values: @@ -96,9 +100,7 @@ # # If you would like a colored hint about the current dirty state, set # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on -# the colored output of "git status -sb" and are available only when -# using __git_ps1 for PROMPT_COMMAND or precmd in Bash, -# but always available in Zsh. +# the colored output of "git status -sb". # # If you would like __git_ps1 to do nothing in the case when the current # directory is set up to be ignored by git, then set @@ -255,12 +257,12 @@ __git_ps1_colorize_gitstring () local c_lblue='%F{blue}' local c_clear='%f' else - # Using \[ and \] around colors is necessary to prevent + # Using \001 and \002 around colors is necessary to prevent # issues with command line editing/browsing/completion! - local c_red='\[\e[31m\]' - local c_green='\[\e[32m\]' - local c_lblue='\[\e[1;34m\]' - local c_clear='\[\e[0m\]' + local c_red=$'\001\e[31m\002' + local c_green=$'\001\e[32m\002' + local c_lblue=$'\001\e[1;34m\002' + local c_clear=$'\001\e[0m\002' fi local bad_color=$c_red local ok_color=$c_green @@ -508,6 +510,12 @@ __git_ps1 () r="$r $step/$total" fi + local conflict="" # state indicator for unresolved conflicts + if [[ "${GIT_PS1_SHOWCONFLICTSTATE}" == "yes" ]] && + [[ $(git ls-files --unmerged 2>/dev/null) ]]; then + conflict="|CONFLICT" + fi + local w="" local i="" local s="" @@ -564,15 +572,12 @@ __git_ps1 () b="\${__git_ps1_branch_name}" fi - # NO color option unless in PROMPT_COMMAND mode or it's Zsh if [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then - if [ $pcmode = yes ] || [ -n "${ZSH_VERSION-}" ]; then - __git_ps1_colorize_gitstring - fi + __git_ps1_colorize_gitstring fi local f="$h$w$i$s$u$p" - local gitstring="$c$b${f:+$z$f}${sparse}$r${upstream}" + local gitstring="$c$b${f:+$z$f}${sparse}$r${upstream}${conflict}" if [ $pcmode = yes ]; then if [ "${__git_printf_supports_v-}" != yes ]; then diff --git a/plugins/gitfast/gitfast.plugin.zsh b/plugins/gitfast/gitfast.plugin.zsh index a6db0c6bd..c456eff7f 100644 --- a/plugins/gitfast/gitfast.plugin.zsh +++ b/plugins/gitfast/gitfast.plugin.zsh @@ -1,6 +1,6 @@ # 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="${ZERO:-${${0:#$ZSH_ARGZERO}:-${(%):-%N}}}" 0="${${(M)0:#/*}:-$PWD/$0}" source "${0:A:h}/git-prompt.sh" diff --git a/plugins/gitfast/update b/plugins/gitfast/update deleted file mode 100755 index feb13ff7e..000000000 --- a/plugins/gitfast/update +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -url="https://raw.githubusercontent.com/felipec/git-completion" -version="1.3.7" - -curl -s -o _git "${url}/v${version}/git-completion.zsh" && -curl -s -o git-completion.bash "${url}/v${version}/git-completion.bash" && -curl -s -o git-prompt.sh "${url}/v${version}/git-prompt.sh" diff --git a/plugins/gitignore/README.md b/plugins/gitignore/README.md index 753dd31fd..23c7887cf 100644 --- a/plugins/gitignore/README.md +++ b/plugins/gitignore/README.md @@ -1,6 +1,6 @@ # gitignore -This plugin enables you the use of [gitignore.io](https://www.gitignore.io/) from the command line. You need an active internet connection. +This plugin enables you the use of [gitignore.io](https://www.toptal.com/developers/gitignore) from the command line. You need an active internet connection. To use it, add `gitignore` to the plugins array in your zshrc file: diff --git a/plugins/gitignore/gitignore.plugin.zsh b/plugins/gitignore/gitignore.plugin.zsh index a687f5cce..3271d61a9 100644 --- a/plugins/gitignore/gitignore.plugin.zsh +++ b/plugins/gitignore/gitignore.plugin.zsh @@ -1,7 +1,7 @@ -function gi() { curl -fLw '\n' https://www.gitignore.io/api/"${(j:,:)@}" } +function gi() { curl -fLw '\n' https://www.toptal.com/developers/gitignore/api/"${(j:,:)@}" } _gitignoreio_get_command_list() { - curl -sfL https://www.gitignore.io/api/list | tr "," "\n" + curl -sfL https://www.toptal.com/developers/gitignore/api/list | tr "," "\n" } _gitignoreio () { diff --git a/plugins/gnu-utils/gnu-utils.plugin.zsh b/plugins/gnu-utils/gnu-utils.plugin.zsh index 6023bf2b4..adc2bd3bb 100644 --- a/plugins/gnu-utils/gnu-utils.plugin.zsh +++ b/plugins/gnu-utils/gnu-utils.plugin.zsh @@ -14,7 +14,7 @@ __gnu_utils() { local -a gcmds local gcmd - # coreutils + # coreutils gcmds=('g[' 'gbase64' 'gbasename' 'gcat' 'gchcon' 'gchgrp' 'gchmod' 'gchown' 'gchroot' 'gcksum' 'gcomm' 'gcp' 'gcsplit' 'gcut' 'gdate' 'gdd' 'gdf' 'gdir' 'gdircolors' 'gdirname' 'gdu' 'gecho' 'genv' 'gexpand' @@ -41,7 +41,7 @@ __gnu_utils() { for gcmd in "${gcmds[@]}"; do # Do nothing if the command isn't found (( ${+commands[$gcmd]} )) || continue - + # This method allows for builtin commands to be primary but it's # lost if hash -r or rehash is executed, or if $PATH is updated. # Thus, a preexec hook is needed, which will only run if whoami diff --git a/plugins/gradle/LICENSE b/plugins/gradle/LICENSE new file mode 100644 index 000000000..06edf4af2 --- /dev/null +++ b/plugins/gradle/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2017 Eric Wendelin + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/plugins/gradle/_gradle b/plugins/gradle/_gradle index f8df928b4..ca13fd0b0 100644 --- a/plugins/gradle/_gradle +++ b/plugins/gradle/_gradle @@ -1,28 +1,4 @@ #compdef gradle gradlew gw -# THE LINE ABOVE MUST BE THE FIRST LINE OF THIS FILE IN ORDER FOR COMPLETION TO WORK - -# -# Taken from https://github.com/gradle/gradle-completion -# Copyright (c) 2017 Eric Wendelin -# -# Permission is hereby granted, free of charge, to any person obtaining a copy of -# this software and associated documentation files (the "Software"), to deal in -# the Software without restriction, including without limitation the rights to -# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -# of the Software, and to permit persons to whom the Software is furnished to do -# so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -# Terms __gradle-set-project-root-dir() { local dir=`pwd` @@ -38,7 +14,7 @@ __gradle-set-project-root-dir() { } __gradle-init-cache-dir() { - cache_dir="$HOME/.gradle/completion" + cache_dir="${GRADLE_USER_HOME:-$HOME/.gradle}/completion" mkdir -p $cache_dir } @@ -98,7 +74,7 @@ __gradle-generate-script-cache() { zle -R "Generating Gradle build script cache" # Cache all Gradle scripts local -a gradle_build_scripts - gradle_build_scripts=( $(find $project_root_dir -type f -name "*.gradle" -o -name "*.gradle.kts" 2>/dev/null | egrep -v "$script_exclude_pattern") ) + gradle_build_scripts=( $(find $project_root_dir -type f -name "*.gradle" -o -name "*.gradle.kts" 2>/dev/null | grep -E -v "$script_exclude_pattern") ) printf "%s\n" "${gradle_build_scripts[@]}" >| $cache_dir/$cache_name fi } @@ -125,7 +101,7 @@ __gradle-generate-tasks-cache() { local gradle_all_tasks="" root_tasks="" subproject_tasks="" output_line local -a match for output_line in ${(f)"$(printf "%s\n" "${gradle_tasks_output[@]}")"}; do - if [[ $output_line =~ ^([[:lower:]][[:alnum:][:punct:]]*)([[:space:]]-[[:space:]]([[:print:]]*))? ]]; then + if [[ $output_line =~ ^([[:alpha:]][[:alnum:][:punct:]]*)([[:space:]]-[[:space:]]([[:print:]]*))? ]]; then local task_name="${match[1]}" local task_description="${match[3]}" # Completion for subproject tasks with ':' prefix diff --git a/plugins/gradle/gradle.plugin.zsh b/plugins/gradle/gradle.plugin.zsh index 5bca364d1..dacc46478 100644 --- a/plugins/gradle/gradle.plugin.zsh +++ b/plugins/gradle/gradle.plugin.zsh @@ -6,7 +6,7 @@ function gradle-or-gradlew() { # taken from https://github.com/gradle/gradle-completion local dir="$PWD" project_root="$PWD" while [[ "$dir" != / ]]; do - if [[ -f "$dir/settings.gradle" || -f "$dir/settings.gradle.kts" || -f "$dir/gradlew" ]]; then + if [[ -x "$dir/gradlew" ]]; then project_root="$dir" break fi diff --git a/plugins/grails/grails.plugin.zsh b/plugins/grails/grails.plugin.zsh index ddc257428..e5dceb530 100644 --- a/plugins/grails/grails.plugin.zsh +++ b/plugins/grails/grails.plugin.zsh @@ -7,7 +7,7 @@ _enumerateGrailsScripts() { then directories+=(plugins/*/scripts) fi - + # Enumerate all of the Groovy files files=() for dir in $directories; @@ -17,13 +17,13 @@ _enumerateGrailsScripts() { files+=($dir/[^_]*.groovy) fi done - + # Don't try to basename () if [ ${#files} -eq 0 ]; then return fi - + scripts=() for file in $files do @@ -42,19 +42,19 @@ _enumerateGrailsScripts() { done echo $scripts } - + _grails() { if (( CURRENT == 2 )); then scripts=( $(_enumerateGrailsScripts) ) - + if [ ${#scripts} -ne 0 ]; then _multi_parts / scripts return fi fi - + _files } - + compdef _grails grails diff --git a/plugins/grc/grc.plugin.zsh b/plugins/grc/grc.plugin.zsh index b709b9e02..55ffc1a1e 100644 --- a/plugins/grc/grc.plugin.zsh +++ b/plugins/grc/grc.plugin.zsh @@ -2,8 +2,10 @@ # common grc.zsh paths files=( - /etc/grc.zsh # default - /usr/local/etc/grc.zsh # homebrew + /etc/grc.zsh # default + /usr/local/etc/grc.zsh # homebrew darwin-x64 + /opt/homebrew/etc/grc.zsh # homebrew darwin-arm64 + /usr/share/grc/grc.zsh # Gentoo Linux (app-misc/grc) ) # verify the file is readable and source it diff --git a/plugins/helm/README.md b/plugins/helm/README.md index 8be024bfb..dcbb30b6c 100644 --- a/plugins/helm/README.md +++ b/plugins/helm/README.md @@ -10,9 +10,10 @@ plugins=(... helm) ## Aliases -| Alias | Full command | -| ----- | ------------ | -| h | helm | -| hin | helm install | -| hse | helm search | -| hup | helm upgrade | +| Alias | Full command | +| ----- | -------------- | +| h | helm | +| hin | helm install | +| hun | helm uninstall | +| hse | helm search | +| hup | helm upgrade | diff --git a/plugins/helm/helm.plugin.zsh b/plugins/helm/helm.plugin.zsh index 7fc05be98..e754a6541 100644 --- a/plugins/helm/helm.plugin.zsh +++ b/plugins/helm/helm.plugin.zsh @@ -14,5 +14,6 @@ fi alias h='helm' alias hin='helm install' +alias hun='helm uninstall' alias hse='helm search' alias hup='helm upgrade' diff --git a/plugins/history-substring-search/README.md b/plugins/history-substring-search/README.md index 6d8b56425..4be744c4c 100644 --- a/plugins/history-substring-search/README.md +++ b/plugins/history-substring-search/README.md @@ -23,7 +23,15 @@ Install Using the [Homebrew]( https://brew.sh ) package manager: brew install zsh-history-substring-search - echo 'source /usr/local/share/zsh-history-substring-search/zsh-history-substring-search.zsh' >> ~/.zshrc + echo 'source $(brew --prefix)/share/zsh-history-substring-search/zsh-history-substring-search.zsh' >> ~/.zshrc + +Using [Fig](https://fig.io): + +Fig adds apps, shortcuts, and autocomplete to your existing terminal. + +Install `zsh-history-substring-search` in just one click. + + Using [Oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh): @@ -33,24 +41,63 @@ Using [Oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh): 2. Activate the plugin in `~/.zshrc`: - plugins=( [plugins...] history-substring-search) + plugins=( [plugins...] zsh-history-substring-search) -3. Source `~/.zshrc` to take changes into account: +3. Run `exec zsh` to take changes into account: - source ~/.zshrc + exec zsh + +Using [zplug](https://github.com/zplug/zplug): + +1. Add this repo to `~/.zshrc`: + + zplug "zsh-users/zsh-history-substring-search", as: plugin + +Using [antigen](https://github.com/zsh-users/antigen): + +1. Add the `antigen bundle` command just before `antigen apply`, like this: + +``` +antigen bundle zsh-users/zsh-history-substring-search +antigen apply +``` + +2. Then, **after** `antigen apply`, add the key binding configurations, like this: + +``` +# zsh-history-substring-search configuration +bindkey '^[[A' history-substring-search-up # or '\eOA' +bindkey '^[[B' history-substring-search-down # or '\eOB' +HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE=1 +``` + +Using [Zinit](https://github.com/zdharma-continuum/zinit): + +1. Use the `Oh-my-zsh` Zinit snippet in `~/.zshrc`: + + zinit snippet OMZ::plugins/git/git.plugin.zsh` + +2. Load the plugin in `~/.zshrc`: + + zinit load 'zsh-users/zsh-history-substring-search + zinit ice wait atload'_history_substring_search_config' + +3. Run `exec zsh` to take changes into account: + + exec zsh Usage ------------------------------------------------------------------------------ 1. Load this script into your interactive ZSH session: - % source zsh-history-substring-search.zsh + source zsh-history-substring-search.zsh If you want to use [zsh-syntax-highlighting][6] along with this script, then make sure that you load it *before* you load this script: - % source zsh-syntax-highlighting.zsh - % source zsh-history-substring-search.zsh + source zsh-syntax-highlighting.zsh + source zsh-history-substring-search.zsh 2. Bind keyboard shortcuts to this script's functions. @@ -73,6 +120,10 @@ Usage bindkey "$terminfo[kcuu1]" history-substring-search-up bindkey "$terminfo[kcud1]" history-substring-search-down + Users have also observed that `[OA` and `[OB` are correct values, + _even if_ these were not the observed values. If you are having trouble + with the observed values, give these a try. + You might also want to bind the Control-P/N keys for use in EMACS mode: bindkey -M emacs '^P' history-substring-search-up @@ -115,7 +166,7 @@ Configuration ------------------------------------------------------------------------------ This script defines the following global variables. You may override their -default values only after having loaded this script into your ZSH session. +default values. * `HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND` is a global variable that defines how the query should be highlighted inside a matching command. Its default @@ -141,6 +192,12 @@ default values only after having loaded this script into your ZSH session. value, causes this script to perform a fuzzy search by words, matching in given order e.g. `ab c` will match `*ab*c*` +* `HISTORY_SUBSTRING_SEARCH_PREFIXED` is a global variable that defines how + the command history will be searched for your query. If set to a non-empty + value, your query will be matched against the start of each history entry. + For example, if this variable is empty, `ls` will match `ls -l` and `echo + ls`; if it is non-empty, `ls` will only match `ls -l`. + * `HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE` is a global variable that defines whether all search results returned are _unique_. If set to a non-empty value, then only unique search results are presented. This behaviour is off @@ -155,6 +212,9 @@ default values only after having loaded this script into your ZSH session. receive globally unique search results only once, then use this configuration variable, or use `setopt HIST_IGNORE_ALL_DUPS`. +* `HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_TIMEOUT` is a global variable that + defines a timeout in seconds for clearing the search highlight. + History ------------------------------------------------------------------------------ @@ -175,24 +235,17 @@ History * March 2016: Geza Lore (@gezalore) greatly refactored it in pull request #55. ------------------------------------------------------------------------------- -Oh My Zsh Distribution Notes ------------------------------------------------------------------------------- +--- -What you are looking at now is Oh My Zsh's repackaging of zsh-history-substring-search -as an OMZ module inside the Oh My Zsh distribution. +## Oh My Zsh Distribution Notes -The upstream repo, zsh-users/zsh-history-substring-search, can be found on GitHub at +What you are looking at now is Oh My Zsh's repackaging of zsh-history-substring-search as an OMZ module inside +the Oh My Zsh distribution. + +The upstream repo, zsh-users/zsh-history-substring-search, can be found on GitHub at https://github.com/zsh-users/zsh-history-substring-search. -This downstream copy was last updated from the following upstream commit: - - SHA: 0f80b8eb3368b46e5e573c1d91ae69eb095db3fb - Commit date: 2019-05-12 17:35:54 -0700 - -Everything above this section is a copy of the original upstream's README, so things -may differ slightly when you're using this inside OMZ. In particular, you do not -need to set up key bindings for the up and down arrows yourself in `~/.zshrc`; the OMZ -plugin does that for you. You may still want to set up additional emacs- or vi-specific -bindings as mentioned above. - +Everything above this section is a copy of the original upstream's README, so things may differ slightly when +you're using this inside OMZ. In particular, you do not need to set up key bindings for the up and down arrows +yourself in `~/.zshrc`; the OMZ plugin does that for you. You may still want to set up additional emacs- or +vi-specific bindings as mentioned above. diff --git a/plugins/history-substring-search/dependencies/OMZ-README.md b/plugins/history-substring-search/dependencies/OMZ-README.md new file mode 100644 index 000000000..c5967bb7d --- /dev/null +++ b/plugins/history-substring-search/dependencies/OMZ-README.md @@ -0,0 +1,15 @@ + +--- + +## Oh My Zsh Distribution Notes + +What you are looking at now is Oh My Zsh's repackaging of zsh-history-substring-search as an OMZ module inside +the Oh My Zsh distribution. + +The upstream repo, zsh-users/zsh-history-substring-search, can be found on GitHub at +https://github.com/zsh-users/zsh-history-substring-search. + +Everything above this section is a copy of the original upstream's README, so things may differ slightly when +you're using this inside OMZ. In particular, you do not need to set up key bindings for the up and down arrows +yourself in `~/.zshrc`; the OMZ plugin does that for you. You may still want to set up additional emacs- or +vi-specific bindings as mentioned above. diff --git a/plugins/history-substring-search/history-substring-search.zsh b/plugins/history-substring-search/history-substring-search.zsh index c326778d4..471cc9ad1 100644 --- a/plugins/history-substring-search/history-substring-search.zsh +++ b/plugins/history-substring-search/history-substring-search.zsh @@ -43,11 +43,12 @@ # declare global configuration variables #----------------------------------------------------------------------------- -typeset -g HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND='bg=magenta,fg=white,bold' -typeset -g HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND='bg=red,fg=white,bold' -typeset -g HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS='i' -typeset -g HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE='' -typeset -g HISTORY_SUBSTRING_SEARCH_FUZZY='' +: ${HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND='bg=magenta,fg=white,bold'} +: ${HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND='bg=red,fg=white,bold'} +: ${HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS='i'} +: ${HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE=''} +: ${HISTORY_SUBSTRING_SEARCH_FUZZY=''} +: ${HISTORY_SUBSTRING_SEARCH_PREFIXED=''} #----------------------------------------------------------------------------- # declare internal global variables @@ -64,6 +65,7 @@ typeset -g -i _history_substring_search_raw_match_index typeset -g -a _history_substring_search_matches typeset -g -i _history_substring_search_match_index typeset -g -A _history_substring_search_unique_filter +typeset -g -i _history_substring_search_zsh_5_9 #----------------------------------------------------------------------------- # the main ZLE widgets @@ -97,6 +99,11 @@ zle -N history-substring-search-down #----------------------------------------------------------------------------- zmodload -F zsh/parameter +autoload -Uz is-at-least + +if is-at-least 5.9 $ZSH_VERSION; then + _history_substring_search_zsh_5_9=1 +fi # # We have to "override" some keys and widgets if the @@ -117,80 +124,125 @@ if [[ $+functions[_zsh_highlight] -eq 0 ]]; then } # - # The following snippet was taken from the zsh-syntax-highlighting project: + # Check if $1 denotes the name of a callable function, i.e. it is fully + # defined or it is marked for autoloading and autoloading it at the first + # call to it will succeed. In particular, if $1 has been marked for + # autoloading but is not available in $fpath, then it will return 1 (false). # - # https://github.com/zsh-users/zsh-syntax-highlighting/blob/56b134f5d62ae3d4e66c7f52bd0cc2595f9b305b/zsh-syntax-highlighting.zsh#L126-161 + # This is based on the zsh-syntax-highlighting plugin. # - # Copyright (c) 2010-2011 zsh-syntax-highlighting contributors - # All rights reserved. + _history-substring-search-function-callable() { + if (( ${+functions[$1]} )) && ! [[ "$functions[$1]" == *"builtin autoload -X"* ]]; then + return 0 # already fully loaded + else + # "$1" is either an autoload stub, or not a function at all. + # We expect 'autoload +X' to return non-zero if it fails to fully load + # the function. + ( autoload -U +X -- "$1" 2>/dev/null ) + return $? + fi + } + # - # Redistribution and use in source and binary forms, with or without - # modification, are permitted provided that the following conditions are - # met: + # The zsh-syntax-highlighting plugin uses zle-line-pre-redraw hook instead + # of the legacy "bind all widgets" if 1) zsh has the memo= feature (added in + # version 5.9) and 2) add-zle-hook-widget is available. # - # * Redistributions of source code must retain the above copyright - # notice, this list of conditions and the following disclaimer. - # - # * Redistributions in binary form must reproduce the above copyright - # notice, this list of conditions and the following disclaimer in the - # documentation and/or other materials provided with the distribution. - # - # * Neither the name of the zsh-syntax-highlighting contributors nor the - # names of its contributors may be used to endorse or promote products - # derived from this software without specific prior written permission. - # - # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - # - #--------------8<-------------------8<-------------------8<----------------- - # Rebind all ZLE widgets to make them invoke _zsh_highlights. - _zsh_highlight_bind_widgets() - { - # Load ZSH module zsh/zleparameter, needed to override user defined widgets. - zmodload zsh/zleparameter 2>/dev/null || { - echo 'zsh-syntax-highlighting: failed loading zsh/zleparameter.' >&2 - return 1 + if [[ $_history_substring_search_zsh_5_9 -eq 1 ]] && _history-substring-search-function-callable add-zle-hook-widget; then + # + # The following code is based on the zsh-syntax-highlighting plugin. + # + autoload -U add-zle-hook-widget + + _history-substring-search-zle-line-finish() { + # + # Reset $WIDGET since the 'main' highlighter depends on it. + # + # Since $WIDGET is declared by zle as read-only in this function's scope, + # a nested function is required in order to shadow its built-in value; + # see "User-defined widgets" in zshall. + # + () { + local -h -r WIDGET=zle-line-finish + _zsh_highlight + } } - # Override ZLE widgets to make them invoke _zsh_highlight. - local cur_widget - for cur_widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|run-help|which-command|beep|yank*)}; do - case $widgets[$cur_widget] in + _history-substring-search-zle-line-pre-redraw() { + # + # If the zsh-syntax-highlighting plugin has been loaded (after our plugin + # plugin, otherwise this hook wouldn't be called), remove our hooks. + # + if [[ $+ZSH_HIGHLIGHT_VERSION -eq 1 ]]; then + autoload -U add-zle-hook-widget + add-zle-hook-widget -d zle-line-pre-redraw _history-substring-search-zle-line-pre-redraw + add-zle-hook-widget -d zle-line-finish _history-substring-search-zle-line-finish + return 0 + fi + # + # Set $? to 0 for _zsh_highlight. Without this, subsequent + # zle-line-pre-redraw hooks won't run, since add-zle-hook-widget happens to + # call us with $? == 1 in the common case. + # + true && _zsh_highlight "$@" + } - # Already rebound event: do nothing. - user:$cur_widget|user:_zsh_highlight_widget_*);; + if [[ -o zle ]]; then + add-zle-hook-widget zle-line-pre-redraw _history-substring-search-zle-line-pre-redraw + add-zle-hook-widget zle-line-finish _history-substring-search-zle-line-finish + fi + else + # + # The following snippet was taken from the zsh-syntax-highlighting project: + # https://github.com/zsh-users/zsh-syntax-highlighting/blob/56b134f5d62ae3d4e66c7f52bd0cc2595f9b305b/zsh-syntax-highlighting.zsh#L126-161 + # + # SPDX-SnippetBegin + # SPDX-License-Identifier: BSD-3-Clause + # SPDX-SnippetCopyrightText: 2010-2011 zsh-syntax-highlighting contributors + #--------------8<-------------------8<-------------------8<----------------- + # Rebind all ZLE widgets to make them invoke _zsh_highlights. + _zsh_highlight_bind_widgets() + { + # Load ZSH module zsh/zleparameter, needed to override user defined widgets. + zmodload zsh/zleparameter 2>/dev/null || { + echo 'zsh-syntax-highlighting: failed loading zsh/zleparameter.' >&2 + return 1 + } - # User defined widget: override and rebind old one with prefix "orig-". - user:*) eval "zle -N orig-$cur_widget ${widgets[$cur_widget]#*:}; \ - _zsh_highlight_widget_$cur_widget() { builtin zle orig-$cur_widget -- \"\$@\" && _zsh_highlight }; \ - zle -N $cur_widget _zsh_highlight_widget_$cur_widget";; + # Override ZLE widgets to make them invoke _zsh_highlight. + local cur_widget + for cur_widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|run-help|which-command|beep|yank*)}; do + case $widgets[$cur_widget] in - # Completion widget: override and rebind old one with prefix "orig-". - completion:*) eval "zle -C orig-$cur_widget ${${widgets[$cur_widget]#*:}/:/ }; \ - _zsh_highlight_widget_$cur_widget() { builtin zle orig-$cur_widget -- \"\$@\" && _zsh_highlight }; \ - zle -N $cur_widget _zsh_highlight_widget_$cur_widget";; + # Already rebound event: do nothing. + user:$cur_widget|user:_zsh_highlight_widget_*);; - # Builtin widget: override and make it call the builtin ".widget". - builtin) eval "_zsh_highlight_widget_$cur_widget() { builtin zle .$cur_widget -- \"\$@\" && _zsh_highlight }; \ - zle -N $cur_widget _zsh_highlight_widget_$cur_widget";; + # User defined widget: override and rebind old one with prefix "orig-". + user:*) eval "zle -N orig-$cur_widget ${widgets[$cur_widget]#*:}; \ + _zsh_highlight_widget_$cur_widget() { builtin zle orig-$cur_widget -- \"\$@\" && _zsh_highlight }; \ + zle -N $cur_widget _zsh_highlight_widget_$cur_widget";; - # Default: unhandled case. - *) echo "zsh-syntax-highlighting: unhandled ZLE widget '$cur_widget'" >&2 ;; - esac - done - } - #-------------->8------------------->8------------------->8----------------- + # Completion widget: override and rebind old one with prefix "orig-". + completion:*) eval "zle -C orig-$cur_widget ${${widgets[$cur_widget]#*:}/:/ }; \ + _zsh_highlight_widget_$cur_widget() { builtin zle orig-$cur_widget -- \"\$@\" && _zsh_highlight }; \ + zle -N $cur_widget _zsh_highlight_widget_$cur_widget";; - _zsh_highlight_bind_widgets + # Builtin widget: override and make it call the builtin ".widget". + builtin) eval "_zsh_highlight_widget_$cur_widget() { builtin zle .$cur_widget -- \"\$@\" && _zsh_highlight }; \ + zle -N $cur_widget _zsh_highlight_widget_$cur_widget";; + + # Default: unhandled case. + *) echo "zsh-syntax-highlighting: unhandled ZLE widget '$cur_widget'" >&2 ;; + esac + done + } + #-------------->8------------------->8------------------->8----------------- + # SPDX-SnippetEnd + + _zsh_highlight_bind_widgets + fi + + unfunction _history-substring-search-function-callable fi _history-substring-search-begin() { @@ -243,10 +295,17 @@ _history-substring-search-begin() { fi # - # Escape and join query parts with wildcard character '*' as separator - # `(j:CHAR:)` join array to string with CHAR as separator + # Escape and join query parts with wildcard character '*' as seperator + # `(j:CHAR:)` join array to string with CHAR as seperator # - local search_pattern="*${(j:*:)_history_substring_search_query_parts[@]//(#m)[\][()|\\*?#<>~^]/\\$MATCH}*" + local search_pattern="${(j:*:)_history_substring_search_query_parts[@]//(#m)[\][()|\\*?#<>~^]/\\$MATCH}*" + + # + # Support anchoring history search to the beginning of the command + # + if [[ -z $HISTORY_SUBSTRING_SEARCH_PREFIXED ]]; then + search_pattern="*${search_pattern}" + fi # # Find all occurrences of the search pattern in the history file. @@ -304,12 +363,21 @@ _history-substring-search-begin() { _history-substring-search-end() { setopt localoptions extendedglob + local highlight_memo= _history_substring_search_result=$BUFFER + if [[ $_history_substring_search_zsh_5_9 -eq 1 ]]; then + highlight_memo='memo=history-substring-search' + fi + # the search was successful so display the result properly by clearing away # existing highlights and moving the cursor to the end of the result buffer if [[ $_history_substring_search_refresh_display -eq 1 ]]; then - region_highlight=() + if [[ -n $highlight_memo ]]; then + region_highlight=( "${(@)region_highlight:#*${highlight_memo}*}" ) + else + region_highlight=() + fi CURSOR=${#BUFFER} fi @@ -329,7 +397,9 @@ _history-substring-search-end() { if [[ $query_part_match_index -le ${#BUFFER:$highlight_start_index} ]]; then highlight_start_index=$(( $highlight_start_index + $query_part_match_index )) highlight_end_index=$(( $highlight_start_index + ${#query_part} )) - region_highlight+=("$(($highlight_start_index - 1)) $(($highlight_end_index - 1)) $_history_substring_search_query_highlight") + region_highlight+=( + "$(($highlight_start_index - 1)) $(($highlight_end_index - 1)) ${_history_substring_search_query_highlight}${highlight_memo:+,$highlight_memo}" + ) fi done fi @@ -338,6 +408,23 @@ _history-substring-search-end() { # zle -R "mn: "$_history_substring_search_match_index" m#: "${#_history_substring_search_matches} # read -k -t 200 && zle -U $REPLY + # + # When this function returns, z-sy-h runs its line-pre-redraw hook. It has no + # logic for determining highlight priority, when two different memo= marked + # region highlights overlap; instead, it always prioritises itself. Below is + # a workaround for dealing with it. + # + if [[ $_history_substring_search_zsh_5_9 -eq 1 ]]; then + zle -R + # + # After line redraw with desired highlight, wait for timeout or user input + # before removing search highlight and exiting. This ensures no highlights + # are left lingering after search is finished. + # + read -k -t ${HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_TIMEOUT:-1} && zle -U $REPLY + region_highlight=( "${(@)region_highlight:#*${highlight_memo}*}" ) + fi + # Exit successfully from the history-substring-search-* widgets. return 0 } diff --git a/plugins/history-substring-search/update-from-upstream.zsh b/plugins/history-substring-search/update-from-upstream.zsh deleted file mode 100755 index 81e1942a5..000000000 --- a/plugins/history-substring-search/update-from-upstream.zsh +++ /dev/null @@ -1,129 +0,0 @@ -#!/usr/bin/env zsh -# -# update-from-upstream.zsh -# -# This script updates the Oh My Zsh version of the zsh-history-substring-search -# plugin from the independent upstream repo. This is to be run by OMZ developers -# when they want to pull in new changes from upstream to OMZ. It is not run -# during normal use of the plugin. -# -# The official upstream repo is zsh-users/zsh-history-substring-search -# https://github.com/zsh-users/zsh-history-substring-search -# -# This is a zsh script, not a function. Call it with `zsh update-from-upstream.zsh` -# from the command line, running it from within the plugin directory. -# -# You can set the environment variable REPO_PATH to point it at an upstream -# repo you have already prepared. Otherwise, it will do a clean checkout of -# upstream's HEAD to a temporary local repo and use that. - - -# Just bail on any error so we don't have to do extra checking. -# This is a developer-use script, so terse output like that should -# be fine. -set -e - - -upstream_basename=zsh-history-substring-search -plugin_basename=history-substring-search -UPSTREAM_REPO=zsh-users/$upstream_basename -need_repo_cleanup=false -upstream_github_url="https://github.com/$UPSTREAM_REPO" - -if [[ -z "$UPSTREAM_REPO_PATH" ]]; then - # Do a clean checkout - my_tempdir=$(mktemp -d -t omz-update-histsubstrsrch) - UPSTREAM_REPO_PATH="$my_tempdir/$upstream_basename" - git clone "$upstream_github_url" "$UPSTREAM_REPO_PATH" - need_repo_cleanup=true - print "Checked out upstream repo to $UPSTREAM_REPO_PATH" -else - print "Using existing $upstream_basename repo at $UPSTREAM_REPO_PATH" -fi - -upstream="$UPSTREAM_REPO_PATH" - -# Figure out what we're pulling in -upstream_sha=$(cd $upstream && git rev-parse HEAD) -upstream_commit_date=$(cd $upstream && git log -1 --pretty=format:%ci) -upstream_just_date=${${=upstream_commit_date}[1]} -print "upstream SHA: $upstream_sha" -print "upstream commit time: $upstream_commit_date" -print "upstream commit date: $upstream_just_date" -print - -# Copy the files over, using the OMZ plugin's names where needed -cp -v "$upstream"/* . -mv -v zsh-history-substring-search.zsh $plugin_basename.zsh -mv -v zsh-history-substring-search.plugin.zsh $plugin_basename.plugin.zsh - -if [[ $need_repo_cleanup == true ]]; then - print "Removing temporary repo at $my_tempdir" - rm -rf "$my_tempdir" -fi - -# Do OMZ-specific edits - -print -print "Updating files with OMZ-specific stuff" -print - -# OMZ binds the keys as part of the plugin loading - -cat >> $plugin_basename.plugin.zsh <> README.md < []" @@ -184,7 +184,7 @@ jmodel() { fi local model="$(yq e ".controllers.$(jcontroller).current-model" < ~/.local/share/juju/models.yaml | cut -d/ -f2)" - + if [[ -z "$model" ]]; then echo "--" return 1 diff --git a/plugins/jump/jump.plugin.zsh b/plugins/jump/jump.plugin.zsh index 829c9d9cb..c2b21e92e 100644 --- a/plugins/jump/jump.plugin.zsh +++ b/plugins/jump/jump.plugin.zsh @@ -8,8 +8,10 @@ # export MARKPATH=$HOME/.marks + jump() { - builtin cd -P "$MARKPATH/$1" 2>/dev/null || {echo "No such mark: $1"; return 1} + local markpath="$(readlink $MARKPATH/$1)" || {echo "No such mark: $1"; return 1} + builtin cd "$markpath" 2>/dev/null || {echo "Destination does not exist for mark [$1]: $markpath"; return 2} } mark() { diff --git a/plugins/kind/README.md b/plugins/kind/README.md new file mode 100644 index 000000000..49024648d --- /dev/null +++ b/plugins/kind/README.md @@ -0,0 +1,22 @@ +# Kind plugin + +This plugin adds completion for the [Kind](https://kind.sigs.k8s.io/) tool, as well +as a few aliases for easier use. + +To use it, add `kind` to the plugins array in your zshrc file: + +```zsh +plugins=(... kind) +``` + +## Aliases + +| Alias | Command | +| ------- | ---------------------------- | +| `kicc` | `kind create cluster` | +| `kiccn` | `kind create cluster --name` | +| `kigc` | `kind get clusters` | +| `kidc` | `kind delete cluster` | +| `kidcn` | `kind delete cluster --name` | +| `kidca` | `kind delete clusters -A` | +| `kigk` | `kind get kubeconfig` | diff --git a/plugins/kind/kind.plugin.zsh b/plugins/kind/kind.plugin.zsh new file mode 100644 index 000000000..183eb7bd6 --- /dev/null +++ b/plugins/kind/kind.plugin.zsh @@ -0,0 +1,23 @@ +if (( ! $+commands[kind] )); then + return +fi + +# If the completion file doesn't exist yet, we need to autoload it and +# bind it to `kind`. Otherwise, compinit will have already done that. +if [[ ! -f "$ZSH_CACHE_DIR/completions/_kind" ]]; then + typeset -g -A _comps + autoload -Uz _kind + _comps[kind]=_kind +fi + +# Generate and load kind completion +kind completion zsh >! "$ZSH_CACHE_DIR/completions/_kind" &| + +# Register aliases +alias kicc="kind create cluster" +alias kiccn="kind create cluster --name" +alias kigc="kind get clusters" +alias kidc="kind delete cluster" +alias kidcn="kind delete cluster --name" +alias kidca="kind delete clusters -A" +alias kigk="kind get kubeconfig" diff --git a/plugins/kn/kn.plugin.zsh b/plugins/kn/kn.plugin.zsh index f60177dd9..483d1d68c 100644 --- a/plugins/kn/kn.plugin.zsh +++ b/plugins/kn/kn.plugin.zsh @@ -4,5 +4,5 @@ if [ $commands[kn] ]; then source <(kn completion zsh) - compdef _kn kn + compdef _kn kn fi diff --git a/plugins/kube-ps1/README.md b/plugins/kube-ps1/README.md index 1ed3e4438..dd49eff39 100644 --- a/plugins/kube-ps1/README.md +++ b/plugins/kube-ps1/README.md @@ -136,6 +136,7 @@ the following environment variables: | `KUBE_PS1_SUFFIX` | `)` | Prompt closing character | | `KUBE_PS1_CLUSTER_FUNCTION` | No default, must be user supplied | Function to customize how cluster is displayed | | `KUBE_PS1_NAMESPACE_FUNCTION` | No default, must be user supplied | Function to customize how namespace is displayed | +| `KUBE_PS1_KUBECONFIG_SYMLINK` | `false` | Treat `KUBECONFIG` and `~/.kube/config` files as symbolic links | For terminals that do not support UTF-8, the symbol will be replaced with the string `k8s`. diff --git a/plugins/kube-ps1/kube-ps1.plugin.zsh b/plugins/kube-ps1/kube-ps1.plugin.zsh index 894e0f7f0..7edc62de8 100644 --- a/plugins/kube-ps1/kube-ps1.plugin.zsh +++ b/plugins/kube-ps1/kube-ps1.plugin.zsh @@ -40,6 +40,7 @@ KUBE_PS1_NS_COLOR="${KUBE_PS1_NS_COLOR-cyan}" KUBE_PS1_BG_COLOR="${KUBE_PS1_BG_COLOR}" KUBE_PS1_KUBECONFIG_CACHE="${KUBECONFIG}" +KUBE_PS1_KUBECONFIG_SYMLINK="${KUBE_PS1_KUBECONFIG_SYMLINK:-false}" KUBE_PS1_DISABLE_PATH="${HOME}/.kube/kube-ps1/disabled" KUBE_PS1_LAST_TIME=0 KUBE_PS1_CLUSTER_FUNCTION="${KUBE_PS1_CLUSTER_FUNCTION}" @@ -190,14 +191,26 @@ _kube_ps1_file_newer_than() { local file=$1 local check_time=$2 - if [[ "${KUBE_PS1_SHELL}" == "zsh" ]]; then - mtime=$(zstat +mtime "${file}") - elif stat -c "%s" /dev/null &> /dev/null; then - # GNU stat - mtime=$(stat -L -c %Y "${file}") + if [[ "${KUBE_PS1_KUBECONFIG_SYMLINK}" == "true" ]]; then + if [[ "${KUBE_PS1_SHELL}" == "zsh" ]]; then + mtime=$(zstat -L +mtime "${file}") + elif stat -c "%s" /dev/null &> /dev/null; then + # GNU stat + mtime=$(stat -c %Y "${file}") + else + # BSD stat + mtime=$(stat -f %m "$file") + fi else - # BSD stat - mtime=$(stat -L -f %m "$file") + if [[ "${KUBE_PS1_SHELL}" == "zsh" ]]; then + mtime=$(zstat +mtime "${file}") + elif stat -c "%s" /dev/null &> /dev/null; then + # GNU stat + mtime=$(stat -L -c %Y "${file}") + else + # BSD stat + mtime=$(stat -L -f %m "$file") + fi fi [[ "${mtime}" -gt "${check_time}" ]] diff --git a/plugins/kubectl/kubectl.plugin.zsh b/plugins/kubectl/kubectl.plugin.zsh index 315d3ce93..0dd4e691a 100644 --- a/plugins/kubectl/kubectl.plugin.zsh +++ b/plugins/kubectl/kubectl.plugin.zsh @@ -162,6 +162,7 @@ alias kdelsa="kubectl delete sa" # DaemonSet management. alias kgds='kubectl get daemonset' +alias kgdsa='kubectl get daemonset --all-namespaces' alias kgdsw='kgds --watch' alias keds='kubectl edit daemonset' alias kdds='kubectl describe daemonset' diff --git a/plugins/kubectx/README.md b/plugins/kubectx/README.md index 98f1cf032..d924e745c 100644 --- a/plugins/kubectx/README.md +++ b/plugins/kubectx/README.md @@ -17,9 +17,9 @@ One can rename default context name for better readability. _Example_. Add to **.zshrc**: ``` -kubectx_mapping[minikube]="mini" -kubectx_mapping[context_name_from_kubeconfig]="$emoji[wolf_face]" -kubectx_mapping[production_cluster]="%{$fg[yellow]%}prod!%{$reset_color%}" +kubectx_mapping["minikube"]="mini" +kubectx_mapping["context_name_from_kubeconfig"]="$emoji[wolf_face]" +kubectx_mapping["production_cluster"]="%{$fg[yellow]%}prod!%{$reset_color%}" ``` ![staging](stage.png) diff --git a/plugins/kubectx/kubectx.plugin.zsh b/plugins/kubectx/kubectx.plugin.zsh index 6096feeae..a3210facc 100644 --- a/plugins/kubectx/kubectx.plugin.zsh +++ b/plugins/kubectx/kubectx.plugin.zsh @@ -9,5 +9,5 @@ function kubectx_prompt_info() { # use value in associative array if it exists # otherwise fall back to the context name - echo "${kubectx_mapping[$current_ctx]:-${current_ctx:gs/%/%%}}" + echo "${kubectx_mapping[\"$current_ctx\"]:-${current_ctx:gs/%/%%}}" } diff --git a/plugins/lando/README.md b/plugins/lando/README.md index 6daeae4e4..2f881cf3d 100644 --- a/plugins/lando/README.md +++ b/plugins/lando/README.md @@ -8,7 +8,7 @@ To use it, add `lando` to the plugins array in your zshrc file: plugins=(... lando) ``` -## ALIASES: +## Wrapped Commands | Alias | Description | |:----------:|:----------------:| @@ -21,16 +21,34 @@ plugins=(... lando) | `wp` | `lando wp` | | `yarn` | `lando yarn` | +More or different commands can be wrapped by setting the `LANDO_ZSH_WRAPPED_COMMANDS` setting, see [Settings](#settings) below. + ## How It Works: This plugin removes the requirement to type `lando` before a command. It utilizes the lando version of supported commands run within directories with the following criteria: + - The `.lando.yml` file is found in the current directory or any parent directory within `$LANDO_ZSH_SITES_DIRECTORY`. - The current directory is within `$LANDO_ZSH_SITES_DIRECTORY` but is not `$LANDO_ZSH_SITES_DIRECTORY` itself. +- If the command is not a part of the commands available in the lando environment, it will run the command without `lando`. ## Settings: -- `LANDO_ZSH_SITES_DIRECTORY`: The plugin will stop searching through parents for `CONFIG_FILE` once it hits this directory. -- `LANDO_ZSH_CONFIG_FILE`: The plugin will check to see if this provided file exists to check for presence of Lando. +> NOTE: these settings must be set *before* the plugin is loaded, and any changes require a restart of the shell to be applied. + +- `LANDO_ZSH_SITES_DIRECTORY`: The plugin will stop searching through parents for `CONFIG_FILE` once it hits this directory: + ```sh + LANDO_ZSH_SITES_DIRECTORY="$HOME/Code" + ``` + +- `LANDO_ZSH_CONFIG_FILE`: The plugin will check to see if this provided file exists to check for presence of Lando: + ```sh + LANDO_ZSH_CONFIG_FILE=".lando.dev.yml" + ``` + +- `LANDO_ZSH_WRAPPED_COMMANDS`: The list of commands to wrap, as a string of commands separated by whitespace: + ```sh + LANDO_ZSH_WRAPPED_COMMANDS="mysql php composer test artisan" + ``` ## Author: diff --git a/plugins/lando/lando.plugin.zsh b/plugins/lando/lando.plugin.zsh index af53e7e5a..ee796d212 100644 --- a/plugins/lando/lando.plugin.zsh +++ b/plugins/lando/lando.plugin.zsh @@ -1,25 +1,36 @@ # Settings : ${LANDO_ZSH_SITES_DIRECTORY:="$HOME/Sites"} : ${LANDO_ZSH_CONFIG_FILE:=.lando.yml} +: ${LANDO_ZSH_WRAPPED_COMMANDS:=" + artisan + composer + drush + gulp + npm + php + wp + yarn +"} # Enable multiple commands with lando. -function artisan \ - composer \ - drush \ - gulp \ - npm \ - php \ - wp \ - yarn { - if checkForLandoFile; then - lando "$0" "$@" +function ${=LANDO_ZSH_WRAPPED_COMMANDS} { + # If the lando task is available in `lando --help`, then it means: + # + # 1. `lando` is in a project with a `.lando.yml` file. + # 2. The lando task is available for lando, based on the .lando.yml config file. + # + # This has a penalty of about 250ms, so we still want to check if the lando file + # exists before, which is the fast path. If it exists, checking help output is + # still faster than running the command and failing. + if _lando_file_exists && lando --help 2>&1 | command grep -Eq "^ +lando $0 "; then + command lando "$0" "$@" else command "$0" "$@" fi } # Check for the file in the current and parent directories. -checkForLandoFile() { +_lando_file_exists() { # Only bother checking for lando within the Sites directory. if [[ "$PWD/" != "$LANDO_ZSH_SITES_DIRECTORY"/* ]]; then # Not within $LANDO_ZSH_SITES_DIRECTORY @@ -38,4 +49,4 @@ checkForLandoFile() { # Could not find $LANDO_ZSH_CONFIG_FILE in the current directory # or in any of its parents up to $LANDO_ZSH_SITES_DIRECTORY. return 1 -} \ No newline at end of file +} diff --git a/plugins/laravel/README.md b/plugins/laravel/README.md index 95f590191..a831a86b6 100644 --- a/plugins/laravel/README.md +++ b/plugins/laravel/README.md @@ -10,6 +10,7 @@ plugins=(... laravel) |:-:|:-:| | `artisan` | `php artisan` | | `pas` | `php artisan serve` | +| `pats` | `php artisan test` | ## Database diff --git a/plugins/laravel/laravel.plugin.zsh b/plugins/laravel/laravel.plugin.zsh index a8382d3c9..319946f07 100644 --- a/plugins/laravel/laravel.plugin.zsh +++ b/plugins/laravel/laravel.plugin.zsh @@ -4,6 +4,7 @@ alias bob='php artisan bob::build' # Development alias pas='php artisan serve' +alias pats='php artisan test' # Database alias pam='php artisan migrate' diff --git a/plugins/macos/README.md b/plugins/macos/README.md index 1cb9b395d..2c52ec8a7 100644 --- a/plugins/macos/README.md +++ b/plugins/macos/README.md @@ -17,7 +17,7 @@ Original author: [Sorin Ionescu](https://github.com/sorin-ionescu) | `tab` | Open the current directory in a new tab | | `split_tab` | Split the current terminal tab horizontally | | `vsplit_tab` | Split the current terminal tab vertically | -| `ofd` | Open the current directory in a Finder window | +| `ofd` | Open passed directories (or $PWD by default) in Finder | | `pfd` | Return the path of the frontmost Finder window | | `pfs` | Return the current Finder selection | | `cdf` | `cd` to the current Finder directory | diff --git a/plugins/macos/macos.plugin.zsh b/plugins/macos/macos.plugin.zsh index e27d412c8..2702a1901 100644 --- a/plugins/macos/macos.plugin.zsh +++ b/plugins/macos/macos.plugin.zsh @@ -3,8 +3,15 @@ 0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}" 0="${${(M)0:#/*}:-$PWD/$0}" -# Open the current directory in a Finder window -alias ofd='open_command $PWD' +# Open in Finder the directories passed as arguments, or the current directory if +# no directories are passed +function ofd { + if (( ! $# )); then + open_command $PWD + else + open_command $@ + fi +} # Show/hide hidden files in the Finder alias showfiles="defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder" @@ -224,6 +231,8 @@ function quick-look() { } function man-preview() { + [[ $# -eq 0 ]] && >&2 echo "Usage: $0 command1 [command2 ...]" && return 1 + local page for page in "${(@f)"$(man -w $@)"}"; do command mandoc -Tpdf $page | open -f -a Preview diff --git a/plugins/macos/spotify b/plugins/macos/spotify index 5fb40517c..ae42db425 100644 --- a/plugins/macos/spotify +++ b/plugins/macos/spotify @@ -1,7 +1,7 @@ #!/usr/bin/env bash function spotify() { -# Copyright (c) 2012--2019 Harish Narayanan +# Copyright (c) 2012--2023 Harish Narayanan # # Contains numerous helpful contributions from Jorge Colindres, Thomas # Pritchard, iLan Epstein, Gabriele Bonetti, Sean Heller, Eric Martin @@ -35,6 +35,9 @@ if ! [[ -f "${USER_CONFIG_FILE}" ]]; then fi source "${USER_CONFIG_FILE}"; +# Set the percent change in volume for vol up and vol down +VOL_INCREMENT=10 + showAPIHelp() { echo; echo "Connecting to Spotify's API:"; @@ -170,12 +173,12 @@ while [ $# -gt 0 ]; do if [ -z "${CLIENT_ID}" ]; then cecho "Invalid Client ID, please update ${USER_CONFIG_FILE}"; showAPIHelp; - return 1 + return 1; fi if [ -z "${CLIENT_SECRET}" ]; then cecho "Invalid Client Secret, please update ${USER_CONFIG_FILE}"; showAPIHelp; - return 1 + return 1; fi SHPOTIFY_CREDENTIALS=$(printf "${CLIENT_ID}:${CLIENT_SECRET}" | base64 | tr -d "\n"|tr -d '\r'); SPOTIFY_PLAY_URI=""; @@ -198,7 +201,7 @@ while [ $# -gt 0 ]; do fi SPOTIFY_ACCESS_TOKEN=$( \ printf "${SPOTIFY_TOKEN_RESPONSE_DATA}" \ - | grep -E -o '"access_token":".*",' \ + | command grep -E -o '"access_token":".*",' \ | sed 's/"access_token"://g' \ | sed 's/"//g' \ | sed 's/,.*//g' \ @@ -219,9 +222,8 @@ while [ $# -gt 0 ]; do -H "Accept: application/json" \ --data-urlencode "q=$Q" \ -d "type=$type&limit=1&offset=0" \ - | grep -E -o "spotify:$type:[a-zA-Z0-9]+" -m 1 + | command grep -E -o "spotify:$type:[a-zA-Z0-9]+" -m 1 ) - echo "play uri: ${SPOTIFY_PLAY_URI}" } case $2 in @@ -235,11 +237,11 @@ while [ $# -gt 0 ]; do results=$( \ curl -s -G $SPOTIFY_SEARCH_API --data-urlencode "q=$Q" -d "type=playlist&limit=10&offset=0" -H "Accept: application/json" -H "Authorization: Bearer ${SPOTIFY_ACCESS_TOKEN}" \ - | grep -E -o "spotify:playlist:[a-zA-Z0-9]+" -m 10 \ + | command grep -E -o "spotify:playlist:[a-zA-Z0-9]+" -m 10 \ ) count=$( \ - echo "$results" | grep -c "spotify:playlist" \ + echo "$results" | command grep -c "spotify:playlist" \ ) if [ "$count" -gt 0 ]; then @@ -333,16 +335,16 @@ while [ $# -gt 0 ]; do cecho "Current Spotify volume level is $vol."; break ; elif [ "$2" = "up" ]; then - if [ $vol -le 90 ]; then - newvol=$(( vol+10 )); + if [ $vol -le $(( 100-$VOL_INCREMENT )) ]; then + newvol=$(( vol+$VOL_INCREMENT )); cecho "Increasing Spotify volume to $newvol."; else newvol=100; cecho "Spotify volume level is at max."; fi elif [ "$2" = "down" ]; then - if [ $vol -ge 10 ]; then - newvol=$(( vol-10 )); + if [ $vol -ge $(( $VOL_INCREMENT )) ]; then + newvol=$(( vol-$VOL_INCREMENT )); cecho "Reducing Spotify volume to $newvol."; else newvol=0; @@ -354,11 +356,11 @@ while [ $# -gt 0 ]; do else echo "Improper use of 'vol' command" echo "The 'vol' command should be used as follows:" - echo " vol up # Increases the volume by 10%."; - echo " vol down # Decreases the volume by 10%."; + echo " vol up # Increases the volume by $VOL_INCREMENT%."; + echo " vol down # Decreases the volume by $VOL_INCREMENT%."; echo " vol [amount] # Sets the volume to an amount between 0 and 100."; echo " vol # Shows the current Spotify volume."; - return 1 + return 1; fi osascript -e "tell application \"Spotify\" to set sound volume to $newvol"; @@ -468,10 +470,9 @@ while [ $# -gt 0 ]; do "help" ) showHelp; break ;; - * ) showHelp; - return 1 ;; + return 1; esac done diff --git a/plugins/macports/_port b/plugins/macports/_port index 897598a46..f40f6550b 100644 --- a/plugins/macports/_port +++ b/plugins/macports/_port @@ -1,6 +1,6 @@ #compdef port -local subcmds +local subcmds # we cache the list of ports # we shall use some cache policy to avoid problems with new ports @@ -31,8 +31,8 @@ subcmds=( 'file' 'help' 'info' -'install' -'installed' +'install' +'installed' 'list' 'livecheck' 'location' @@ -51,7 +51,7 @@ subcmds=( 'test' 'unarchive' 'uninstall' -'upgrade' +'upgrade' 'variants' 'version' ) diff --git a/plugins/marked2/README.md b/plugins/marked2/README.md index 101343abb..2f825bc4a 100644 --- a/plugins/marked2/README.md +++ b/plugins/marked2/README.md @@ -1,6 +1,6 @@ ## marked2 -Plugin for Marked 2, a previewer for Markdown files on Mac OS X +Plugin for Marked 2, a previewer for Markdown files on Mac OS X ### Requirements diff --git a/plugins/marktext/README.md b/plugins/marktext/README.md index 71d287451..254e4e7ac 100644 --- a/plugins/marktext/README.md +++ b/plugins/marktext/README.md @@ -1,6 +1,6 @@ ## marktext -Plugin for MarkText, a previewer for Markdown files on Mac OS X +Plugin for MarkText, a previewer for Markdown files on Mac OS X ### Requirements diff --git a/plugins/minikube/minikube.plugin.zsh b/plugins/minikube/minikube.plugin.zsh index e87abceaf..0d2737052 100644 --- a/plugins/minikube/minikube.plugin.zsh +++ b/plugins/minikube/minikube.plugin.zsh @@ -1,13 +1,13 @@ -# Autocompletion for Minikube. -# -if (( $+commands[minikube] )); then - __MINIKUBE_COMPLETION_FILE="${ZSH_CACHE_DIR}/minikube_completion" - - if [[ ! -f $__MINIKUBE_COMPLETION_FILE ]]; then - minikube completion zsh >! $__MINIKUBE_COMPLETION_FILE - fi - - [[ -f $__MINIKUBE_COMPLETION_FILE ]] && source $__MINIKUBE_COMPLETION_FILE - - unset __MINIKUBE_COMPLETION_FILE +if (( ! $+commands[minikube] )); then + return fi + +# If the completion file doesn't exist yet, we need to autoload it and +# bind it to `minikube`. Otherwise, compinit will have already done that. +if [[ ! -f "$ZSH_CACHE_DIR/completions/_minikube" ]]; then + typeset -g -A _comps + autoload -Uz _minikube + _comps[minikube]=_minikube +fi + +minikube completion zsh >| "$ZSH_CACHE_DIR/completions/_minikube" &| diff --git a/plugins/mise/README.md b/plugins/mise/README.md new file mode 100644 index 000000000..8ec05aab9 --- /dev/null +++ b/plugins/mise/README.md @@ -0,0 +1,32 @@ +# mise + +Adds integration with [mise](https://github.com/jdx/mise) (formerly `rtx`), a runtime executor compatible with +npm, nodenv, pyenv, etc. mise is written in rust and is very fast. 20x-200x faster than asdf. With that being +said, mise is compatible with asdf plugins and .tool-versions files. It can be used as a drop-in replacement. + +## Installation + +1. [Download & install mise](https://github.com/jdx/mise#installation) by running the following: + +```bash +curl https://mise.jdx.dev/install.sh | sh +``` + +2. [Enable mise](https://github.com/jdx/mise#quickstart) by adding it to your `plugins` definition in + `~/.zshrc`. + +```bash +plugins=(mise) +``` + +## Usage + +See the [mise readme](https://github.com/jdx/mise#table-of-contents) for information on how to use mise. Here +are a few examples: + +```bash +mise install node Install the current version specified in .tool-versions/.mise.toml +mise use -g node@system Use system node as global default +mise install node@20.0.0 Install a specific version number +mise use -g node@20 Use node-20.x as global default +``` diff --git a/plugins/mise/mise.plugin.zsh b/plugins/mise/mise.plugin.zsh new file mode 100644 index 000000000..357174d91 --- /dev/null +++ b/plugins/mise/mise.plugin.zsh @@ -0,0 +1,26 @@ +# TODO: 2024-01-03 remove rtx support +local __mise=mise +if (( ! $+commands[mise] )); then + if (( $+commands[rtx] )); then + __mise=rtx + else + return + fi +fi + +# Load mise hooks +eval "$($__mise activate zsh)" + +# Hook mise into current environment +eval "$($__mise hook-env -s zsh)" + +# If the completion file doesn't exist yet, we need to autoload it and +# bind it to `mise`. Otherwise, compinit will have already done that. +if [[ ! -f "$ZSH_CACHE_DIR/completions/_$__mise" ]]; then + typeset -g -A _comps + autoload -Uz _$__mise + _comps[$__mise]=_$__mise +fi + +# Generate and load mise completion +$__mise completion zsh >| "$ZSH_CACHE_DIR/completions/_$__mise" &| diff --git a/plugins/mongo-atlas/README.md b/plugins/mongo-atlas/README.md index ef1b5e0d2..94183c544 100644 --- a/plugins/mongo-atlas/README.md +++ b/plugins/mongo-atlas/README.md @@ -1,6 +1,6 @@ # MongoDB Atlas plugin -This plugin adds completion for [Atlas](https://www.mongodb.com/docs/atlas/cli/stable/) a command line interface built specifically for +This plugin adds completion for [Atlas](https://www.mongodb.com/docs/atlas/cli/stable/) a command line interface built specifically for MongoDB Atlas. To use it, add `mongo-atlas` to the plugins array in your zshrc file: diff --git a/plugins/n98-magerun/n98-magerun.plugin.zsh b/plugins/n98-magerun/n98-magerun.plugin.zsh index d79aee7eb..2744ad96e 100644 --- a/plugins/n98-magerun/n98-magerun.plugin.zsh +++ b/plugins/n98-magerun/n98-magerun.plugin.zsh @@ -1,6 +1,6 @@ # ------------------------------------------------------------------------------ # FILE: n98-magerun.plugin.zsh -# DESCRIPTION: oh-my-zsh n98-magerun plugin file. Adapted from composer plugin +# DESCRIPTION: oh-my-zsh n98-magerun plugin file. Adapted from composer plugin # AUTHOR: Andrew Dwyer (andrewrdwyer at gmail dot com) # AUTHOR: Jisse Reitsma (jisse at yireo dot com) # VERSION: 1.1.0 diff --git a/plugins/nmap/nmap.plugin.zsh b/plugins/nmap/nmap.plugin.zsh index 406870f00..f649dafc2 100644 --- a/plugins/nmap/nmap.plugin.zsh +++ b/plugins/nmap/nmap.plugin.zsh @@ -27,6 +27,6 @@ alias nmap_detect_versions="sudo nmap -sV -p1-65535 -O --osscan-guess -T4 -Pn" alias nmap_check_for_vulns="nmap --script=vuln" alias nmap_full_udp="sudo nmap -sS -sU -T4 -A -v -PE -PS22,25,80 -PA21,23,80,443,3389 " alias nmap_traceroute="sudo nmap -sP -PE -PS22,25,80 -PA21,23,80,3389 -PU -PO --traceroute " -alias nmap_full_with_scripts="sudo nmap -sS -sU -T4 -A -v -PE -PP -PS21,22,23,25,80,113,31339 -PA80,113,443,10042 -PO --script all " +alias nmap_full_with_scripts="sudo nmap -sS -sU -T4 -A -v -PE -PP -PS21,22,23,25,80,113,31339 -PA80,113,443,10042 -PO --script all " alias nmap_web_safe_osscan="sudo nmap -p 80,443 -O -v --osscan-guess --fuzzy " alias nmap_ping_scan="nmap -n -sP" diff --git a/plugins/nomad/_nomad b/plugins/nomad/_nomad index 1c935a02e..87f80aa84 100644 --- a/plugins/nomad/_nomad +++ b/plugins/nomad/_nomad @@ -89,7 +89,7 @@ __plan() { '-address=[(addr) The address of the Nomad server. Overrides the NOMAD_ADDR environment variable if set. Default = http://127.0.0.1:4646]' \ '-region=[(region) The region of the Nomad servers to forward commands to. Overrides the NOMAD_REGION environment variable if set. Defaults to the Agent s local region.]' \ '-no-color[Disables colored command output.]' \ - '-diff[Determines whether the diff between the remote job and planned job is shown. Defaults to true.]' + '-diff[Determines whether the diff between the remote job and planned job is shown. Defaults to true.]' } __run() { @@ -97,7 +97,7 @@ __run() { '-address=[(addr) The address of the Nomad server. Overrides the NOMAD_ADDR environment variable if set. Default = http://127.0.0.1:4646]' \ '-region=[(region) The region of the Nomad servers to forward commands to. Overrides the NOMAD_REGION environment variable if set. Defaults to the Agent s local region.]' \ '-no-color[Disables colored command output.]' \ - '-check-index[If set, the job is only registered or updated if the the passed job modify index matches the server side version. If a check-index value of zero is passed, the job is only registered if it does not yet exist. If a non-zero value is passed, it ensures that the job is being updated from a known state. The use of this flag is most common in conjunction with plan command.]' \ + '-check-index[If set, the job is only registered or updated if the passed job modify index matches the server side version. If a check-index value of zero is passed, the job is only registered if it does not yet exist. If a non-zero value is passed, it ensures that the job is being updated from a known state. The use of this flag is most common in conjunction with plan command.]' \ '-detach[Return immediately instead of entering monitor mode. After job submission, the evaluation ID will be printed to the screen, which can be used to examine the evaluation using the eval-status command.]' \ '-output[Output the JSON that would be submitted to the HTTP API without submitting the job.]' \ '-verbose[Show full information.]' diff --git a/plugins/npm/README.md b/plugins/npm/README.md index 420dd710a..7848a1290 100644 --- a/plugins/npm/README.md +++ b/plugins/npm/README.md @@ -30,6 +30,7 @@ plugins=(... npm) | `npmi` | `npm info` | Run npm info | | `npmSe` | `npm search` | Run npm search | | `npmrd` | `npm run dev` | Run npm run dev | +| `npmrb` | `npm run build` | Run npm run build | ## `npm install` / `npm uninstall` toggle diff --git a/plugins/npm/npm.plugin.zsh b/plugins/npm/npm.plugin.zsh index 3cba18f6c..c333f76ed 100644 --- a/plugins/npm/npm.plugin.zsh +++ b/plugins/npm/npm.plugin.zsh @@ -58,7 +58,7 @@ alias npmt="npm test" # Run npm scripts alias npmR="npm run" -# Run npm publish +# Run npm publish alias npmP="npm publish" # Run npm init @@ -73,6 +73,9 @@ alias npmSe="npm search" # Run npm run dev alias npmrd="npm run dev" +# Run npm run build +alias npmrb="npm run build" + npm_toggle_install_uninstall() { # Look up to the previous 2 history commands local line diff --git a/plugins/nvm/README.md b/plugins/nvm/README.md index eee3bf717..eb1e236ee 100644 --- a/plugins/nvm/README.md +++ b/plugins/nvm/README.md @@ -26,9 +26,9 @@ These settings should go in your zshrc file, before Oh My Zsh is sourced: #### Lazy startup This option will help you to defer nvm's load until you use it to speed-up your zsh startup. This will source -nvm script only when using it, and will create a function for `node`, `npm`, `npx`, `pnpm`, `yarn`, and the -command(s) specified by `lazy-cmd` option, so when you call either of them, nvm will be loaded and run with -default version. To enable it, you can add this snippet to your zshrc, before Oh My Zsh is sourced: +nvm script only when using it, and will create a function for `node`, `npm`, `npx`, `pnpm`, `yarn`, `corepack` +and the command(s) specified by `lazy-cmd` option, so when you call either of them, nvm will be loaded and run +with default version. To enable it, you can add this snippet to your zshrc, before Oh My Zsh is sourced: ```zsh zstyle ':omz:plugins:nvm' lazy yes @@ -43,8 +43,7 @@ zstyle ':omz:plugins:nvm' lazy-cmd eslint prettier typescript ... #### `.nvmrc` autoload -Note: _this option cannot be used at the same time as `lazy`. `autoload` will override it and load `nvm` at -startup._ +Note: _if used at the same time as `lazy`, `autoload` will start working only after nvm has been lazy-loaded_ If set, the plugin will automatically load a node version when if finds a [`.nvmrc` file](https://github.com/nvm-sh/nvm#nvmrc) in the current working directory indicating which node @@ -52,12 +51,7 @@ version to load. This can be done, similar as previous options, adding: ```zsh zstyle ':omz:plugins:nvm' autoload yes -``` - -To remove the output generated by NVM when autoloading, you can set the following option: - -```zsh -zstyle ':omz:plugins:nvm' silent-autoload yes +zstyle ':omz:plugins:nvm' silent-autoload yes # optionally remove the output generated by NVM when autoloading ``` Note: _this will not remove regular `nvm` output_ diff --git a/plugins/nvm/_nvm b/plugins/nvm/_nvm deleted file mode 100644 index e292a8d8c..000000000 --- a/plugins/nvm/_nvm +++ /dev/null @@ -1,34 +0,0 @@ -#compdef nvm -#autoload - -[[ -f "$NVM_DIR/nvm.sh" ]] || return 0 - -local -a _1st_arguments -_1st_arguments=( - 'help:show help' - '--version:print out the latest released version of nvm' - 'install:download and install a version in ' - 'install-latest-npm:download and install the latest npm version' - 'uninstall:uninstall a version' - 'use:modify PATH to use . Uses .nvmrc if available' - 'exec:run on . Uses .nvmrc if available' - 'run:run `node` on with as arguments. Uses .nvmrc if available' - 'current:list installed versions' - 'ls:list installed versions or versions matching a given description' - 'version:resolve the given description to a single local version' - 'version-remote:resolve the given description to a single remote version' - 'ls-remote:list remote versions available for install' - 'deactivate:undo effects of `nvm` on current shell' - 'alias:show or set aliases' - 'unalias:deletes an alias' - 'reinstall-packages:reinstall global `npm` packages contained in to current version' - 'unload:unload `nvm` from shell' - 'which:display path to installed node version. Uses .nvmrc if available' -) - -_arguments -C '*:: :->subcmds' && return 0 - -if (( CURRENT == 1 )); then - _describe -t commands "nvm subcommand" _1st_arguments - return -fi diff --git a/plugins/nvm/nvm.plugin.zsh b/plugins/nvm/nvm.plugin.zsh index 484ef2964..95c94030a 100644 --- a/plugins/nvm/nvm.plugin.zsh +++ b/plugins/nvm/nvm.plugin.zsh @@ -1,3 +1,7 @@ +# Don't try to load nvm if command already available +# Note: nvm is a function so we need to use `which` +which nvm &>/dev/null && return + # See https://github.com/nvm-sh/nvm#installation-and-update if [[ -z "$NVM_DIR" ]]; then if [[ -d "$HOME/.nvm" ]]; then @@ -12,42 +16,35 @@ if [[ -z "$NVM_DIR" ]]; then fi fi -# Don't try to load nvm if command already available -# Note: nvm is a function so we need to use `which` -which nvm &>/dev/null && return - -if [[ -z "$NVM_DIR" ]]; then - echo "[oh-my-zsh] nvm installation cannot be found" - echo "[oh-my-zsh] set NVM_DIR to your installation" - return -fi -if [[ ! -f "$NVM_DIR/nvm.sh" ]]; then - echo "[oh-my-zsh] nvm.sh does not exist in $NVM_DIR" +if [[ -z "$NVM_DIR" ]] || [[ ! -f "$NVM_DIR/nvm.sh" ]]; then return fi -if zstyle -t ':omz:plugins:nvm' lazy && \ - ! zstyle -t ':omz:plugins:nvm' autoload; then - # Call nvm when first using nvm, node, npm, pnpm, yarn or other commands in lazy-cmd - zstyle -a ':omz:plugins:nvm' lazy-cmd nvm_lazy_cmd - eval " - function nvm node npm npx pnpm yarn $nvm_lazy_cmd { - unfunction nvm node npm npx pnpm yarn $nvm_lazy_cmd - # Load nvm if it exists in \$NVM_DIR - [[ -f \"\$NVM_DIR/nvm.sh\" ]] && source \"\$NVM_DIR/nvm.sh\" - \"\$0\" \"\$@\" - } - " - unset nvm_lazy_cmd -else - source "$NVM_DIR/nvm.sh" -fi +function _omz_load_nvm_completion { + local _nvm_completion + # Load nvm bash completion + for _nvm_completion in "$NVM_DIR/bash_completion" "$NVM_HOMEBREW/etc/bash_completion.d/nvm"; do + if [[ -f "$_nvm_completion" ]]; then + # Load bashcompinit + autoload -U +X bashcompinit && bashcompinit + # Bypass compinit call in nvm bash completion script. See: + # https://github.com/nvm-sh/nvm/blob/4436638/bash_completion#L86-L93 + ZSH_VERSION= source "$_nvm_completion" + break + fi + done + unfunction _omz_load_nvm_completion +} -# Autoload nvm when finding a .nvmrc file in the current directory -# Adapted from: https://github.com/nvm-sh/nvm#zsh -if zstyle -t ':omz:plugins:nvm' autoload; then +function _omz_setup_autoload { + if ! zstyle -t ':omz:plugins:nvm' autoload; then + unfunction _omz_setup_autoload + return + fi + + # Autoload nvm when finding a .nvmrc file in the current directory + # Adapted from: https://github.com/nvm-sh/nvm#zsh function load-nvmrc { - local node_version="$(nvm version)" local nvmrc_path="$(nvm_find_nvmrc)" local nvm_silent="" zstyle -t ':omz:plugins:nvm' silent-autoload && nvm_silent="--silent" @@ -60,10 +57,8 @@ if zstyle -t ':omz:plugins:nvm' autoload; then elif [[ "$nvmrc_node_version" != "$node_version" ]]; then nvm use $nvm_silent fi - elif [[ "$node_version" != "$(nvm version default)" ]]; then - if [[ -z $nvm_silent ]]; then - echo "Reverting to nvm default version" - fi + elif [[ -n "$(PWD=$OLDPWD nvm_find_nvmrc)" ]] && [[ "$(nvm version)" != "$(nvm version default)" ]]; then + [[ -z $nvm_silent ]] && echo "Reverting to nvm default version" nvm use default $nvm_silent fi @@ -73,18 +68,30 @@ if zstyle -t ':omz:plugins:nvm' autoload; then add-zsh-hook chpwd load-nvmrc load-nvmrc + unfunction _omz_setup_autoload +} + +if zstyle -t ':omz:plugins:nvm' lazy; then + # Call nvm when first using nvm, node, npm, pnpm, yarn, corepack or other commands in lazy-cmd + zstyle -a ':omz:plugins:nvm' lazy-cmd nvm_lazy_cmd + nvm_lazy_cmd=(nvm node npm npx pnpm yarn corepack $nvm_lazy_cmd) # default values + eval " + function $nvm_lazy_cmd { + for func in $nvm_lazy_cmd; do + if (( \$+functions[\$func] )); then + unfunction \$func + fi + done + # Load nvm if it exists in \$NVM_DIR + [[ -f \"\$NVM_DIR/nvm.sh\" ]] && source \"\$NVM_DIR/nvm.sh\" + _omz_load_nvm_completion + _omz_setup_autoload + \"\$0\" \"\$@\" + } + " + unset nvm_lazy_cmd +else + source "$NVM_DIR/nvm.sh" + _omz_load_nvm_completion + _omz_setup_autoload fi - -# Load nvm bash completion -for nvm_completion in "$NVM_DIR/bash_completion" "$NVM_HOMEBREW/etc/bash_completion.d/nvm"; do - if [[ -f "$nvm_completion" ]]; then - # Load bashcompinit - autoload -U +X bashcompinit && bashcompinit - # Bypass compinit call in nvm bash completion script. See: - # https://github.com/nvm-sh/nvm/blob/4436638/bash_completion#L86-L93 - ZSH_VERSION= source "$nvm_completion" - break - fi -done - -unset NVM_HOMEBREW nvm_completion diff --git a/plugins/otp/README.md b/plugins/otp/README.md index 8331fd02b..52ad9525b 100644 --- a/plugins/otp/README.md +++ b/plugins/otp/README.md @@ -16,7 +16,7 @@ Provided aliases: email address). Then the OTP key needs to be pasted, followed by a CTRL+D character inserted on an empty line. -- `ot`: generates a MFA code based on the given key and copies it to the clipboard +- `ot`: generates a MFA code based on the given key and copies it to the clipboard (on Linux it relies on xsel, on MacOS X it uses pbcopy instead). The plugin uses `$HOME/.otp` to store its internal files. diff --git a/plugins/per-directory-history/README.md b/plugins/per-directory-history/README.md index 69854aa38..11150b059 100644 --- a/plugins/per-directory-history/README.md +++ b/plugins/per-directory-history/README.md @@ -34,6 +34,8 @@ toggle set the `PER_DIRECTORY_HISTORY_TOGGLE` environment variable. and global histories. * `PER_DIRECTORY_HISTORY_TOGGLE` is the key binding used to run the toggle-history function above (default `^G`) +* `PER_DIRECTORY_HISTORY_PRINT_MODE_CHANGE` is a variable which toggles whether + the current mode is printed to the screen following a mode change (default `true`) ## History diff --git a/plugins/per-directory-history/per-directory-history.zsh b/plugins/per-directory-history/per-directory-history.zsh index 7cd673cdb..926373ae0 100644 --- a/plugins/per-directory-history/per-directory-history.zsh +++ b/plugins/per-directory-history/per-directory-history.zsh @@ -21,7 +21,7 @@ #------------------------------------------------------------------------------- # # The idea/inspiration for a per directory history is from Stewart MacArthur[1] -# and Dieter[2], the implementation idea is from Bart Schaefer on the the zsh +# and Dieter[2], the implementation idea is from Bart Schaefer on the zsh # mailing list[3]. The implementation is by Jim Hester in September 2012. # # [1]: http://www.compbiome.com/2010/07/bash-per-directory-bash-history.html @@ -59,6 +59,7 @@ [[ -z $HISTORY_BASE ]] && HISTORY_BASE="$HOME/.directory_history" [[ -z $HISTORY_START_WITH_GLOBAL ]] && HISTORY_START_WITH_GLOBAL=false [[ -z $PER_DIRECTORY_HISTORY_TOGGLE ]] && PER_DIRECTORY_HISTORY_TOGGLE='^G' +[[ -z $PER_DIRECTORY_HISTORY_PRINT_MODE_CHANGE ]] && PER_DIRECTORY_HISTORY_PRINT_MODE_CHANGE=true #------------------------------------------------------------------------------- # toggle global/directory history used for searching - ctrl-G by default @@ -68,19 +69,22 @@ function per-directory-history-toggle-history() { if [[ $_per_directory_history_is_global == true ]]; then _per-directory-history-set-directory-history _per_directory_history_is_global=false - print -n "\nusing local history" + if [[ $PER_DIRECTORY_HISTORY_PRINT_MODE_CHANGE == true ]]; then + zle -M "using local history" + fi else _per-directory-history-set-global-history _per_directory_history_is_global=true - print -n "\nusing global history" + if [[ $PER_DIRECTORY_HISTORY_PRINT_MODE_CHANGE == true ]]; then + zle -M "using global history" + fi fi - zle .push-line - zle .accept-line } autoload per-directory-history-toggle-history zle -N per-directory-history-toggle-history bindkey $PER_DIRECTORY_HISTORY_TOGGLE per-directory-history-toggle-history +bindkey -M vicmd $PER_DIRECTORY_HISTORY_TOGGLE per-directory-history-toggle-history #------------------------------------------------------------------------------- # implementation details diff --git a/plugins/pipenv/README.md b/plugins/pipenv/README.md index 4329feb32..e78ef0e3b 100644 --- a/plugins/pipenv/README.md +++ b/plugins/pipenv/README.md @@ -1,6 +1,7 @@ # Pipenv ## Installation + In your `.zshrc` file, add `pipenv` to the plugins section ``` @@ -8,7 +9,9 @@ plugins=(... pipenv ...) ``` ## Features -This plugin provides some features to simplify the use of Pipenv while working on ZSH. + +This plugin provides some features to simplify the use of Pipenv while working on ZSH. + - Adds completion for pipenv - Auto activates and deactivates pipenv shell - Adds short aliases for common pipenv commands @@ -27,3 +30,13 @@ This plugin provides some features to simplify the use of Pipenv while working o - `pwh` is aliased to `pipenv --where` - `pvenv` is aliased to `pipenv --venv` - `ppy` is aliased to `pipenv --py` + +## Configuration + +### Shell activation + +If you want to disable the shell activation and deactivation feature, add the following style to your `.zshrc` before sourcing `oh-my-zsh.sh`: + +```zsh +zstyle ':omz:plugins:pipenv' auto-shell no +``` diff --git a/plugins/pipenv/pipenv.plugin.zsh b/plugins/pipenv/pipenv.plugin.zsh index 22d1a3131..f81c266a4 100644 --- a/plugins/pipenv/pipenv.plugin.zsh +++ b/plugins/pipenv/pipenv.plugin.zsh @@ -12,28 +12,30 @@ fi _PIPENV_COMPLETE=zsh_source pipenv >| "$ZSH_CACHE_DIR/completions/_pipenv" &| -# Automatic pipenv shell activation/deactivation -_togglePipenvShell() { - # deactivate shell if Pipfile doesn't exist and not in a subdir - if [[ ! -f "$PWD/Pipfile" ]]; then - if [[ "$PIPENV_ACTIVE" == 1 ]]; then - if [[ "$PWD" != "$pipfile_dir"* ]]; then - exit +if zstyle -T ':omz:plugins:pipenv' auto-shell; then + # Automatic pipenv shell activation/deactivation + _togglePipenvShell() { + # deactivate shell if Pipfile doesn't exist and not in a subdir + if [[ ! -f "$PWD/Pipfile" ]]; then + if [[ "$PIPENV_ACTIVE" == 1 ]]; then + if [[ "$PWD" != "$pipfile_dir"* ]]; then + exit + fi fi fi - fi - # activate the shell if Pipfile exists - if [[ "$PIPENV_ACTIVE" != 1 ]]; then - if [[ -f "$PWD/Pipfile" ]]; then - export pipfile_dir="$PWD" - pipenv shell + # activate the shell if Pipfile exists + if [[ "$PIPENV_ACTIVE" != 1 ]]; then + if [[ -f "$PWD/Pipfile" ]]; then + export pipfile_dir="$PWD" + pipenv shell + fi fi - fi -} -autoload -U add-zsh-hook -add-zsh-hook chpwd _togglePipenvShell -_togglePipenvShell + } + autoload -U add-zsh-hook + add-zsh-hook chpwd _togglePipenvShell + _togglePipenvShell +fi # Aliases alias pch="pipenv check" diff --git a/plugins/pm2/_pm2 b/plugins/pm2/_pm2 index faa6a3404..66320b810 100644 --- a/plugins/pm2/_pm2 +++ b/plugins/pm2/_pm2 @@ -79,7 +79,7 @@ _id_names() { local app_list app_list=`pm2 list -m` - local -a names ids + local -a names ids names=(`echo $app_list | grep '+---' | awk '{print $2}'`) ids=(`echo $app_list | grep 'pm2 id' | awk '{print $4}'`) diff --git a/plugins/podman/README.md b/plugins/podman/README.md new file mode 100644 index 000000000..99daa28cd --- /dev/null +++ b/plugins/podman/README.md @@ -0,0 +1,47 @@ +# Podman plugin + +This plugin adds auto-completion and aliases for [podman](https://podman.io/). + +To use it add `podman` to the plugins array in your zshrc file. + +```zsh +plugins=(... podman) +``` + +## Aliases + +| Alias | Command | Description | +| :------ | :-------------------------------------------- | :--------------------------------------------------------------------------------------- | +| pbl | `podman build` | Build an image from a Dockerfile | +| pcin | `podman container inspect` | Display detailed information on one or more containers | +| pcls | `podman container ls` | List all the running podman containers | +| pclsa | `podman container ls --all` | List all running and stopped containers | +| pib | `podman image build` | Build an image from a Dockerfile (same as podman build) | +| pii | `podman image inspect` | Display detailed information on one or more images | +| pils | `podman image ls` | List podman images | +| pipu | `podman image push` | Push an image or repository to a remote registry | +| pirm | `podman image rm` | Remove one or more images | +| pit | `podman image tag` | Add a name and tag to a particular image | +| plo | `podman container logs` | Fetch the logs of a podman container | +| pnc | `podman network create` | Create a new network | +| pncn | `podman network connect` | Connect a container to a network | +| pndcn | `podman network disconnect` | Disconnect a container from a network | +| pni | `podman network inspect` | Return information about one or more networks | +| pnls | `podman network ls` | List all networks the engine daemon knows about, including those spanning multiple hosts | +| pnrm | `podman network rm` | Remove one or more networks | +| ppo | `podman container port` | List port mappings or a specific mapping for the container | +| ppu | `podman pull` | Pull an image or a repository from a registry | +| pr | `podman container run` | Create a new container and start it using the specified command | +| prit | `podman container run --interactive --tty` | Create a new container and start it in an interactive shell | +| prm | `podman container rm` | Remove the specified container(s) | +| prm! | `podman container rm --force` | Force the removal of a running container (uses SIGKILL) | +| pst | `podman container start` | Start one or more stopped containers | +| prs | `podman container restart` | Restart one or more containers | +| psta | `podman stop $(podman ps -q)` | Stop all running containers | +| pstp | `podman container stop` | Stop one or more running containers | +| ptop | `podman top` | Display the running processes of a container | +| pvi | `podman volume inspect` | Display detailed information about one or more volumes | +| pvls | `podman volume ls` | List all the volumes known to podman | +| pvprune | `podman volume prune` | Cleanup dangling volumes | +| pxc | `podman container exec` | Run a new command in a running container | +| pxcit | `podman container exec --interactive --tty` | Run a new command in a running container in an interactive shell | diff --git a/plugins/podman/podman.plugin.zsh b/plugins/podman/podman.plugin.zsh new file mode 100644 index 000000000..97cf92b2a --- /dev/null +++ b/plugins/podman/podman.plugin.zsh @@ -0,0 +1,47 @@ +if (( ! $+commands[podman] )); then + return +fi + +# If the completion file doesn't exist yet, we need to autoload it and +# bind it to `podman`. Otherwise, compinit will have already done that. +if [[ ! -f "$ZSH_CACHE_DIR/completions/_podman" ]]; then + typeset -g -A _comps + autoload -Uz _podman + _comps[podman]=_podman +fi + +podman completion zsh 2> /dev/null >| "$ZSH_CACHE_DIR/completions/_podman" &| + +alias pbl='podman build' +alias pcin='podman container inspect' +alias pcls='podman container ls' +alias pclsa='podman container ls --all' +alias pib='podman image build' +alias pii='podman image inspect' +alias pils='podman image ls' +alias pipu='podman image push' +alias pirm='podman image rm' +alias pit='podman image tag' +alias plo='podman container logs' +alias pnc='podman network create' +alias pncn='podman network connect' +alias pndcn='podman network disconnect' +alias pni='podman network inspect' +alias pnls='podman network ls' +alias pnrm='podman network rm' +alias ppo='podman container port' +alias ppu='podman pull' +alias pr='podman container run' +alias prit='podman container run --interactive --tty' +alias prm='podman container rm' +alias 'prm!'='podman container rm --force' +alias pst='podman container start' +alias prs='podman container restart' +alias psta='podman stop $(podman ps --quiet)' +alias pstp='podman container stop' +alias ptop='podman top' +alias pvi='podman volume inspect' +alias pvls='podman volume ls' +alias pvprune='podman volume prune' +alias pxc='podman container exec' +alias pxcit='podman container exec --interactive --tty' diff --git a/plugins/poetry-env/README.md b/plugins/poetry-env/README.md new file mode 100644 index 000000000..bd99d2a91 --- /dev/null +++ b/plugins/poetry-env/README.md @@ -0,0 +1,10 @@ +# Poetry Environment Plugin + +This plugin automatically changes poetry environment when you cd into or out of the project directory. +Note: Script looks for pyproject.toml file to determine poetry if its a poetry environment + +To use it, add `poetry-env` to the plugins array in your zshrc file: + +```zsh +plugins=(... poetry-env) +``` diff --git a/plugins/poetry-env/poetry-env.plugin.zsh b/plugins/poetry-env/poetry-env.plugin.zsh new file mode 100644 index 000000000..be46717d8 --- /dev/null +++ b/plugins/poetry-env/poetry-env.plugin.zsh @@ -0,0 +1,27 @@ +_togglePoetryShell() { + # Determine if currently in a Poetry-managed directory + local in_poetry_dir=0 + if [[ -f "$PWD/pyproject.toml" ]] && grep -q 'tool.poetry' "$PWD/pyproject.toml"; then + in_poetry_dir=1 + fi + + # Deactivate the current environment if moving out of a Poetry directory or into a different Poetry directory + if [[ $poetry_active -eq 1 ]] && { [[ $in_poetry_dir -eq 0 ]] && [[ "$PWD" != "$poetry_dir"* ]]; }; then + export poetry_active=0 + unset poetry_dir + deactivate + fi + + # Activate the environment if in a Poetry directory and no environment is currently active + if [[ $in_poetry_dir -eq 1 ]] && [[ $poetry_active -ne 1 ]]; then + venv_dir=$(poetry env info --path 2>/dev/null) + if [[ -n "$venv_dir" ]]; then + export poetry_active=1 + export poetry_dir="$PWD" + source "${venv_dir}/bin/activate" + fi + fi +} +autoload -U add-zsh-hook +add-zsh-hook chpwd _togglePoetryShell +_togglePoetryShell # Initial call to check the current directory at shell startup diff --git a/plugins/postgres/README.md b/plugins/postgres/README.md index 59445f31c..3f59a8fe4 100644 --- a/plugins/postgres/README.md +++ b/plugins/postgres/README.md @@ -19,4 +19,4 @@ plugins=(... postgres) | stoppost | `pg_ctl -D /usr/local/var/postgres stop -s -m fast` | Stop postgres server | | restartpost | `stoppost && sleep 1 && startpost` | Restart (calls stop, then start) | | reloadpost | `pg_ctl reload -D /usr/local/var/postgres -s` | Reload postgres configuration (some setting require restart)| -| statuspost | `pg_ctl status -D /usr/local/var/postgres -s` | Check startus of postgres server (running, stopped) | +| statuspost | `pg_ctl status -D /usr/local/var/postgres -s` | Check status of postgres server (running, stopped) | diff --git a/plugins/pyenv/README.md b/plugins/pyenv/README.md index f1ca3d288..f18fc8cfb 100644 --- a/plugins/pyenv/README.md +++ b/plugins/pyenv/README.md @@ -10,7 +10,7 @@ To use it, add `pyenv` to the plugins array in your zshrc file: plugins=(... pyenv) ``` -If you receive a `Found pyenv, but it is badly configured.` error on startup, you may need to ensure that `pyenv` is initialized before the oh-my-zsh pyenv plugin is loaded. This can be achived by adding the following earlier in the `.zshrc` file than the `plugins=(...)` line: +If you receive a `Found pyenv, but it is badly configured.` error on startup, you may need to ensure that `pyenv` is initialized before the oh-my-zsh pyenv plugin is loaded. This can be achieved by adding the following earlier in the `.zshrc` file than the `plugins=(...)` line: ```zsh export PYENV_ROOT="$HOME/.pyenv" diff --git a/plugins/python/README.md b/plugins/python/README.md index 97c1a34ee..b990a26b9 100644 --- a/plugins/python/README.md +++ b/plugins/python/README.md @@ -12,7 +12,7 @@ plugins=(... python) | Command | Description | | ---------------- | -------------------------------------------------------------------------------------- | -| `py` | Runs `python3` | +| `py` | Runs `python3`. Only set if `py` is not installed. | | `ipython` | Runs the appropriate `ipython` version according to the activated virtualenv | | `pyfind` | Finds .py files recursively in the current directory | | `pyclean [dirs]` | Deletes byte-code and cache files from a list of directories or the current one | @@ -22,8 +22,19 @@ plugins=(... python) ## Virtual environments -The plugin provides two utilities to manage Python venvs: +The plugin provides three utilities to manage Python 3.3+ [venv](https://docs.python.org/3/library/venv.html) +virtual environments: -- `mkv [name]`: make a new virtual environment called `name` (default: `venv`) in current directory. +- `mkv [name]`: make a new virtual environment called `name` (default: if set `$PYTHON_VENV_NAME`, else + `venv`) in the current directory. -- `vrun [name]`: activate virtual environment called `name` (default: `venv`) in current directory. +- `vrun [name]`: Activate the virtual environment called `name` (default: if set `$PYTHON_VENV_NAME`, else + `venv`) in the current directory. + +- `auto_vrun`: Automatically activate the venv virtual environment when entering a directory containing + `/bin/activate`, and automatically deactivate it when navigating out of it (keeps venv activated + in subdirectories). + - To enable the feature, set `export PYTHON_AUTO_VRUN=true` before sourcing oh-my-zsh. + - Plugin activates first virtual environment in lexicographic order whose name begins with ``. + The default virtual environment name is `venv`. To use a different name, set + `export PYTHON_VENV_NAME=`. For example: `export PYTHON_VENV_NAME=".venv"` diff --git a/plugins/python/python.plugin.zsh b/plugins/python/python.plugin.zsh index 2fbb59577..7256aa04f 100644 --- a/plugins/python/python.plugin.zsh +++ b/plugins/python/python.plugin.zsh @@ -1,5 +1,5 @@ -# python command -alias py='python3' +# set python command if 'py' not installed +builtin which py > /dev/null || alias py='python3' # Find python file alias pyfind='find . -name "*.py"' @@ -44,18 +44,19 @@ function pyuserpaths() { alias pygrep='grep -nr --include="*.py"' # Run proper IPython regarding current virtualenv (if any) -alias ipython="python3 -c 'import IPython; IPython.terminal.ipapp.launch_new_instance()'" +alias ipython='python3 -c "import IPython, sys; sys.exit(IPython.start_ipython())"' # Share local directory as a HTTP server alias pyserver="python3 -m http.server" ## venv utilities +: ${PYTHON_VENV_NAME:=venv} # Activate a the python virtual environment specified. -# If none specified, use 'venv'. +# If none specified, use $PYTHON_VENV_NAME, else 'venv'. function vrun() { - local name="${1:-venv}" + local name="${1:-$PYTHON_VENV_NAME}" local venvpath="${name:P}" if [[ ! -d "$venvpath" ]]; then @@ -72,12 +73,35 @@ function vrun() { echo "Activated virtual environment ${name}" } -# Create a new virtual environment, with default name 'venv'. +# Create a new virtual environment using the specified name. +# If none specfied, use $PYTHON_VENV_NAME function mkv() { - local name="${1:-venv}" + local name="${1:-$PYTHON_VENV_NAME}" local venvpath="${name:P}" python3 -m venv "${name}" || return echo >&2 "Created venv in '${venvpath}'" vrun "${name}" } + +if [[ "$PYTHON_AUTO_VRUN" == "true" ]]; then + # Automatically activate venv when changing dir + function auto_vrun() { + # deactivate if we're on a different dir than VIRTUAL_ENV states + # we don't deactivate subdirectories! + if (( $+functions[deactivate] )) && [[ $PWD != ${VIRTUAL_ENV:h}* ]]; then + deactivate > /dev/null 2>&1 + fi + + if [[ $PWD != ${VIRTUAL_ENV:h} ]]; then + for _file in "${PYTHON_VENV_NAME}"*/bin/activate(N.); do + # make sure we're not in a venv already + (( $+functions[deactivate] )) && deactivate > /dev/null 2>&1 + source $_file > /dev/null 2>&1 + break + done + fi + } + add-zsh-hook chpwd auto_vrun + auto_vrun +fi diff --git a/plugins/qodana/README.md b/plugins/qodana/README.md new file mode 100644 index 000000000..0b68bdecf --- /dev/null +++ b/plugins/qodana/README.md @@ -0,0 +1,20 @@ +# JetBrains Qodana CLI plugin + +This plugin adds completion for the [JetBrains Qodana CLI](https://github.com/JetBrains/qodana-cli). + +To use it, add `qodana` to the plugins array in your zshrc file: + +```zsh +plugins=(... qodana) +``` + +This plugin does not add any aliases. + +## Cache + +This plugin caches the completion script and is automatically updated when the +plugin is loaded, which is usually when you start up a new terminal emulator. + +The cache is stored at: + +- `$ZSH_CACHE_DIR/completions/_qodana` completions script diff --git a/plugins/qodana/qodana.plugin.zsh b/plugins/qodana/qodana.plugin.zsh new file mode 100644 index 000000000..2b92a8051 --- /dev/null +++ b/plugins/qodana/qodana.plugin.zsh @@ -0,0 +1,14 @@ +# Autocompletion for the JetBrains Qodana CLI (qodana). +if (( ! $+commands[qodana] )); then + return +fi + +# If the completion file doesn't exist yet, we need to autoload it and +# bind it to `qodana`. Otherwise, compinit will have already done that. +if [[ ! -f "$ZSH_CACHE_DIR/completions/_qodana" ]]; then + typeset -g -A _comps + autoload -Uz _qodana + _comps[qodana]=_qodana +fi + +qodana completion zsh >| "$ZSH_CACHE_DIR/completions/_qodana" &| diff --git a/plugins/rails/_rails b/plugins/rails/_rails index ac90d45cc..48fd1909e 100644 --- a/plugins/rails/_rails +++ b/plugins/rails/_rails @@ -1,6 +1,6 @@ #compdef rails # ------------------------------------------------------------------------------ -# Copyright (c) 2016 GitHub zsh-users - http://github.com/zsh-users +# Copyright (c) 2016 GitHub zsh-users - https://github.com/zsh-users # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -28,136 +28,494 @@ # Description # ----------- # -# Completion script for Ruby on Rails (http://rubyonrails.org/). +# Completion script for Ruby on Rails 7.1.0 (https://rubyonrails.org/). # # ------------------------------------------------------------------------------ # Authors # ------- # # * Kazuya Takeshima (https://github.com/mitukiii) +# * Shohei Yoshida (https://github.com/syohex) # # ------------------------------------------------------------------------------ - _rails() { - local context state line curcontext="$curcontext" + local context state state_descr line curcontext="$curcontext" + typeset -A opt_args - if (( CURRENT > 2 )); then - (( CURRENT-- )) - shift words - _call_function - "_rails_${words[1]}" || _nothing - else - __rails_commands - fi -} - -__rails_commands() { - local context state line curcontext="$curcontext" - - local -a rails_options - __rails_setup_rails_options - - _arguments -C \ - $rails_options \ - ': :->command' - - case "$state" in - command) - local -a commands - local application_directory - __rails_setup_application_directory - - if [ -n "$application_directory" ]; then - commands=( - {generate,g}'[Generate new code]' - {console,c}'[Start the Rails console]' - {server,s}'[Start the Rails server]' - {dbconsole,db}'[Start a console for the database specified in config/database.yml]' - application'[Generate the Rails application code]' - {destroy,d}'[Undo code generated with "generate"]' - benchmarker'[See how fast a piece of code runs]' - profiler'[Get profile information from a piece of code]' - plugin'[Install a plugin]' - {runner,r}'[Run a piece of code in the application environment]' - {test,t}'[Run tests]' - ) - else - commands=( - new'[Create a new Rails application]' - ) - fi - - _values 'command' $commands - ;; - esac -} - -__rails_setup_application_directory() { - application_directory="$(pwd)" - - while [ -n "$application_directory" ]; do - if [ -f "${application_directory}/script/rails" -o -f "${application_directory}/bin/rails" ]; then - return - fi - application_directory="${application_directory%/*}" - done - - application_directory= -} - -__rails_setup_rails_options() { - rails_options=( - {-h,--help}'[Show this help message and quit]' - {-v,--version}'[Show Rails version number and quit]' + local -a runtime_options rails_options + runtime_options=( + '(- *)'{-h,--help}'[Show this help message and quit]' + '(- *)'{-v,--version}'[Show Rails version and quit]' ) -} -__rails_setup_runtime_options() { runtime_options=( '(-f --force)'{-f,--force}'[Overwrite files that already exist]' '(-p --pretend)'{-p,--pretend}'[Run but do not make any changes]' '(-q --quiet)'{-q,--quiet}'[Suppress status output]' '(-s --skip)'{-s,--skip}'[Skip files that already exist]' ) + + local ret=1 + + _arguments -C \ + $rails_options \ + '1: :_rails_subcommands' \ + '*:: :->command' && ret=0 + + case "$state" in + (command) + case $words[1] in + (new) + _rails_new && ret=0 + ;; + (generate|g|destroy|d) + _rails_generate && ret=0 + ;; + (console|c) + _arguments \ + '(- *)'{-h,--help}'[Show this help message and quit]' \ + '(-e --environment)'{-e,--environment=}'[The environment to run "console" in]:env:(test development production)' \ + '(-s --sandbox)'{-s,--sandbox}'[Rollback database modifications on exit]' \ + && ret=0 + ;; + (server|s) + _arguments \ + '(- *)'{-h,--help}'[Show this help message and quit]' \ + '(-e --environment)'{-e,--environment=}'[The environment to run "server" in]:env:(test development production)' \ + '(-p --port)'{-p,--port}'[Run Rails on the specified port]:port' \ + '(-b --binding)'{-b,--binding=}'[Bind Rails to the specified IP]:binding' \ + '(-c --config)'{-c,--config=}'[Use a custom rackup configuration]:config file:_files -g "*.ru"' \ + '(-d --daemon)'{-d,--daemon}'[Run server as a Daemon]' \ + '(-u --using)'{-u,--using=}'[Specify the Rack server used to run the application]:server:(thin puma webrick)' \ + '(-P --pid)'{-P,--pid=}'[Specify the PID file]:pid file:_files -g "*.pid"' \ + '(-C --dev-caching --no-dev-caching)'{-C,--dev-caching}'[Perform caching in development]' \ + '(-C --dev-caching --no-dev-caching)--no-dev-caching[Not perform caching in development]' \ + '--early-hints[Enable HTTP/2 early hints]' \ + '(--log-to-stdout --no-log-to-stdout)--log-to-stdout[Log to stdout]' \ + '(--log-to-stdout --no-log-to-stdout)--no-log-to-stdout[Not log to stdout]' \ + && ret=0 + ;; + (dbconsole|db) + _arguments \ + '(- *)'{-h,--help}'[Show this help message and quit]' \ + '(-e --environment)'{-e,--environment=}'[The environment to run "server" in]:env:(test development production)' \ + '(-p --include-password)'{-p,--include-password}'[Automatically provide the password from database.yml]' \ + '--mode=[Automatically put the sqlite3 database in the specified mode]:mode:(html list line column)' \ + '(--header --no-header)--header[Display header]' \ + '(--header --no-header)--no-header[Not display header]' \ + '(--db --database)'{--db=,--database=}'[Specify the database to use]:database:_files' \ + && ret=0 + ;; + (test|t|test:system) + _arguments \ + '(- *)'{-h,--help}'[Show this help message and quit]' \ + '--no-plugins[Bypass minitest plugin auto-loading]' \ + '(-s --seed)'{-s,--seed=}'[Sets random seed]:seed' \ + '(-v -verbose)'{-v,--verbose}'[Show progress processing files]' \ + '--show-skips[Show skipped at the end of run]' \ + \*{-n,--name=}'[Filter run on /regexp/ or string]:pattern' \ + *--exclude='[Exclude /regexp/ or string from run]:pattern' \ + \*{-S,--skip=}'[Skip reporting of certain types of results]' \ + '(-w --warnings)'{-w,--warnings}'[Run with Ruby warnings enabled]' \ + '(-e --environment)'{-e,--environment=}'[Run tests in the given environment]' \ + '(-b --backtrace)'{-b,--backtrace}'[Show the complete backtrace]' \ + '(-d --defer-output)'{-d,--defer-output}'[Output test failures and errors after the test run]' \ + '(-f --fail-fast)'{-f,--fail-fast}'[Abort test run on first failure or error]' \ + '(-c --color --no-color)'{-c,--color}'[Enable color in the output]' \ + '(-c --color --no-color)--no-color[Disable color in the output]' \ + '--profile=[Enable profiling of tests and list the slowest test cases]:count' \ + '(-p --pride)'{-p,--pride}'[Show your testing pride]' \ + '*:: :_files -g "*.rb"' \ + && ret=0 + ;; + (runner|r) + _arguments \ + '(- *)'{-h,--help}'[Show this help message and quit]' \ + '(-e --environment)'{-e,--environment=}'[The environment to run "runner"]:env:(test development production)' \ + '*:: :_files -g "*.rb"' \ + && ret=0 + ;; + (plugin) + _arguments \ + '1: :(new)' \ + '*:: :_rails_new' \ + && ret=0 + ;; + (routes) + _arguments \ + '(- *)'{-h,--help}'[Show this help message and quit]' \ + '(-c --controller)'{-c,--controller=}'[Filter by a specific controller]:controller' \ + '(-g --grep)'{-g,--grep}'[Grep routes by a specific pattern]' \ + '(-E --expanded)'{-E,--expanded}'[Print routes expanded vertically with parts explained]' \ + '(-u --unused)'{-u,--unused}'[Print unused routes]' \ + && ret=0 + ;; + (*) + _arguments \ + '(- *)'{-h,--help}'[Show help message and quit]' \ + '*:: :_files' \ + && ret=0 + ;; + esac + ;; + esac + + return ret } -__rails_setup_generators_options() { - local -a runtime_options - __rails_setup_runtime_options +(( $+functions[_rails_subcommands] )) || +_rails_subcommands() { + local -a commands - generators_options=( - $runtime_options - --skip-namespace'[Skip namespace (affects only isolated applications)]' - --old-style-hash"[Force using old style hash (:foo => 'bar') on Ruby >= 1.9]" + _rails_is_in_app + + if (( $? == 1 )); then + # is not in rails app directory + commands=( + new'[Create a new Rails application]' + ) + else + commands=( + {generate,g}'[Generate new code]' + {console,c}'[Start the Rails console]' + {server,s}'[Start the Rails server]' + {test,t}'[Run tests]' + "test\\:system[Run systems test only]" + {dbconsole,db}'[Start a console for the database specified in config/database.yml]' + plugin'[Install a plugin]' + + # generated by ./bin/rails --help | ruby -ne '(b=$2;printf("%s[%s]\n", $1.gsub(/:/,"\\:"),b.strip)) if /^([a-z0-9_:]+)\S*\s+([^(\n]+)/' + "about[List versions of all Rails frameworks and the environment]" + "action_mailbox\:ingress\:exim[Relay an inbound email from Exim to Action Mailbox]" + "action_mailbox\:ingress\:postfix[Relay an inbound email from Postfix to Action Mailbox]" + "action_mailbox\:ingress\:qmail[Relay an inbound email from Qmail to Action Mailbox]" + "action_mailbox\:install[Install Action Mailbox and its dependencies]" + "action_mailbox\:install\:migrations[Copy migrations from action_mailbox to application]" + "action_text\:install[Copy over the migration, stylesheet, and JavaScript files]" + "action_text\:install\:migrations[Copy migrations from action_text to application]" + "active_storage\:install[Copy over the migration needed to the application]" + "app\:template[Apply the template supplied by LOCATION=]" + "app\:update[Update configs and some other initially generated files]" + "assets\:clean[Remove old compiled assets]" + "assets\:clobber[Remove compiled assets]" + "assets\:environment[Load asset compile environment]" + "assets\:precompile[Compile all the assets named in config.assets.precompile]" + "cache_digests\:dependencies[Lookup first-level dependencies for TEMPLATE]" + "cache_digests\:nested_dependencies[Lookup nested dependencies for TEMPLATE]" + "credentials\:diff[Enroll/disenroll in decrypted diffs of credentials using git]" + "credentials\:edit[Open the decrypted credentials in $VISUAL or $EDITOR for editing]" + "credentials\:show[Show the decrypted credentials]" + "db\:create[Create the database from DATABASE_URL or config/database.yml for the current RAILS_ENV]" + "db\:drop[Drop the database from DATABASE_URL or config/database.yml for the current RAILS_ENV]" + "db\:encryption\:init[Generate a set of keys for configuring Active Record encryption in a given environment]" + "db\:environment\:set[Set the environment value for the database]" + "db\:fixtures\:load[Load fixtures into the current environment's database]" + "db\:migrate[Migrate the database]" + "db\:migrate\:down[Run the 'down' for a given migration VERSION]" + "db\:migrate\:redo[Roll back the database one migration and re-migrate up]" + "db\:migrate\:status[Display status of migrations]" + "db\:migrate\:up[Run the 'up' for a given migration VERSION]" + "db\:prepare[Run setup if database does not exist, or run migrations if it does]" + "db\:reset[Drop and recreate all databases from their schema for the current environment and load the seeds]" + "db\:rollback[Roll the schema back to the previous version]" + "db\:schema\:cache\:clear[Clear a db/schema_cache.yml file]" + "db\:schema\:cache\:dump[Create a db/schema_cache.yml file]" + "db\:schema\:dump[Create a database schema file]" + "db\:schema\:load[Load a database schema file]" + "db\:seed[Load the seed data from db/seeds.rb]" + "db\:seed\:replant[Truncate tables of each database for current environment and load the seeds]" + "db\:setup[Create all databases, load all schemas, and initialize with the seed data]" + "db\:system\:change[Change 'config/database.yml' and your database gem to the target database]" + "db\:version[Retrieve the current schema version number]" + "destroy[Remove code generated by 'bin/rails generate']" + "dev\:cache[Toggle development mode caching on/off]" + "encrypted\:edit[Open the decrypted file in $VISUAL or $EDITOR for editing]" + "encrypted\:show[Show the decrypted contents of the file]" + "importmap\:install[Setup Importmap for the app]" + "initializers[Print out all defined initializers in the order they are invoked by Rails.]" + "log\:clear[Truncate all/specified *.log files in log/ to zero bytes]" + "middleware[Print out your Rack middleware stack]" + "notes[Show comments in your code annotated with FIXME, OPTIMIZE, and TODO]" + "restart[Restart app by touching tmp/restart.txt]" + "routes[List all the defined routes]" + "runner[Run Ruby code in the context of your application]" + "secret[Generate a cryptographically secure secret key]" + "secrets\:edit[**deprecated** Open the secrets in $VISUAL or $EDITOR for editing]" + "secrets\:show[**deprecated** Show the decrypted secrets]" + "stats[Report code statistics]" + "stimulus\:install[Install Stimulus into the app]" + "stimulus\:install\:importmap[Install Stimulus on an app running importmap-rails]" + "stimulus\:install\:node[Install Stimulus on an app running node]" + "test\:all[Run all tests, including system tests]" + "test\:channels[Run tests in test/channels]" + "test\:controllers[Run tests in test/controllers]" + "test\:db[Reset the database and run 'bin/rails test']" + "test\:functionals[Run tests in test/controllers, test/mailers, and test/functional]" + "test\:generators[Run tests in test/lib/generators]" + "test\:helpers[Run tests in test/helpers]" + "test\:integration[Run tests in test/integration]" + "test\:jobs[Run tests in test/jobs]" + "test\:mailboxes[Run tests in test/mailboxes]" + "test\:mailers[Run tests in test/mailers]" + "test\:models[Run tests in test/models]" + "test\:units[Run tests in test/models, test/helpers, and test/unit]" + "time\:zones[List all time zones, list by two-letter country code]" + "tmp\:clear[Clear cache, socket and screenshot files from tmp/]" + "tmp\:create[Create tmp directories for cache, sockets, and pids]" + "turbo\:install[Install Turbo into the app]" + "turbo\:install\:importmap[Install Turbo into the app with asset pipeline]" + "turbo\:install\:node[Install Turbo into the app with webpacker]" + "turbo\:install\:redis[Switch on Redis and use it in development]" + "version[Show the Rails version]" + "yarn\:install[Install all JavaScript dependencies as specified via Yarn]" + "zeitwerk\:check[Check project structure for Zeitwerk compatibility]" + ) + fi + + _values 'command' $commands +} + +# rails new +(( $+functions[_rails_new] )) || +_rails_new() { + local ret=1 + + _arguments \ + $runtime_options \ + $rails_options \ + --skip-namespace'[Skip namespace]' \ + '(-n --name)'{-n,--name=}'[Name of the app]:name' \ + '(-r --ruby)'{-r,--ruby=}'[Path to the Ruby binary of your choice]:path:_files' \ + '(-b --builder)'{-b,--builder=}'[Path to a application builder(can be a filesystem path or URL)]: :_rails_path_or_url' \ + '(-m --template)'{-m,--template=}'[Path to an application template(can be a filesystem path or URL)]: :_rails_path_or_url' \ + '(-d --database)'{-d,--database=}'[Preconfigure for selected database]:database:(mysql trilogy oracle postgresql sqlite3 frontbase ibm_db sqlserver jdbcmysql jdbcsqlite3 jdbcpostgresql jdbc)' \ + --skip-gemfile"[Don't create a Gemfile]" \ + --skip-bundle"[Don't run bundle install]" \ + '(-G --skip-git)'{-G,--skip-git}'[Skip git init]' \ + --skip-docker'[Skip Dockerfile]' \ + --skip-keeps'[Skip source control .keep files]' \ + '(-M --skip-action-mailer)'{-M,--skip-action-mailer}'[Skip Action Mailer files]' \ + --skip-action-mailbox'[Skip Action Mailbox gem]' \ + --skip-action-text'[Skip Action Text gem]' \ + '(-O --skip-active-record)'{-O,--skip-active-record}'[Skip Active Record files]' \ + --skip-active-job'[Skip Active Job]' \ + --skip-active-storage'[Skip Active Storage files]' \ + '(-C --skip-action-cable)'{-C,--skip-action-cable}'[Skip Action Cable files]' \ + '(-A --skip-asset-pipeline)'{-A,--skip-asset-pipeline}'[Skip asset pipeline]' \ + '(-a --asset-pipeline)'{-a,--asset-pipeline=}'[Choose your asset pipeline]:asset pipeline:(sprockets propshaft)' \ + '(-J --skip-js)'{-J,--skip-js}'[Skip JavaScript files]' \ + --skip-hotwire'[Skip Hotwire integration]' \ + --skip-jbuilder'[Skip jbuilder gem]' \ + '(-T --skip-test)'{-T,--skip-test}'[Skip test files]' \ + --skip-system-test'[Skip system test files]' \ + --skip-bootsnap'[Skip bootsnap gem]' \ + --skip-dev-gems'[Skip development gems(e.g. web-console)]' \ + --dev'[Setup the application with Gemfile pointing to your Rails checkout]' \ + --edge'[Setup the application with Gemfile pointing to Rails repository]' \ + --master'[Set up the application with Gemfile pointing to Rails repository main branch]' \ + --rc='[Path to file containing extra configuration options for rails command]:rc:_files' \ + --api'[Preconfigure smaller stack for API only apps]' \ + --minimal'[Preconfigure a minimal rails app]' \ + '(-j --js)'{-j,--js=}'[Choose JavaScript approach]:javascript:(importmap bun webpack esbuild rollup)' \ + '(-c --css)'{-c,--css=}'[Choose CSS processor]:css processor:(tailwind bootstrap bulma postcss sass)' \ + '(-B --skip-bundle)'{-B,--skip-bundle}"[Don't run bundle install]" \ + --skip-decrypted-diffs"[Don't configure git to show decrypted diffs of encrypted credentials]" \ + ':app path:_directories' && ret=0 + + return ret +} + +# rails generate +(( $+functions[_rails_generate] )) || +_rails_generate() { + local ret=1 + + _arguments -C \ + '(- *)'{-h,--help}"[Print generator's options and usage]" \ + $runtime_options \ + '1:generator:_rails_generate_generator' \ + '*:: :->generate' && ret=0 + + case "$state" in + (generate) + local -a opts + opts=( + '(- *)'{-h,--help}'[Show this help message and quit]' + $runtime_options + '--skip-namespace[Skip namespace]' + '--skip-collision-check[Skip collision check]' + ) + + case $words[1] in + (application_record|migration|model|resource|scaffold|scaffold_controller) + opts+=( + '(-o --orm)'{-o,--orm=}'[ORM to be invoked]:orm:(active_record)' + ) + ;| + (channel) + opts+=( + '--no-assets[Not generate assets]' + ) + ;| + (controller|resource|scaffold|scaffold_controller) + opts+=( + '--skip-routes[Do not add routes to config/routes.rb]' + '--no-helper[Not generate helper]' + ) + ;| + (controller|job|model|resource|scaffold) + opts+=( + '--parent=[The parent class for the generated controler]:parent class' + ) + ;| + (controler|mailer|resource|scaffold|scaffold_controller) + opts+=( + '(-e --template-engine)'{-e,--template-engine=}'[Template engine to be invoked]:engine:(erb)' + ) + ;| + (channel|controller|generator|helper|job|mailbox|mailer|model|scaffold|scaffold_controller) + opts+=( + '(-t --test-framework)'{-t,--test-framework=}'[Test framework to be invoked]:test_framework:(test_unit)' + ) + ;| + (generator|test_unit:channel) + opts+=( + '--no-namespace[Not generate namespace generate]' + ) + ;| + (integration_test) + opts+=( + '--integration-tool=[Integration tool to be invoked]:tool:(test_unit)' + ) + ;| + (jbuilder|resource|scaffold|scaffold_controller) + opts+=( + '--model-name=[ModelName to be used]:name' + ) + ;| + (jbuilder|model|resource|scaffold|scaffold_controller) + opts+=( + '--force-plural[Do not singularize the model name]' + ) + ;| + (jbuilder|migration|model|resource|scaffold_controller) + opts+=( + '--no-timestamps[Not generate timestamps]' + ) + ;| + (job) + opts+=( + '--queue=[The queue name for the generated job]:name' + ) + ;| + (migration|model|resource|scaffold) + opts+=( + '--primary-key-type=[The type for primary key]' + '(--db --database)'{--db,--database=}'[The database for your migration]:db' + ) + ;| + (model|resource|scaffold) + opts+=( + '--no-migration[Not generate migration]' + '--no-indexes[Not add indexes for references and belongs_to columns]' + '--no-fixture[Not generate fixture]' + '(-r --fixture-replacement)'{-r,--fixture-replacement=}'[Fixture replacement to be invoked]:fixture' + ) + ;| + (resource) + opts+=( + '(-c --resource-controller)'{-c,--resource-controller=}'[Resource controller to be invoked]:controller:(controller)' + '(-a --actions)'{-a,--actions=}'[Actions for the source controller]:action' + ) + ;| + (resource|scaffold|scaffold_controller) + opts+=( + '--no-resource-route[Not generate resource route]' + ) + ;| + (scaffold) + opts+=( + '(-c --scaffold-controller)'{-c,--scaffold-controller=}'[Scaffold controller to be invoked]:controller:(scaffold_controller)' + + ) + ;| + (scaffold|scaffold_controller) + opts+=( + '--api[Generate API-only controller and tests, with no view templates]' + '--no-jbuilder[Not generate jbuilder]' + ) + ;| + (scaffold|scaffold_controller|system_test) + opts+=( + '--system-tests=[System test framework to be invoked]:framework:(test_unit)' + ) + ;| + (stimulus) + opts+=( + '--skip-manifest[Do not update the stimulus manifest]' + ) + ;| + (jbuilder|migration|resource|scaffold) + opts+=( + '*:field:_rails_migration_fields' + ) + ;| + esac + + _arguments $opts && ret=0 + ;; + esac + + return ret +} + +(( $+functions[_rails_generate_generator] )) || +_rails_generate_generator() { + local -a generators=( + # rails + application_record benchmark channel controller generator helper integration_test + jbuilder job mailbox mailer migration model resource scaffold scaffold_controller + system_test task + + # active record + "active_record\\:application_record" + "active_record\\:multi_db" + + # Stimulus + stimulus + + # TestUnit + "test_unit\\:channel" "test_unit\\:generator" "test_unit\\:install" + "test_unit\\:mailbox" "test_unit\\:plugin" ) + + _values 'generators' $generators } -__rails_setup_model_generators_options() { - local -a generators_options - __rails_setup_generators_options +# Utilities +(( $+functions[_rails_is_in_app] )) || +_rails_is_in_app() { + local dir="$PWD" + while [ -n "$dir" ]; do + if [[ -f "${dir}/bin/rails" ]]; then + return 0 + fi + dir="${dir/*}" + done - model_generators_options=( - $generators_options - '(-o --orm)'{-o,--orm=}'[Orm to be invoked]:orm' - ) + return 1 } -__rails_setup_resource_generators_options() { - local -a model_generators_options - __rails_setup_model_generators_options - - resource_generators_options=( - $model_generators_options - --force-plural'[Forces the use of a plural ModelName]' - --resource-route'[Indicates when to generate resource route]: :__rails_boolean' - ) +(( $+functions[_rails_path_or_url] )) || +_rails_path_or_url() { + _alternative \ + 'files:path:_files -g "*.rb"' \ + 'url:url:_urls' } -__rails_boolean() { - _values 'boolean' 'true' 'false' -} - -__rails_migration_fields() { +(( $+functions[_rails_migration_fields] )) || +_rails_migration_fields() { if compset -P '*:*:'; then _values 'index' 'index' 'uniq' else @@ -169,450 +527,6 @@ __rails_migration_fields() { fi } -_rails_generate() { - local context state line curcontext="$curcontext" - - if (( CURRENT > 2 )); then - (( CURRENT-- )) - shift words - _call_function - "_rails_generate_${words[1]}" || _rails_generate_default - else - __rails_generate_commands - fi -} - -_rails_g() { - _rails_generate -} - -__rails_generate_commands() { - local context curcontext="$curcontext" update_policy - - zstyle -s ":completion:${curcontext}:" cache-policy update_policy - if [ -z "$update_policy" ]; then - zstyle ":completion:${curcontext}:" cache-policy _rails_generate_commands_caching_policy - fi - - local application_directory - __rails_setup_application_directory - local cache_name - cache_name="rails/${application_directory##*/}/all_generators" - if ! _retrieve_cache ${cache_name}; then - local -a all_generators - all_generators=($(_call_program rails_generators rails generate 2> /dev/null | awk '/^ [a-zA-Z_]+/{ print $1 }')) - _store_cache ${cache_name} all_generators - fi - - local -a rails_generators - rails_generators=(${all_generators:#*:*}) - _describe -t rails_generators 'rails generator' rails_generators - - local -a -U namespaces - local namespace - local -a generators - namespaces=(${(R)${(M)all_generators:#*:*}%:*}) - for namespace in $namespaces; do - generators=(${${(M)all_generators:#${namespace}:*}/:/\\:}) - _describe -t ${namespace}_generators "${namespace/_/ } generator" generators - done -} - -_rails_generate_commands_caching_policy() { - local application_directory - __rails_setup_application_directory - - if [ "${application_directory}/Gemfile" -nt "$1" ]; then - return 0 - fi - - local -a oldp - oldp=( "$1"(Nmw+1) ) - (( $#oldp )) -} - -_rails_generate_default() { - local -a generators_options - __rails_setup_generators_options - - _arguments \ - $generators_options \ - '*:argument' -} - -_rails_generate_assets() { - local -a generators_options - __rails_setup_generators_options - - _arguments \ - $generators_options \ - '(-j --javascripts)'{-j,--javascripts}'[Generate JavaScripts]: :__rails_boolean' \ - '(-y --stylesheets)'{-y,--stylesheets}'[Generate Stylesheets]: :__rails_boolean' \ - '(-je --javascript-engine)'{-je,--javascript-engine=}'[Engine for JavaScripts]:javascript engine' \ - '(-se --stylesheet-engine)'{-se,--stylesheet-engine=}'[Engine for Stylesheets]:stylesheet engine' \ - ': :_guard "^-*" "name"' -} - -_rails_generate_controller() { - local -a generators_options - __rails_setup_generators_options - - _arguments \ - $generators_options \ - '(-e --template-engine)'{-e,--template-engine=}'[Template engine to be invoked]:template engine' \ - '(-t --test-framework)'{-t,--test-framework=}'[Test framework to be invoked]:test framework' \ - --helper'[Indicates when to generate helper]: :__rails_boolean' \ - --assets'[Indicates when to generate assets]: :__rails_boolean' \ - ': :_guard "^-*" "name"' \ - '*: :_guard "^-*" "action"' -} - -_rails_generate_generator() { - local -a generators_options - __rails_setup_generators_options - - _arguments \ - $generators_options \ - --namespace'[Namespace generator under lib/generators/name]: :__rails_boolean' \ - ': :_guard "^-*" "name"' -} - -_rails_generate_helper() { - local -a generators_options - __rails_setup_generators_options - - _arguments \ - $generators_options \ - '(-t --test-framework)'{-t,--test-framework=}'[Test framework to be invoked]:test framework' \ - ': :_guard "^-*" "name"' \ -} - -_rails_generate_integration_test() { - local -a generators_options - __rails_setup_generators_options - - _arguments \ - $generators_options \ - --integration-tool='[Integration tool to be invoke]:integration tool' \ - ': :_guard "^-*" "name"' \ -} - -_rails_generate_jbuilder() { - local -a generators_options - __rails_setup_generators_options - - _arguments \ - $generators_options \ - ': :_guard "^-*" "name"' \ - '*: :__rails_migration_fields' -} - -_rails_generate_mailer() { - local -a generators_options - __rails_setup_generators_options - - _arguments \ - $generators_options \ - '(-e --template-engine)'{-e,--template-engine=}'[Template engine to be invoked]:template engine' \ - '(-t --test-framework)'{-t,--test-framework=}'[Test framework to be invoked]:test framework' \ - ': :_guard "^-*" "name"' \ - '*: :_guard "^-*" "method"' -} - -_rails_generate_migration() { - local -a modelgenerators_options - __rails_setup_model_generators_options - - _arguments \ - $model_generators_options \ - ': :_guard "^-*" "name"' \ - '*: :__rails_migration_fields' -} - -_rails_generate_model() { - _rails_generate_migration -} - -_rails_generate_observer() { - local -a model_generators_options - __rails_setup_model_generators_options - - _arguments \ - $model_generators_options \ - ': :_guard "^-*" "name"' -} - -_rails_generate_performance_test() { - local -a generators_options - __rails_setup_generators_options - - _arguments \ - $generators_options \ - --performance-tool='[Performance tool to be invoked]:performance tool' \ - ': :_guard "^-*" "name"' \ -} - -_rails_generate_resource() { - local context state line curcontext="$curcontext" - - local -a resource_generators_options - __rails_setup_resource_generators_options - - _arguments -C \ - $resource_generators_options \ - '(-c --resource-controller)'{-c,--resource-controller=}'[Resource controller to be invoked]:name' \ - '(-a --actions)'{-a,--actions=}'[Actions for the resource controller]: :->actions' \ - ': :->name' \ - '*: :->fields' - - if (( words[(I)(--actions=*|-a)] > 0 && words[(I)(--actions=*|-a)] == words[(I)-*] )); then - state=actions - fi - - case "$state" in - actions) - _guard "[[:alnum:]_]#" "actions" - ;; - name) - _guard "^-*" "name" - ;; - fields) - __rails_migration_fields - ;; - esac -} - -_rails_generate_scaffold() { - local -a resource_generators_options - __rails_setup_resource_generators_options - - _arguments \ - $resource_generators_options \ - '(-y --stylesheets)'{-y,--stylesheets}'[Generate Stylesheets]: :__rails_boolean' \ - '(-se --stylesheet-engine)'{-se,--stylesheet-engine=}'[Engine for Stylesheets]:stylesheet engine' \ - '(-c --scaffold-controller)'{-c,--scaffold-controller=}'[Scaffold controller to be invoked]:name' \ - --assets'[Indicates when to generate assets]:boolean:(true false)' \ - ': :_guard "^-*" "name"' \ - '*: :__rails_migration_fields' -} - -_rails_generate_scaffold_controller() { - local -a model_generators_options - __rails_setup_model_generators_options - - _arguments \ - $model_generators_options \ - '(-e --template-engine)'{-e,--template-engine=}'[Template engine to be invoked]:template engine' \ - '(-t --test-framework)'{-t,--test-framework=}'[Test framework to be invoked]:test framework' \ - --helper'[Indicates when to generate helper]: :__rails_boolean' \ - ': :_guard "^-*" "name"' -} - -_rails_generate_session_migration() { - local -a model_generators_options - __rails_setup_model_generators_options - - _arguments \ - $model_generators_options \ - ': :_guard "^-*" "name"' -} - -_rails_generate_task() { - local -a generators_options - __rails_setup_generators_options - - _arguments \ - $generators_options \ - ': :_guard "^-*" "name"' \ - '*: :_guard "^-*" "action"' -} - -_rails_console() { - _arguments \ - '(- *)'{-h,--help}'[Show this help message]' \ - '(-s --sandbox)'{-s,--sandbox}'[Rollback database modifications on exit]' \ - --debugger'[Enable ruby-debugging for the console]' -} - -_rails_c() { - _rails_console -} - -_rails_server() { - _arguments \ - '(- *)'{-h,--help}'[Show this help message]' \ - '(-p --port)'{-p,--port=}'[Runs Rails on the specified port]: :_guard "[[\:digit\:]]#" "port"' \ - '(-b --binding)'{-b,--binding=}'[Binds Rails to the specified ip]:ip:_hosts' \ - '(-c --config)'{-c,--config=}'[Use custom rackup configuration file]:file:_files -g "*.ru"' \ - '(-d --daemon)'{-d,--daemon}'[Make server run as a Daemon]' \ - '(-u --debugger)'{-u,--debugger}'[Enable ruby-debugging for the server]' \ - '(-e --environment)'{-e,--environment=}'[Specifies the environment to run this server under (test/development/production)]:name:(test development production)' \ - '(-P --pid)'{-P,--pid=}'[Specifies the PID file]:pid:_files -g "*.pid"' -} - -_rails_s() { - _rails_server -} - -_rails_dbconsole() { - _arguments \ - '(- *)'--help'[Show this help message]' \ - '(-p --include-password)'{-p,--include-password}'[Automatically provide the password from database.yml]' \ - --mode'[Automatically put the sqlite3 database in the specified mode (html, list, line, column)]:mode:(html list line column)' \ - --header -} - -_rails_new() { - local context state line curcontext="$curcontext" - - local _a rails_options runtime_options - __rails_setup_rails_options - __rails_setup_runtime_options - - _arguments -C \ - $rails_options \ - $runtime_options \ - '(-r --ruby)'{-r,--ruby=}'[Path to the Ruby binary of your choice]:path' \ - '(-b --builder)'{-b,--builder=}'[Path to a application builder (can be a filesystem path or URL)]: :->path_or_url' \ - '(-m --template)'{-m,--template=}'[Path to an application template (can be a filesystem path or URL)]: :->path_or_url' \ - --skip-gemfile"[Don't create a Gemfile]" \ - --skip-bundle"[Don't run bundle install]" \ - '(-G --skip-git)'{-G,--skip-git}'[Skip Git ignores and keeps]' \ - '(-O --skip-active-record)'{-O,--skip-active-record}'[Skip Active Record files]' \ - '(-S --skip-sprockets)'{-S,--skip-sprockets}'[Skip Sprockets files]' \ - '(-d --database)'{-d,--database=}'[Preconfigure for selected database]:database:(mysql oracle postgresql sqlite3 frontbase ibm_db sqlserver jdbcmysql jdbcsqlite3 jdbcpostgresql jdbc)' \ - '(-j --javascript)'{-j,--javascript=}'[Preconfigure for selected JavaScript library]:javascript' \ - '(-J --skip-javascript)'{-J,--skip-javascript}'[Skip JavaScript files]' \ - --dev'[Setup the application with Gemfile pointing to your Rails checkout]' \ - --edge'[Setup the application with Gemfile pointing to Rails repository]' \ - '(-T --skip-test-unit)'{-T,--skip-test-unit}'[Skip Test::Unit files]' \ - --old-style-hash"[Force using old style hash (:foo => 'bar') on Ruby >= 1.9]" \ - ':app path:_directories' - - case "$state" in - path_or_url) - _alternative \ - 'files:path:_files -g "*.rb"' \ - 'url:url:_urls' - ;; - esac -} - -_rails_application() { - _rails_new -} - -_rails_db() { - _rails_dbconsole -} - -_rails_destroy() { - _rails_generate -} - -_rails_d() { - _rails_destroy -} - -_rails_benchmarker() { - _arguments \ - '(- *)'{-h,--help}'[Show this help message]' \ - '(-r --runs)'{-r,--runs}'[Number of runs]: :_guard "[[\:digit\:]]#" "number"' \ - '(-o --output)'{-o,--output}'[Directory to use when writing the results]:directory:_directories' \ - '(-m --metrics)'{-m,--metrics}'[Metrics to use]: :_values -s "," "metrics" "wall_time" "memory" "objects" "gc_runs" "gc_time"' \ - '*: :_guard "^-*" "ruby code"' -} - -_rails_profiler() { - _arguments \ - '(- *)'{-h,--help}'[Show this help message]' \ - '(-r --runs)'{-r,--runs}'[Number of runs]: :_guard "[[\:digit\:]]#" "number"' \ - '(-o --output)'{-o,--output}'[Directory to use when writing the results]:directory:_directories' \ - '(-m --metrics)'{-m,--metrics}'[Metrics to use]: :_values -s "," "metrics" "process_time" "memory" "objects"' \ - '(-f --formats)'{-f,--formats}'[Formats to output to]: :_values -s "," "formats" "flat" "graph" "html" "call_tree" "call_stack"' \ - '*: :_guard "^-*" "ruby code"' -} - -_rails_plugin() { - local context state line curcontext="$curcontext" - - if (( CURRENT > 2 )); then - (( CURRENT-- )) - shift words - _call_function - "_rails_plugin_${words[1]}" || _nothing - else - __rails_plugin_commands - fi -} - -__rails_plugin_commands() { - _values 'plugin command' \ - install'[Install plugin(s) from known repositories or URLs]' \ - remove'[Uninstall plugins]' \ - new -} - -_rails_plugin_install() { - _arguments \ - '(-x --externals)'{-x,--externals}'[Use svn:externals to grab the plugin. Enables plugin updates and plugin versioning]' \ - '(-o --checkout)'{-o,--checkout}'[Use svn checkout to grab the plugin. Enables updating but does not add a svn:externals entry]' \ - '(-e --export)'{-e,--export}'[Use svn export to grab the plugin. Exports the plugin, allowing you to check it into your local repository. Does not enable updates or add an svn:externals entry]' \ - '(-q --quiet)'{-q,--quiet}'[Suppresses the output from installation. Ignored if -v is passed (rails plugin -v install ...)]' \ - '(-r --revision)'{-r,--revision=}'[Checks out the given revision from subversion or git. Ignored if subversion/git is not used]:revision' \ - '(-f --force)'{-f,--force}"[Reinstalls a plugin if it's already installed]" \ - '*:plugin:_urls' -} - -_rails_plugin_remove() { - local -a plugins - - plugins=($(_call_program rails_plugins ls -1 vendor/plugins)) - - _describe -t plugins 'plugin' plugins -} - -_rails_plugin_new() { - _rails_new -} - -_rails_runner() { - local context state line curcontext="$curcontext" - - _arguments -C \ - '(- *)'{-h,--help}'[Show this help message]' \ - '(-e --environment)'{-e,--environment=}'[Specifies the environment for the runner to operate under (test/development/production)]:name:(test development production)' \ - ': :->code_or_path' - - case "$state" in - code_or_path) - _alternative \ - 'files:filename:_files -g "*.rb"' \ - 'codes:ruby code:_guard "^-*" "ruby code"' - ;; - esac -} - -_rails_r() { - _rails_runner -} - -_rails_test() { - local context state line curcontext="$curcontext" - - _arguments -C \ - ': :->path' - - case "$state" in - path) - _alternative \ - 'files:filename:_files -g "*.rb"' - ;; - esac -} - -_rails_t() { - _rails_test -} - _rails "$@" # Local Variables: diff --git a/plugins/rake-fast/rake-fast.plugin.zsh b/plugins/rake-fast/rake-fast.plugin.zsh index 86e5ed586..082f02f29 100644 --- a/plugins/rake-fast/rake-fast.plugin.zsh +++ b/plugins/rake-fast/rake-fast.plugin.zsh @@ -43,14 +43,17 @@ _tasks_changed () { } _rake_generate () { - echo "version:$_rake_tasks_version" > .rake_tasks - - rake --silent --tasks --all \ + local rake_tasks_content="version:$_rake_tasks_version\n" + rake_tasks_content+=$(rake --silent --tasks --all \ | sed "s/^rake //" | sed "s/\:/\\\:/g" \ | sed "s/\[[^]]*\]//g" \ | sed "s/ *# /\:/" \ - | sed "s/\:$//" \ - >> .rake_tasks + | sed "s/\:$//") + + local rake_tasks_file="$(mktemp -t .rake_tasks.XXXXXX)" + echo $rake_tasks_content > $rake_tasks_file + + mv $rake_tasks_file .rake_tasks } _rake () { diff --git a/plugins/react-native/README.md b/plugins/react-native/README.md index 807c063a5..39eed6c68 100644 --- a/plugins/react-native/README.md +++ b/plugins/react-native/README.md @@ -54,6 +54,10 @@ plugins=(... react-native) | **rnios14pl** | `react-native run-ios --simulator "iPhone 14 Plus"` | | **rnios14p** | `react-native run-ios --simulator "iPhone 14 Pro"` | | **rnios14pm** | `react-native run-ios --simulator "iPhone 14 Pro Max"` | +| **rnios15** | `react-native run-ios --simulator "iPhone 15"` | +| **rnios15pl** | `react-native run-ios --simulator "iPhone 15 Plus"` | +| **rnios15p** | `react-native run-ios --simulator "iPhone 15 Pro"` | +| **rnios15pm** | `react-native run-ios --simulator "iPhone 15 Pro Max"` | | _iPad_ | | | **rnipad2** | `react-native run-ios --simulator "iPad 2"` | | **rnipad5** | `react-native run-ios --simulator "iPad (5th generation)"` | diff --git a/plugins/react-native/react-native.plugin.zsh b/plugins/react-native/react-native.plugin.zsh index afeaab4fd..9ee081248 100644 --- a/plugins/react-native/react-native.plugin.zsh +++ b/plugins/react-native/react-native.plugin.zsh @@ -39,6 +39,10 @@ alias rnios14='react-native run-ios --simulator "iPhone 14"' alias rnios14pl='react-native run-ios --simulator "iPhone 14 Plus"' alias rnios14p='react-native run-ios --simulator "iPhone 14 Pro"' alias rnios14pm='react-native run-ios --simulator "iPhone 14 Pro Max"' +alias rnios15='react-native run-ios --simulator "iPhone 15"' +alias rnios15pl='react-native run-ios --simulator "iPhone 15 Plus"' +alias rnios15p='react-native run-ios --simulator "iPhone 15 Pro"' +alias rnios15pm='react-native run-ios --simulator "iPhone 15 Pro Max"' # iPad alias rnipad2='react-native run-ios --simulator "iPad 2"' diff --git a/plugins/ros/_ros b/plugins/ros/_ros index 6a04d3c8f..c73a7b353 100644 --- a/plugins/ros/_ros +++ b/plugins/ros/_ros @@ -18,7 +18,7 @@ _1st_arguments=( 'config:Get and set options' 'version:Show the roswell version information' "help:Use \"ros help [command]\" for more information about a command."$'\n\t\t'"Use \"ros help [topic]\" for more information about the topic." -) +) #local expl diff --git a/plugins/rtx/rtx.plugin.zsh b/plugins/rtx/rtx.plugin.zsh new file mode 100644 index 000000000..43127a25f --- /dev/null +++ b/plugins/rtx/rtx.plugin.zsh @@ -0,0 +1,2 @@ +# TODO: 2024-01-03 remove rtx support +echo "[oh-my-zsh] 'rtx' plugin has been renamed to 'mise'" diff --git a/plugins/ruby/ruby.plugin.zsh b/plugins/ruby/ruby.plugin.zsh index 408512110..e09b22c75 100644 --- a/plugins/ruby/ruby.plugin.zsh +++ b/plugins/ruby/ruby.plugin.zsh @@ -23,4 +23,4 @@ alias gel="gem lock" alias geo="gem open" alias geoe="gem open -e" alias rrun="ruby -e" -alias rserver="ruby -e httpd . -p 8080" # requires webrick +alias rserver="ruby -run -e httpd . -p 8080" # requires webrick diff --git a/plugins/sbt/sbt.plugin.zsh b/plugins/sbt/sbt.plugin.zsh index 851302c68..1e977140b 100644 --- a/plugins/sbt/sbt.plugin.zsh +++ b/plugins/sbt/sbt.plugin.zsh @@ -4,7 +4,7 @@ # AUTHOR: Mirko Caserta (mirko.caserta@gmail.com) # VERSION: 1.0.2 # ------------------------------------------------------------------------------ - + # aliases - mnemonic: prefix is 'sb' alias sbc='sbt compile' alias sbcc='sbt clean compile' diff --git a/plugins/screen/screen.plugin.zsh b/plugins/screen/screen.plugin.zsh index c1db8ad92..26531c40b 100644 --- a/plugins/screen/screen.plugin.zsh +++ b/plugins/screen/screen.plugin.zsh @@ -8,7 +8,7 @@ if [[ "$TERM" == screen* ]]; then _GET_HOST='echo $HOST | sed "s/\..*//"' fi - # use the current user as the prefix of the current tab title + # use the current user as the prefix of the current tab title TAB_TITLE_PREFIX='"`'$_GET_HOST'`:`'$_GET_PATH' | sed "s:..*/::"`$PROMPT_CHAR"' # when at the shell prompt, show a truncated version of the current path (with # standard ~ replacement) as the rest of the title. diff --git a/plugins/shell-proxy/README.md b/plugins/shell-proxy/README.md index b19888c56..102e46b6b 100644 --- a/plugins/shell-proxy/README.md +++ b/plugins/shell-proxy/README.md @@ -23,6 +23,7 @@ Set `SHELLPROXY_URL` environment variable to the URL of the proxy server: ```sh SHELLPROXY_URL="http://127.0.0.1:8123" +SHELLPROXY_NO_PROXY="localhost,127.0.0.1" proxy enable ``` @@ -36,11 +37,15 @@ Example: ```sh #!/bin/bash +# HTTP Proxy if [[ "$(uname)" = Darwin ]]; then echo "http://127.0.0.1:6152" # Surge Mac else echo "http://127.0.0.1:8123" # polipo fi + +# No Proxy +echo "localhost,127.0.0.1" ``` ### Method 3 diff --git a/plugins/shell-proxy/proxy.py b/plugins/shell-proxy/proxy.py index 14f2944cc..8c2aaf9f3 100755 --- a/plugins/shell-proxy/proxy.py +++ b/plugins/shell-proxy/proxy.py @@ -6,6 +6,7 @@ from subprocess import check_output, list2cmdline cwd = os.path.dirname(__file__) ssh_agent = os.path.join(cwd, "ssh-agent.py") proxy_env = "SHELLPROXY_URL" +no_proxy_env = "SHELLPROXY_NO_PROXY" proxy_config = os.environ.get("SHELLPROXY_CONFIG") or os.path.expandvars("$HOME/.config/proxy") usage="""shell-proxy: no proxy configuration found. @@ -15,18 +16,30 @@ See the plugin README for more information.""".format(env=proxy_env, config=prox def get_http_proxy(): default_proxy = os.environ.get(proxy_env) - if default_proxy: - return default_proxy + no_proxy = os.environ.get(no_proxy_env) + if default_proxy and no_proxy: + return default_proxy, no_proxy + if os.path.isfile(proxy_config): - return check_output(proxy_config).decode("utf-8").strip() + proxy_configdata = [line.strip() for line in check_output(proxy_config).decode("utf-8").splitlines()] + if len(proxy_configdata) >= 1: + if not default_proxy: + default_proxy = proxy_configdata[0] + if len(proxy_configdata) == 2 and not no_proxy: + no_proxy = proxy_configdata[1] + + if default_proxy: + return default_proxy, no_proxy print(usage, file=sys.stderr) sys.exit(1) -def make_proxies(url: str): +def make_proxies(url: str, no_proxy: str): proxies = {"%s_PROXY" % _: url for _ in ("HTTP", "HTTPS", "FTP", "RSYNC", "ALL")} proxies.update({name.lower(): value for (name, value) in proxies.items()}) proxies["GIT_SSH"] = ssh_agent + if no_proxy: + proxies.update({"NO_PROXY": no_proxy, "no_proxy": no_proxy}) return proxies @@ -35,7 +48,7 @@ def merge(mapping: dict): class CommandSet: - proxies = make_proxies(get_http_proxy()) + proxies = make_proxies(*get_http_proxy()) aliases = { _: "env __SSH_PROGRAM_NAME__=%s %s" % (_, ssh_agent) for _ in ("ssh", "sftp", "scp", "slogin", "ssh-copy-id") diff --git a/plugins/shell-proxy/shell-proxy.plugin.zsh b/plugins/shell-proxy/shell-proxy.plugin.zsh index 4fdbe9322..f6c31da45 100644 --- a/plugins/shell-proxy/shell-proxy.plugin.zsh +++ b/plugins/shell-proxy/shell-proxy.plugin.zsh @@ -27,7 +27,7 @@ eval ' # capture the output of the proxy script and bail out if it fails local output - output="$(SHELLPROXY_URL="$SHELLPROXY_URL" SHELLPROXY_CONFIG="$SHELLPROXY_CONFIG" "$proxy" "$1")" || + output="$(SHELLPROXY_URL="$SHELLPROXY_URL" SHELLPROXY_NO_PROXY="$SHELLPROXY_NO_PROXY" SHELLPROXY_CONFIG="$SHELLPROXY_CONFIG" "$proxy" "$1")" || return $? # evaluate the output generated by the proxy script diff --git a/plugins/shell-proxy/ssh-proxy.py b/plugins/shell-proxy/ssh-proxy.py index a498c84bc..4b692f9e4 100755 --- a/plugins/shell-proxy/ssh-proxy.py +++ b/plugins/shell-proxy/ssh-proxy.py @@ -22,7 +22,8 @@ if parsed.scheme not in proxy_protocols: def make_argv(): yield "nc" - if sys.platform == 'linux': + if sys.platform in {'linux', 'cygwin'}: + # caveats: the built-in netcat of most linux distributions and cygwin support proxy type # caveats: macOS built-in netcat command not supported proxy-type yield "-X" # --proxy-type # Supported protocols are 4 (SOCKS v4), 5 (SOCKS v5) and connect (HTTP proxy). diff --git a/plugins/singlechar/singlechar.plugin.zsh b/plugins/singlechar/singlechar.plugin.zsh index d4b0b6735..6d785d9e1 100644 --- a/plugins/singlechar/singlechar.plugin.zsh +++ b/plugins/singlechar/singlechar.plugin.zsh @@ -1,5 +1,5 @@ ########################### -# Settings +# Settings # These can be overwritten any time. # If they are not set yet, they will be diff --git a/plugins/snap/README.md b/plugins/snap/README.md new file mode 100644 index 000000000..75c5ec19a --- /dev/null +++ b/plugins/snap/README.md @@ -0,0 +1,18 @@ +# snap plugin + +This plugin sets up aliases for the common [snap](https://snapcraft.io/docs/getting-started) commands + +## Aliases + +| Alias | Full command | +| --- | ---| +| sv | snap version | +| sf | snap find | +| si | snap install | +| sin | snap info | +| sr | snap remove | +| sref | snap refresh | +| srev | snap revert | +| sl | snap list | +| sd | snap disable | +| se | snap enable | diff --git a/plugins/snap/snap.plugin.zsh b/plugins/snap/snap.plugin.zsh new file mode 100644 index 000000000..af2346978 --- /dev/null +++ b/plugins/snap/snap.plugin.zsh @@ -0,0 +1,10 @@ +alias sv="snap version" +alias sf="snap find" +alias si="snap install" +alias sin="snap info" +alias sr="snap remove" +alias sref="snap refresh" +alias srev="snap revert" +alias sl="snap list" +alias sd="snap disable" +alias se="snap enable" diff --git a/plugins/ssh-agent/README.md b/plugins/ssh-agent/README.md index 8c118e65b..0afa80cc8 100644 --- a/plugins/ssh-agent/README.md +++ b/plugins/ssh-agent/README.md @@ -90,7 +90,7 @@ use the `ssh-add-args` setting. You can pass multiple arguments separated by spa zstyle :omz:plugins:ssh-agent ssh-add-args -K -c -a /run/user/1000/ssh-auth ``` -These will then be passed the the `ssh-add` call as if written directly. The example +These will then be passed the `ssh-add` call as if written directly. The example above will turn into: ```zsh diff --git a/plugins/ssh-agent/ssh-agent.plugin.zsh b/plugins/ssh-agent/ssh-agent.plugin.zsh index 78ac46b13..1da54d4dd 100644 --- a/plugins/ssh-agent/ssh-agent.plugin.zsh +++ b/plugins/ssh-agent/ssh-agent.plugin.zsh @@ -13,6 +13,11 @@ function _start_agent() { fi fi + if [[ ! -d "$HOME/.ssh" ]]; then + echo "[oh-my-zsh] ssh-agent plugin requires ~/.ssh directory" + return 1 + fi + # Set a maximum lifetime for identities added to ssh-agent local lifetime zstyle -s :omz:plugins:ssh-agent lifetime lifetime @@ -57,7 +62,7 @@ function _add_identities() { # if id is an absolute path, make file equal to id [[ "$id" = /* ]] && file="$id" || file="$HOME/.ssh/$id" # check for filename match, otherwise try for signature match - if [[ ${loaded_ids[(I)$file]} -le 0 ]]; then + if [[ -f $file && ${loaded_ids[(I)$file]} -le 0 ]]; then sig="$(ssh-keygen -lf "$file" | awk '{print $2}')" [[ ${loaded_sigs[(I)$sig]} -le 0 ]] && not_loaded+=("$file") fi @@ -93,8 +98,10 @@ function _add_identities() { # Add a nifty symlink for screen/tmux if agent forwarding is enabled if zstyle -t :omz:plugins:ssh-agent agent-forwarding \ - && [[ -n "$SSH_AUTH_SOCK" && ! -L "$SSH_AUTH_SOCK" ]]; then - ln -sf "$SSH_AUTH_SOCK" /tmp/ssh-agent-$USERNAME-screen + && [[ -n "$SSH_AUTH_SOCK" ]]; then + if [[ ! -L "$SSH_AUTH_SOCK" ]]; then + ln -sf "$SSH_AUTH_SOCK" /tmp/ssh-agent-$USERNAME-screen + fi else _start_agent fi diff --git a/plugins/ssh/ssh.plugin.zsh b/plugins/ssh/ssh.plugin.zsh new file mode 100644 index 000000000..b5b050536 --- /dev/null +++ b/plugins/ssh/ssh.plugin.zsh @@ -0,0 +1,53 @@ +############################################################ +# Take all host sections in .ssh/config and offer them for +# completion as hosts (e.g. for ssh, rsync, scp and the like) +# Filter out wildcard host sections. +_ssh_configfile="$HOME/.ssh/config" +if [[ -f "$_ssh_configfile" ]]; then + _ssh_hosts=($( + egrep '^Host.*' "$_ssh_configfile" |\ + awk '{for (i=2; i<=NF; i++) print $i}' |\ + sort |\ + uniq |\ + grep -v '^*' |\ + sed -e 's/\.*\*$//' + )) + zstyle ':completion:*:hosts' hosts $_ssh_hosts + unset _ssh_hosts +fi +unset _ssh_configfile + +############################################################ +# Remove host key from known hosts based on a host section +# name from .ssh/config +function ssh_rmhkey { + local ssh_configfile="$HOME/.ssh/config" + local ssh_host="$1" + if [[ -z "$ssh_host" ]]; then return; fi + ssh-keygen -R $(grep -A10 "$ssh_host" "$ssh_configfile" | grep -i HostName | head -n 1 | awk '{print $2}') +} +compctl -k hosts ssh_rmhkey + +############################################################ +# Load SSH key into agent +function ssh_load_key() { + local key="$1" + if [[ -z "$key" ]]; then return; fi + local keyfile="$HOME/.ssh/$key" + local keysig=$(ssh-keygen -l -f "$keyfile") + if ( ! ssh-add -l | grep -q "$keysig" ); then + ssh-add "$keyfile" + fi +} + +############################################################ +# Remove SSH key from agent +function ssh_unload_key { + local key="$1" + if [[ -z "$key" ]]; then return; fi + local keyfile="$HOME/.ssh/$key" + local keysig=$(ssh-keygen -l -f "$keyfile") + if ( ssh-add -l | grep -q "$keysig" ); then + ssh-add -d "$keyfile" + fi +} diff --git a/plugins/starship/starship.plugin.zsh b/plugins/starship/starship.plugin.zsh index 8c5d9135e..fc415e64c 100644 --- a/plugins/starship/starship.plugin.zsh +++ b/plugins/starship/starship.plugin.zsh @@ -1,7 +1,7 @@ -# ignore oh-my-zsh theme -unset ZSH_THEME - if (( $+commands[starship] )); then + # ignore oh-my-zsh theme + unset ZSH_THEME + eval "$(starship init zsh)" else echo '[oh-my-zsh] starship not found, please install it from https://starship.rs' diff --git a/plugins/stripe/README.md b/plugins/stripe/README.md new file mode 100644 index 000000000..9f0f32bc2 --- /dev/null +++ b/plugins/stripe/README.md @@ -0,0 +1,9 @@ +# Struoe + +This plugin provides completion for the [Stripe CLI](https://stripe.com/docs/stripe-cli). + +To use it add stripe to the plugins array in your zshrc file. + +```bash +plugins=(... stripe) +``` diff --git a/plugins/stripe/stripe.plugin.zsh b/plugins/stripe/stripe.plugin.zsh new file mode 100644 index 000000000..e2041bef2 --- /dev/null +++ b/plugins/stripe/stripe.plugin.zsh @@ -0,0 +1,13 @@ +if (( ! $+commands[stripe] )); then + return +fi + +# If the completion file doesn't exist yet, we need to autoload it and +# bind it to `stripe`. Otherwise, compinit will have already done that. +if [[ ! -f "$ZSH_CACHE_DIR/completions/_stripe" ]]; then + typeset -g -A _comps + autoload -Uz _stripe + _comps[stripe]=_stripe +fi + +stripe completion --shell zsh --write-to-stdout >| "$ZSH_CACHE_DIR/completions/_stripe" &| diff --git a/plugins/sublime/sublime.plugin.zsh b/plugins/sublime/sublime.plugin.zsh index dadf37574..cc84de737 100644 --- a/plugins/sublime/sublime.plugin.zsh +++ b/plugins/sublime/sublime.plugin.zsh @@ -4,7 +4,7 @@ alias st=subl alias stt='subl .' # Define sst only if sudo exists -(( $+commands[sudo] )) && alias sst='sudo subl' +(( $+commands[sudo] )) && alias sst='sudo -EH subl' alias stp=find_project alias stn=create_project @@ -62,7 +62,7 @@ alias stn=create_project for _sublime_path in $_sublime_paths; do if [[ -a $_sublime_path ]]; then alias subl="'$_sublime_path'" - (( $+commands[sudo] )) && alias sst="sudo '$_sublime_path'" + (( $+commands[sudo] )) && alias sst="sudo -EH '$_sublime_path'" break fi done diff --git a/plugins/systemadmin/README.md b/plugins/systemadmin/README.md index 3a9d9de66..bd6b08760 100644 --- a/plugins/systemadmin/README.md +++ b/plugins/systemadmin/README.md @@ -1,7 +1,7 @@ # Systemadmin plugin This plugin adds a series of aliases and functions which make a System Administrator's life easier. - + To use it, add `systemadmin` to the plugins array in your zshrc file: ```zsh diff --git a/plugins/systemadmin/systemadmin.plugin.zsh b/plugins/systemadmin/systemadmin.plugin.zsh index 7ce62bac1..03dd995b6 100644 --- a/plugins/systemadmin/systemadmin.plugin.zsh +++ b/plugins/systemadmin/systemadmin.plugin.zsh @@ -13,11 +13,11 @@ # ------------------------------------------------------------------------------ function retlog() { - if [[ -z $1 ]];then - echo '/var/log/nginx/access.log' - else - echo $1 - fi + if [[ -z $1 ]];then + echo '/var/log/nginx/access.log' + else + echo $1 + fi } alias ping='ping -c 5' @@ -28,142 +28,160 @@ alias mkdir='mkdir -pv' alias psmem='ps -e -orss=,args= | sort -b -k1 -nr' alias psmem10='ps -e -orss=,args= | sort -b -k1 -nr | head -n 10' # get top process eating cpu if not work try execute : export LC_ALL='C' -alias pscpu='ps -e -o pcpu,cpu,nice,state,cputime,args|sort -k1,1n -nr' -alias pscpu10='ps -e -o pcpu,cpu,nice,state,cputime,args|sort -k1,1n -nr | head -n 10' +alias pscpu='ps -e -o pcpu,cpu,nice,state,cputime,args | sort -k1,1n -nr' +alias pscpu10='ps -e -o pcpu,cpu,nice,state,cputime,args | sort -k1,1n -nr | head -n 10' # top10 of the history alias hist10='print -l ${(o)history%% *} | uniq -c | sort -nr | head -n 10' function ip() { - if [ -t 1 ]; then - command ip -color "$@" - else - command ip "$@" - fi + if [ -t 1 ]; then + command ip -color "$@" + else + command ip "$@" + fi } # directory LS function dls() { - print -l *(/) + print -l *(/) } function psgrep() { - ps aux | grep "${1:-.}" | grep -v grep + ps aux | grep "${1:-.}" | grep -v grep } # Kills any process that matches a regexp passed to it function killit() { - ps aux | grep -v "grep" | grep "$@" | awk '{print $2}' | xargs sudo kill + ps aux | grep -v "grep" | grep "$@" | awk '{print $2}' | xargs sudo kill } # list contents of directories in a tree-like format if ! (( $+commands[tree] )); then - function tree() { - find $@ -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' - } + function tree() { + find $@ -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' + } fi # Sort connection state function sortcons() { - netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn + { + LANG= ss -nat | awk 'NR > 1 {print $1}' \ + || LANG= netstat -nat | awk 'NR > 2 {print $6}' + } | sort | uniq -c | sort -rn } # View all 80 Port Connections function con80() { - netstat -nat|grep -i ":80"|wc -l + { + LANG= ss -nat || LANG= netstat -nat + } | grep -E ":80[^0-9]" | wc -l } # On the connected IP sorted by the number of connections function sortconip() { - netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n + { + LANG= ss -ntu | awk 'NR > 1 {print $6}' \ + || LANG= netstat -ntu | awk 'NR > 2 {print $5}' + } | cut -d: -f1 | sort | uniq -c | sort -n } # top20 of Find the number of requests on 80 port function req20() { - netstat -anlp|grep 80|grep tcp|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -n20 + { + LANG= ss -tn | awk '$4 ~ /:80$/ {print $5}' \ + || LANG= netstat -tn | awk '$4 ~ /:80$/ {print $5}' + } | awk -F: '{print $1}' | sort | uniq -c | sort -nr | head -n 20 } # top20 of Using tcpdump port 80 access to view function http20() { - sudo tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr |head -n 20 + sudo tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr | head -n 20 } # top20 of Find time_wait connection function timewait20() { - netstat -n|grep TIME_WAIT|awk '{print $5}'|sort|uniq -c|sort -rn|head -n20 + { + LANG= ss -nat | awk 'NR > 1 && /TIME-WAIT/ {print $5}' \ + || LANG= netstat -nat | awk 'NR > 2 && /TIME_WAIT/ {print $5}' + } | sort | uniq -c | sort -rn | head -n 20 } # top20 of Find SYN connection function syn20() { - netstat -an | grep SYN | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr|head -n20 + { + LANG= ss -an | awk '/SYN/ {print $5}' \ + || LANG= netstat -an | awk '/SYN/ {print $5}' + } | awk -F: '{print $1}' | sort | uniq -c | sort -nr | head -n20 } # Printing process according to the port number function port_pro() { - netstat -ntlp | grep "${1:-.}" | awk '{print $7}' | cut -d/ -f1 + LANG= ss -ntlp | awk "NR > 1 && /:${1:-}/ {print \$6}" | sed 's/.*pid=\([^,]*\).*/\1/' \ + || LANG= netstat -ntlp | awk "NR > 2 && /:${1:-}/ {print \$7}" | cut -d/ -f1 } # top10 of gain access to the ip address function accessip10() { - awk '{counts[$(11)]+=1}; END {for(url in counts) print counts[url], url}' "$(retlog)" + awk '{counts[$(11)]+=1}; END {for(url in counts) print counts[url], url}' "$(retlog)" } # top20 of Most Visited file or page function visitpage20() { - awk '{print $11}' "$(retlog)"|sort|uniq -c|sort -nr|head -n 20 + awk '{print $11}' "$(retlog)" | sort | uniq -c | sort -nr | head -n 20 } # top100 of Page lists the most time-consuming (more than 60 seconds) as well as the corresponding page number of occurrences function consume100() { - awk '($NF > 60 && $7~/\.php/){print $7}' "$(retlog)" |sort -n|uniq -c|sort -nr|head -n 100 - # if django website or other website make by no suffix language - # awk '{print $7}' "$(retlog)" |sort -n|uniq -c|sort -nr|head -n 100 + awk '($NF > 60 && $7~/\.php/){print $7}' "$(retlog)" | sort -n | uniq -c | sort -nr | head -n 100 + # if django website or other website make by no suffix language + # awk '{print $7}' "$(retlog)" | sort -n | uniq -c | sort -nr | head -n 100 } # Website traffic statistics (G) function webtraffic() { - awk "{sum+=$10} END {print sum/1024/1024/1024}" "$(retlog)" + awk "{sum+=$10} END {print sum/1024/1024/1024}" "$(retlog)" } # Statistical connections 404 function c404() { - awk '($9 ~/404/)' "$(retlog)" | awk '{print $9,$7}' | sort + awk '($9 ~ /404/)' "$(retlog)" | awk '{print $9,$7}' | sort } # Statistical http status. function httpstatus() { - awk '{counts[$(9)]+=1}; END {for(code in counts) print code, counts[code]}' "$(retlog)" + awk '{counts[$(9)]+=1}; END {for(code in counts) print code, counts[code]}' "$(retlog)" } # Delete 0 byte file function d0() { - find "${1:-.}" -type f -size 0 -exec rm -rf {} \; + find "${1:-.}" -type f -size 0 -exec rm -rf {} \; } # gather external ip address function geteip() { - curl -s -S -4 https://icanhazip.com + curl -s -S -4 https://icanhazip.com - # handle case when there is no IPv6 external IP, which shows error - # curl: (7) Couldn't connect to server - curl -s -S -6 https://icanhazip.com 2>/dev/null - local ret=$? - (( ret == 7 )) && print -P -u2 "%F{red}error: no IPv6 route to host%f" - return $ret + # handle case when there is no IPv6 external IP, which shows error + # curl: (7) Couldn't connect to server + curl -s -S -6 https://icanhazip.com 2>/dev/null + local ret=$? + (( ret == 7 )) && print -P -u2 "%F{red}error: no IPv6 route to host%f" + return $ret } # determine local IP address(es) function getip() { - if (( ${+commands[ip]} )); then - ip addr | awk '/inet /{print $2}' | command grep -v 127.0.0.1 - else - ifconfig | awk '/inet /{print $2}' | command grep -v 127.0.0.1 - fi + if (( ${+commands[ip]} )); then + ip addr | awk '/inet /{print $2}' | command grep -v 127.0.0.1 + else + ifconfig | awk '/inet /{print $2}' | command grep -v 127.0.0.1 + fi } # Clear zombie processes function clrz() { - ps -eal | awk '{ if ($2 == "Z") {print $4}}' | kill -9 + ps -eal | awk '{ if ($2 == "Z") {print $4}}' | kill -9 } # Second concurrent function conssec() { - awk '{if($9~/200|30|404/)COUNT[$4]++}END{for( a in COUNT) print a,COUNT[a]}' "$(retlog)"|sort -k 2 -nr|head -n10 + awk '{if($9~/200|30|404/)COUNT[$4]++}END{for( a in COUNT) print a,COUNT[a]}' "$(retlog)" | sort -k 2 -nr | head -n10 } diff --git a/plugins/systemd/README.md b/plugins/systemd/README.md index ffa0567a8..755c649a1 100644 --- a/plugins/systemd/README.md +++ b/plugins/systemd/README.md @@ -12,6 +12,7 @@ plugins=(... systemd) | Alias | Command | Description | |:-----------------------|:-----------------------------------|:-----------------------------------------------------------------| +| `sc-failed` | `systemctl --failed` | List failed systemd units | | `sc-list-units` | `systemctl list-units` | List all units systemd has in memory | | `sc-is-active` | `systemctl is-active` | Show whether a unit is active | | `sc-status` | `systemctl status` | Show terse runtime status information about one or more units | diff --git a/plugins/systemd/systemd.plugin.zsh b/plugins/systemd/systemd.plugin.zsh index 1270bea0e..382a57b29 100644 --- a/plugins/systemd/systemd.plugin.zsh +++ b/plugins/systemd/systemd.plugin.zsh @@ -93,6 +93,9 @@ alias scu-enable-now="scu-enable --now" alias scu-disable-now="scu-disable --now" alias scu-mask-now="scu-mask --now" +# --failed commands +alias scu-failed='systemctl --user --failed' +alias sc-failed='systemctl --failed' function systemd_prompt_info { local unit diff --git a/plugins/terraform/README.md b/plugins/terraform/README.md index c19f2ad1c..2b535517c 100644 --- a/plugins/terraform/README.md +++ b/plugins/terraform/README.md @@ -1,7 +1,7 @@ # Terraform plugin -Plugin for Terraform, a tool from Hashicorp for managing infrastructure safely and efficiently. -It adds completion for `terraform`, as well as aliases and a prompt function. +Plugin for Terraform, a tool from Hashicorp for managing infrastructure safely and efficiently. It adds +completion for `terraform`, as well as aliases and a prompt function. To use it, add `terraform` to the plugins array of your `~/.zshrc` file: @@ -11,29 +11,34 @@ plugins=(... terraform) ## Requirements -* [Terraform](https://terraform.io/) +- [Terraform](https://terraform.io/) ## Aliases -| Alias | Command | -| ----- | -------------------- | -| `tf` | `terraform` | -| `tfa` | `terraform apply` | -| `tfc` | `terraform console` | -| `tfd` | `terraform destroy` | -| `tff` | `terraform fmt` | -| `tfi` | `terraform init` | -| `tfo` | `terraform output` | -| `tfp` | `terraform plan` | -| `tfv` | `terraform validate` | +| Alias | Command | +| ------ | -------------------- | +| `tf` | `terraform` | +| `tfa` | `terraform apply` | +| `tfc` | `terraform console` | +| `tfd` | `terraform destroy` | +| `tff` | `terraform fmt` | +| `tfi` | `terraform init` | +| `tfo` | `terraform output` | +| `tfp` | `terraform plan` | +| `tfv` | `terraform validate` | +| `tfs` | `terraform state` | +| `tft` | `terraform test` | +| `tfsh` | `terraform show` | + ## Prompt function -You can add the current Terraform workspace in your prompt by adding `$(tf_prompt_info)` -to your `PROMPT` or `RPROMPT` variable. +You can add the current Terraform workspace in your prompt by adding `$(tf_prompt_info)`, +`$(tf_version_prompt_info)` to your `PROMPT` or `RPROMPT` variable. ```sh RPROMPT='$(tf_prompt_info)' +RPROMPT='$(tf_version_prompt_info)' ``` You can also specify the PREFIX and SUFFIX for the workspace with the following variables: @@ -41,4 +46,6 @@ You can also specify the PREFIX and SUFFIX for the workspace with the following ```sh ZSH_THEME_TF_PROMPT_PREFIX="%{$fg[white]%}" ZSH_THEME_TF_PROMPT_SUFFIX="%{$reset_color%}" +ZSH_THEME_TF_VERSION_PROMPT_PREFIX="%{$fg[white]%}" +ZSH_THEME_TF_VERSION_PROMPT_SUFFIX="%{$reset_color%}" ``` diff --git a/plugins/terraform/_terraform b/plugins/terraform/_terraform index 625834563..157495814 100644 --- a/plugins/terraform/_terraform +++ b/plugins/terraform/_terraform @@ -1,411 +1,545 @@ #compdef terraform +compdef _terraform 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' +(( ${+functions[_terraform_commands]} )) || _terraform_commands() { + local -a _terraform_cmds + _terraform_cmds=( + 'apply:Create or update infrastructure' + 'console:Try Terraform expressions at an interactive command prompt' + 'destroy:Destroy previously-created infrastructure' + 'fmt:Reformat your configuration in the standard style' + 'force-unlock:Release a stuck lock on the current workspace' + 'get:Install or upgrade remote Terraform modules' + 'graph:Generate a Graphviz graph of the steps in an operation' + 'import:Associate existing infrastructure with a Terraform resource' + 'init:Prepare your working directory for other commands' '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' + 'metadata:Metadata related commands' + 'output:Show output values from your root module' + 'plan:Show changes required by the current configuration' + 'providers:Show the providers required for this configuration' + 'refresh:Update the state to match remote systems' + 'show:Show the current state or a saved 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' + 'taint:Mark a resource instance as not fully functional' + 'test:Execute integration tests for Terraform modules' + 'untaint:Remove the '\''tainted'\'' state from a resource instance' + 'validate:Check whether the configuration is valid' + 'version:Show the current 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' -) + ) + if (( CURRENT == 1 )); then + _describe -t commands 'terraform commands' _terraform_cmds + return + fi -__012upgrade() { + local curcontext="${curcontext}" + cmd="${${_terraform_cmds[(r)$words[1]:*]%%:*}}" + curcontext="${curcontext%:*:*}:terraform-${cmd}:" + + local __chdir="${opt_args[-chdir]:-.}" + + if (( ${+functions[_terraform_$cmd]} )); then + "_terraform_${cmd}" + else + _message "no more options" + fi +} + +(( ${+functions[_terraform_apply]} )) || _terraform_apply() { _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.]' + '-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 -W __chdir -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.]' \ + '-destroy[Destroy Terraform-managed infrastructure. The command "terraform destroy" is a convenience alias for this option.]' \ + '-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \ + '-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \ + '-input=[(true) Ask for input for variables if not directly set.]:input:(true false)' \ + '-no-color[If specified, output won'\''t contain any color.]' \ + '-parallelism=[(10) Limit the number of parallel resource operations.]:parallelism:' \ + '-refresh=[(true) Skip checking for external changes to remote objects while creating the plan. This can potentially make planning faster, but at the expense of possibly planning against a stale record of the remote system state.]:refresh:(true false)' \ + '*-replace=[(resource) Force replacement of a particular resource instance using its resource address. If applying would'\''ve normally produced an update or no-op action for this instance, Terraform will replace it instead. You can use this option multiple times to replace more than one object.]:resource:__terraform_state_resources' \ + '-state=[(terraform.tfstate) Path to read and save state (unless state-out is specified).]:statefile:_files -W __chdir -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 -W __chdir -g "*.tfstate"' \ + '*-target=[(resource) Limit the operation to only the given module, resource, or resource instance and all of its dependencies. You can use this option multiple times to include more than one object. This is for exceptional use only.]:target:__terraform_state_resources' \ + '*-var=[(for=bar) Set a value for one of the input variables in the root module of the configuration. Use this option more than once to set more than one variable.]:var:' \ + '*-var-file=[(foo) Load variable values from the given file, in addition to the default files terraform.tfvars and *.auto.tfvars. Use this option more than once to include more than one variables file.]:file:_files -W __chdir -g "*.tfvars{,.json}"' \ + ':plan:_files -W __chdir -' } -__013upgrade() { +(( ${+functions[_terraform_console]} )) || _terraform_console() { _arguments \ - '-yes[Skip the initial introduction messages and interactive confirmation. This can be used to run this command in batch from a script.]' + '-state=[(terraform.tfstate) Legacy option for the local backend only. See the local backend'\''s documentation for more information.]:statefile:_files -W __chdir -g "*.tfstate"' \ + '-plan[Create a new plan (as if running "terraform plan") and then evaluate expressions against its planned state, instead of evaluating against the current state. You can use this to inspect the effects of configuration changes that haven'\''t been applied yet.]' \ + '*-var=[(for=bar) Set a variable in the Terraform configuration. This flag can be set multiple times.]:var:' \ + '*-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 -W __chdir -g "*.tfvars{,.json}"' } -__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() { +(( ${+functions[_terraform_destroy]} )) || _terraform_destroy() { _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" + '-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 -W __chdir -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) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \ + '-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \ + '-input=[(true) Ask for input for variables if not directly set.]:input:(true false)' \ + '-no-color[If specified, output won'\''t contain any color.]' \ + '-parallelism=[(10) Limit the number of parallel resource operations.]:parallelism:' \ + '-refresh=[(true) Update state prior to checking for differences. This has no effect if a plan file is given to apply.]:refresh:(true false)' \ + '-state=[(terraform.tfstate) Path to read and save state (unless state-out is specified).]:statefile:_files -W __chdir -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 -W __chdir -g "*.tfstate"' \ + '*-target=[(resource) Limit the operation to only the given module, resource, or resource instance and all of its dependencies. You can use this option multiple times to include more than one object. This is for exceptional use only.]:target:__terraform_state_resources' \ + '*-var=[(for=bar) Set a value for one of the input variables in the root module of the configuration. Use this option more than once to set more than one variable.]:var:' \ + '*-var-file=[(foo) Load variable values from the given file, in addition to the default files terraform.tfvars and *.auto.tfvars. Use this option more than once to include more than one variables file.]:file:_files -W __chdir -g "*.tfvars{,.json}"' } -__state_mv() { +(( ${+functions[_terraform_fmt]} )) || _terraform_fmt() { _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: " + '-list=[(true) Don'\''t list files whose formatting differs (always disabled if using STDIN)]:list:(true false)' \ + '-write=[(true) Don'\''t write to source files (always disabled if using STDIN or -check)]:write:(true false)' \ + '-diff[Display diffs of formatting changes]' \ + '-check[Check if the input is formatted. Exit status will be 0 if all input is properly formatted and non-zero otherwise.]' \ + '-no-color[If specified, output won'\''t contain any color.]' \ + '-recursive[Also process files in subdirectories. By default, only the given directory (or current directory) is processed.]' \ + '*:targets:_files -W __chdir -' } -__state_push() { +(( ${+functions[_terraform_force-unlock]} )) || _terraform_force-unlock() { _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" + '-force[Don'\''t ask for input for unlock confirmation.]' \ + ':lock_id:' } -__state_replace_provider() { +(( ${+functions[_terraform_get]} )) || _terraform_get() { + _arguments \ + '-update[Check already-downloaded modules for available updates and install the newest versions available.]' \ + '-no-color[Disable text coloring in the output.]' \ + '-test-directory=[(tests) Set the Terraform test directory, defaults to "tests".]:test_directory:_files -W __chdir -/' +} + +(( ${+functions[_terraform_graph]} )) || _terraform_graph() { + _arguments \ + '-draw-cycles[Highlight any cycles in the graph with colored edges. This helps when diagnosing cycle errors. This option is supported only when illustrating a real evaluation graph, selected using the -type=TYPE option.]' \ + '-module-depth=[(-1) (deprecated) In prior versions of Terraform, specified the depth of modules to show in the output.]:module_depth:' \ + '-plan=[Render graph using the specified plan file instead of the configuration in the current directory. Implies -type=apply.]:plan:_files -W __chdir -' \ + '-type=[(plan) Type of operation graph to output. Can be: plan, plan-refresh-only, plan-destroy, or apply. By default Terraform just summarizes the relationships between the resources in your configuration, without any particular operation in mind. Full operation graphs are more detailed but therefore often harder to read.]:type:(plan plan-refresh-only plan-destroy apply)' +} + +(( ${+functions[_terraform_import]} )) || _terraform_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 -W __chdir -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.]:config:_files -W __chdir -/' \ + '-input=[(true) Disable interactive input prompts.]:input:(true false)' \ + '-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \ + '-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \ + '-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 -W __chdir -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 -W __chdir -g "*.tfstate"' \ + '*-var=[(for=bar) Set a variable in the Terraform configuration. This flag can be set multiple times. This is only useful with the "-config" flag.]:var:' \ + '*-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 -W __chdir -g "*.tfvars{,.json}"' \ + ':addr:' \ + ':id:' +} + +(( ${+functions[_terraform_init]} )) || _terraform_init() { + _arguments \ + '-backend=[(true) Disable backend or Terraform Cloud initialization for this configuration and use what was previously initialized instead.]:backend:(true false)' \ + '-backend-config=[Configuration to be merged with what is in the configuration file'\''s '\''backend'\'' block. This can be either a path to an HCL file with key/value assignments (same format as terraform.tfvars) or a '\''key=value'\'' format, and can be specified multiple times. The backend type must be in the configuration itself.]:backend_config:_files -W __chdir -' \ + '-force-copy[Suppress prompts about copying state data. This is equivalent to providing a "yes" to all confirmation prompts.]' \ + '-from-module=[Copy the contents of the given module into the target directory before initialization.]:from_module:_files -W __chdir -/' \ + '-get=[(true) Disable downloading modules for this configuration.]:get:(true false)' \ + '-input=[(true) Disable interactive prompts. Note that some actions may require interactive prompts and will error if input is disabled.]:input:(true false)' \ + '-lock=[(true) Don'\''t hold a state lock during backend migration. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \ + '-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \ + '-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 -W __chdir -/' \ + '-reconfigure[Reconfigure the backend, ignoring any saved configuration.]' \ + '-migrate-state[Reconfigure a backend, and attempt to migrate any existing state.]' \ + '-upgrade[Install the latest module and provider versions allowed within configured constraints, overriding the default behavior of selecting exactly the version recorded in the dependency lockfile.]' \ + '-lockfile=[Set a dependency lockfile mode. Currently only "readonly" is valid.]:lockfile:( readonly )' \ + '-ignore-remote-version[A rare option used for Terraform Cloud and the remote backend only. Set this to ignore checking that the local and remote Terraform versions use compatible state representations, making an operation proceed even when there is a potential mismatch. See the documentation on configuring Terraform with Terraform Cloud for more information.]' \ + '-test-directory=[(tests) Set the Terraform test directory, defaults to "tests".]:test_directory:_files -W __chdir -/' +} + +(( ${+functions[_terraform_login]} )) || _terraform_login() { + _arguments \ + ':hostname:' +} + +(( ${+functions[_terraform_logout]} )) || _terraform_logout() { + _arguments \ + ':hostname:' +} + +(( ${+functions[_terraform_metadata]} )) || _terraform_metadata() { + _arguments \ + '*::terraform metadata command:_terraform_metadata_commands' +} + +(( ${+functions[_terraform_metadata_commands]} )) || _terraform_metadata_commands() { + local -a _metadata_cmds + _metadata_cmds=( + 'functions:Show signatures and descriptions for the available functions' + ) + if (( CURRENT == 1 )); then + _describe -t commands "terraform metadata commands" _metadata_cmds + return + fi + + local curcontext="${curcontext}" + cmd="${${_metadata_cmds[(r)$words[1]:*]%%:*}}" + curcontext="${curcontext%:*:*}:terraform-metadata-${cmd}:" + + if (( ${+functions[_terraform_metadata_$cmd]} )); then + "_terraform_metadata_${cmd}" + else + _message "no more options" + fi +} + +(( ${+functions[_terraform_metadata_functions]} )) || _terraform_metadata_functions() { + _arguments \ + '-json[]' +} + +(( ${+functions[_terraform_output]} )) || _terraform_output() { + _arguments \ + '-state=[(path) Path to the state file to read. Defaults to "terraform.tfstate". Ignored when remote state is used.]:statefile:_files -W __chdir -g "*.tfstate"' \ + '-no-color[If specified, output will contain no color.]' \ + '-json[If specified, machine readable output will be printed in JSON format]' \ + '-raw[For value types that can be automatically converted to a string, will print the raw string directly, rather than a human-oriented representation of the value.]' \ + ':name:' +} + +(( ${+functions[_terraform_plan]} )) || _terraform_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[Select the "destroy" planning mode, which creates a plan to destroy all objects currently managed by this Terraform configuration instead of the usual behavior.]' \ + '-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.]:input:(true false)' \ + '-generate-config-out=[(path) (Experimental) If import blocks are present in configuration, instructs Terraform to generate HCL for any imported resources not already present. The configuration is written to a new file at PATH, which must not already exist. Terraform may still attempt to write configuration if the plan errors.]:generate_config_out:' \ + '-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \ + '-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \ + '-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.]:out:' \ + '-parallelism=[(10) Limit the number of concurrent operations.]:parallelism:' \ + '-refresh=[(true) Skip checking for external changes to remote objects while creating the plan. This can potentially make planning faster, but at the expense of possibly planning against a stale record of the remote system state.]:refresh:(true false)' \ + '-refresh-only[Select the "refresh only" planning mode, which checks whether remote objects still match the outcome of the most recent Terraform apply but does not propose any actions to undo any changes made outside of Terraform.]' \ + '*-replace=[(resource) Force replacement of a particular resource instance using its resource address. If the plan would'\''ve normally produced an update or no-op action for this instance, Terraform will plan to replace it instead. You can use this option multiple times to replace more than one object.]:replace:__terraform_state_resources' \ + '-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 -W __chdir -g "*.tfstate"' \ + '*-target=[(resource) Limit the planning operation to only the given module, resource, or resource instance and all of its dependencies. You can use this option multiple times to include more than one object. This is for exceptional use only.]:target:__terraform_state_resources' \ + '*-var=[(for=bar) Set a value for one of the input variables in the root module of the configuration. Use this option more than once to set more than one variable.]:var:' \ + '*-var-file=[(foo) Load variable values from the given file, in addition to the default files terraform.tfvars and *.auto.tfvars. Use this option more than once to include more than one variables file.]:file:_files -W __chdir -g "*.tfvars{,.json}"' +} + +(( ${+functions[_terraform_providers]} )) || _terraform_providers() { + _arguments \ + '-test-directory=[(path) Set the Terraform test directory, defaults to "tests".]:test_directory:_files -W __chdir -/' \ + '*::terraform providers command:_terraform_providers_commands' +} + +(( ${+functions[_terraform_providers_commands]} )) || _terraform_providers_commands() { + local -a _providers_cmds + _providers_cmds=( + 'lock:Write out dependency locks for the configured providers' + 'mirror:Save local copies of all required provider plugins' + 'schema:Show schemas for the providers used in the configuration' + ) + if (( CURRENT == 1 )); then + _describe -t commands "terraform providers commands" _providers_cmds + return + fi + + local curcontext="${curcontext}" + cmd="${${_providers_cmds[(r)$words[1]:*]%%:*}}" + curcontext="${curcontext%:*:*}:terraform-providers-${cmd}:" + + if (( ${+functions[_terraform_providers_$cmd]} )); then + "_terraform_providers_${cmd}" + else + _message "no more options" + fi +} + +(( ${+functions[_terraform_providers_lock]} )) || _terraform_providers_lock() { + _arguments \ + '-fs-mirror=[(dir) Consult the given filesystem mirror directory instead of the origin registry for each of the given providers.]:fs_mirror:_files -W __chdir -/' \ + '-net-mirror=[(url) Consult the given network mirror (given as a base URL) instead of the origin registry for each of the given providers.]:net_mirror:' \ + '*-platform=[(os_arch) Choose a target platform to request package checksums for.]:platform:' \ + '*:provider:' +} + +(( ${+functions[_terraform_providers_mirror]} )) || _terraform_providers_mirror() { + _arguments \ + '*-platform=[(os_arch) Choose which target platform to build a mirror for.]:platform:' \ + '::' \ + ':target_dir:_files -W __chdir -/' +} + +(( ${+functions[_terraform_providers_schema]} )) || _terraform_providers_schema() { + _arguments \ + '-json[]' +} + +(( ${+functions[_terraform_refresh]} )) || _terraform_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 -W __chdir -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.]:input:(true false)' \ + '-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \ + '-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \ + '-no-color[If specified, output will not contain any color.]' \ + '-parallelism=[(10) Limit the number of parallel resource operations.]:parallelism:' \ + '-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]:statefile:_files -W __chdir -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 -W __chdir -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:__terraform_state_resources' \ + '*-var=[(for=bar) Set a variable in the Terraform configuration. This flag can be set multiple times.]:var:' \ + '*-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 -W __chdir -g "*.tfvars{,.json}"' +} + +(( ${+functions[_terraform_show]} )) || _terraform_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.]' \ + ':path:_files -W __chdir -g "*.tfstate"' +} + +(( ${+functions[_terraform_state]} )) || _terraform_state() { + _arguments \ + '*::terraform state command:_terraform_state_commands' +} + +(( ${+functions[_terraform_state_commands]} )) || _terraform_state_commands() { + 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 in the state' + 'rm:Remove instances from the state' + 'show:Show a resource in the state' + ) + if (( CURRENT == 1 )); then + _describe -t commands "terraform state commands" _state_cmds + return + fi + + local curcontext="${curcontext}" + cmd="${${_state_cmds[(r)$words[1]:*]%%:*}}" + curcontext="${curcontext%:*:*}:terraform-state-${cmd}:" + + if (( ${+functions[_terraform_state_$cmd]} )); then + "_terraform_state_${cmd}" + else + _message "no more options" + fi +} + +(( ${+functions[_terraform_state_list]} )) || _terraform_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.]:statefile:_files -W __chdir -g "*.tfstate"' \ + '-id=[(id) Filters the results to include only instances whose resource types have an attribute named id whose value equals the given id string.]:id:' \ + '*:address:__terraform_state_resources' +} + +(( ${+functions[_terraform_state_mv]} )) || _terraform_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 -W __chdir -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 -W __chdir -g "*.backup"' \ + '-ignore-remote-version[A rare option used for the remote backend only. See the remote backend documentation for more information.]' \ + '-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \ + '-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \ + '-state=[(path) Path to the source state file. Defaults to the configured backend, or "terraform.tfstate"]:statefile:_files -W __chdir -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 -W __chdir -g "*.tfstate"' \ + '::' \ + ':source:__terraform_state_resources' \ + ':destination: ' +} + +(( ${+functions[_terraform_state_push]} )) || _terraform_state_push() { + _arguments \ + '-force[Write the state even if lineages don'\''t match or the remote serial is higher.]' \ + '-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \ + '-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \ + '::' \ + ':destination:_files' +} + +(( ${+functions[_terraform_state_replace-provider]} )) || _terraform_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:" + '-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 -W __chdir -g "*.backup"' \ + '-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \ + '-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \ + '-state=[(PATH) Path to the source state file. Defaults to the configured backend, or "terraform.tfstate"]:statefile:_files -W __chdir -g "*.tfstate"' \ + '::' \ + ':from_provider_fqn:' \ + ':to_provider_fqn:' } -__state_rm() { +(( ${+functions[_terraform_state_rm]} )) || _terraform_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" + '-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 -W __chdir -g "*.backup"' \ + '-ignore-remote-version[Continue even if remote and local Terraform versions are incompatible. This may result in an unusable workspace, and should be used with extreme caution.]' \ + '-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \ + '-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \ + '-state=[(PATH) Path to the state file to update. Defaults to the current workspace state.]:statefile:_files -W __chdir -g "*.tfstate"' \ + '*:address:__terraform_state_resources' } - -__state_show() { +(( ${+functions[_terraform_state_show]} )) || _terraform_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" + '-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 -W __chdir -g "*.tfstate"' \ + "*:address:__terraform_state_resources" } -__statelist() { - compadd $(terraform state list $opt_args[-state]) +(( ${+functions[__terraform_state_resources]} )) || __terraform_state_resources() { + local resource + local -a resources + terraform -chdir="${__chdir}" state list -state="${opt_args[-state]}" 2>/dev/null | while read -r resource; do + resources+=( "${resource}" ) + done + compadd "${@}" - "${resources[@]}" } -__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 \ +(( ${+functions[_terraform_taint]} )) || _terraform_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"' + '-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 -W __chdir -g "*.backup"' \ + '-ignore-remote-version[A rare option used for the remote backend only. See the remote backend documentation for more information.]' \ + '-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \ + '-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \ + '-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]:statefile:_files -W __chdir -g "*.tfstate"' \ + '-state-out=[(path) Path to write updated state file. By default, the "-state" path will be used.]:statefile:_files -W __chdir -g "*.tfstate"' \ + '*:address:__terraform_state_resources' } -__validate() { - _arguments \ - '-no-color[If specified, output will not contain any color.]' \ +(( ${+functions[_terraform_test]} )) || _terraform_test() { + _arguments \ + '-cloud-run=[(source) If specified, Terraform will execute this test run remotely using Terraform Cloud. You must specify the source of a module registered in a private module registry as the argument to this flag. This allows Terraform to associate the cloud run with the correct Terraform Cloud module and organization.]:cloud_run:' \ + '*-filter=[(testfile) If specified, Terraform will only execute the test files specified by this flag. You can use this option multiple times to execute more than one test file.]:testfile:_files -W __chdir -g "*.tftest.hcl"' \ + '-json[If specified, machine readable output will be printed in JSON format]' \ + '-no-color[If specified, machine readable output will be printed in JSON format]' \ + '-test-directory=[(path) Set the Terraform test directory, defaults to "tests".]:test_directory:_files -W __chdir -/' \ + '*-var=[(for=bar) Set a value for one of the input variables in the root module of the configuration. Use this option more than once to set more than one variable.]:var:' \ + '*-var-file=[(foo) Load variable values from the given file, in addition to the default files terraform.tfvars and *.auto.tfvars. Use this option more than once to include more than one variables file.]:file:_files -W __chdir -g "*.tfvars{,.json}"' \ + '-verbose[Print the plan or state for each test run block as it executes.]' \ +} + +(( ${+functions[_terraform_untaint]} )) || _terraform_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 -W __chdir -g "*.backup"' \ + '-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \ + '-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \ + '-state=[(path) Path to read and save state (unless state-out is specified). Defaults to "terraform.tfstate".]:statefile:_files -W __chdir -g "*.tfstate"' \ + '-state-out=[(path) Path to write updated state file. By default, the "-state" path will be used.]:statefile:_files -W __chdir -g "*.tfstate"' \ + ':name:__terraform_state_resources' +} + +(( ${+functions[_terraform_validate]} )) || _terraform_validate() { + _arguments \ '-json[Produce output in a machine-readable JSON format, suitable for use in text editor integrations and other automated systems.]' \ - ':dir:_files -/' + '-no-color[If specified, output will not contain any color.]' \ + '-no-tests[If specified, Terraform will not validate test files.]' \ + '-test-directory=[(path) Set the Terraform test directory, defaults to "tests".]:test_directory:_files -W __chdir -/' \ + ':dir:_files -W __chdir -/' } -__version() { - _arguments \ - '-json[Output the version information as a JSON object.]' +(( ${+functions[_terraform_version]} )) || _terraform_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 +(( ${+functions[_terraform_workspace]} )) || _terraform_workspace() { + _arguments \ + '*::terraform workspace command:_terraform_workspace_commands' } -_arguments '*:: :->command' +(( ${+functions[_terraform_workspace_commands]} )) || _terraform_workspace_commands() { + 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' + ) + if (( CURRENT == 1 )); then + _describe -t commands "terraform workspace commands" _workspace_cmds + return + fi -if (( CURRENT == 1 )); then - _describe -t commands "terraform command" _terraform_cmds - return + local curcontext="${curcontext}" + cmd="${${_workspace_cmds[(r)$words[1]:*]%%:*}}" + curcontext="${curcontext%:*:*}:terraform-workspace-${cmd}:" + + if (( ${+functions[_terraform_workspace_$cmd]} )); then + "_terraform_workspace_${cmd}" + else + _message "no more options" + fi +} + +(( ${+functions[_terraform_workspace_delete]} )) || _terraform_workspace_delete() { + _arguments \ + '-force[Remove a workspace even if it is managing resources. Terraform can no longer track or manage the workspace'\''s infrastructure.]' \ + '-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \ + '-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \ + '::' \ + ':name:__terraform_workspaces' +} + +(( ${+functions[_terraform_workspace_list]} )) || _terraform_workspace_list() { + _arguments +} + +(( ${+functions[_terraform_workspace_new]} )) || _terraform_workspace_new() { + _arguments \ + '-lock=[(true) Don'\''t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.]:lock:(true false)' \ + '-lock-timeout=[(0s) Duration to retry a state lock.]:lock_timeout:' \ + '-state=[(path) Copy an existing state file into the new workspace.]:statefile:_files -W __chdir -g "*.tfstate"' \ + '::' \ + ':name:' +} + +(( ${+functions[_terraform_workspace_select]} )) || _terraform_workspace_select() { + _arguments \ + '-or-create=[(false) Create the Terraform workspace if it doesn'\''t exist.]:or_create:(true false)' \ + '::' \ + ':name:__terraform_workspaces' +} + +(( ${+functions[_terraform_workspace_show]} )) || _terraform_workspace_show() { + _arguments +} + +(( ${+functions[__terraform_workspaces]} )) || __terraform_workspaces() { + local workspace + local -a workspaces + terraform -chdir="${__chdir}" workspace list | while read -r workspace; do + if [[ -z "${workspace}" ]]; then + continue + fi + workspaces+=( "${workspace#[ *] }" ) + done + compadd "${@}" - "${workspaces[@]}" +} + +_terraform() { + _arguments \ + '-chdir=[(DIR) Switch to a different working directory before executing the given subcommand.]:chdir:_files -W __chdir -/' \ + '-help[Show this help output, or the help for a specified subcommand.]' \ + '-version[An alias for the "version" subcommand.]' \ + '*::terraform command:_terraform_commands' +} + +# don't run the completion function when being source-ed or eval-ed +if [ "${funcstack[1]}" = '_terraform' ]; then + _terraform 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 7006f204b..8ef392efd 100644 --- a/plugins/terraform/terraform.plugin.zsh +++ b/plugins/terraform/terraform.plugin.zsh @@ -8,6 +8,13 @@ function tf_prompt_info() { echo "${ZSH_THEME_TF_PROMPT_PREFIX-[}${workspace:gs/%/%%}${ZSH_THEME_TF_PROMPT_SUFFIX-]}" } +function tf_version_prompt_info() { + local terraform_version + terraform_version=$(terraform --version | head -n 1 | cut -d ' ' -f 2) + echo "${ZSH_THEME_TF_VERSION_PROMPT_PREFIX-[}${terraform_version:gs/%/%%}${ZSH_THEME_TF_VERSION_PROMPT_SUFFIX-]}" +} + + alias tf='terraform' alias tfa='terraform apply' alias tfc='terraform console' @@ -17,3 +24,6 @@ alias tfi='terraform init' alias tfo='terraform output' alias tfp='terraform plan' alias tfv='terraform validate' +alias tfs='terraform state' +alias tft='terraform test' +alias tfsh='terraform show' diff --git a/plugins/thor/README.md b/plugins/thor/README.md index 09c705d9a..484c88b84 100644 --- a/plugins/thor/README.md +++ b/plugins/thor/README.md @@ -1,6 +1,6 @@ # Thor plugin -This plugin adds completion for [Thor](http://whatisthor.com/), +This plugin adds completion for [Thor](http://whatisthor.com/), a ruby toolkit for building powerful command-line interfaces. To use it, add `thor` to the plugins array in your zshrc file: diff --git a/plugins/tig/tig.plugin.zsh b/plugins/tig/tig.plugin.zsh index 7e0c530ac..5b7d2550a 100644 --- a/plugins/tig/tig.plugin.zsh +++ b/plugins/tig/tig.plugin.zsh @@ -1,3 +1,5 @@ alias tis='tig status' alias til='tig log' alias tib='tig blame -C' +alias tif='tig reflog' +alias tia='tig --all' diff --git a/plugins/tmux/README.md b/plugins/tmux/README.md index 7348f77c9..09952a9f5 100644 --- a/plugins/tmux/README.md +++ b/plugins/tmux/README.md @@ -1,7 +1,7 @@ # tmux -This plugin provides aliases for [tmux](https://tmux.github.io/), the terminal multiplexer. -To use it add `tmux` to the plugins array in your zshrc file. +This plugin provides aliases for [tmux](https://tmux.github.io/), the terminal multiplexer. To use it add +`tmux` to the plugins array in your zshrc file. ```zsh plugins=(... tmux) @@ -19,25 +19,28 @@ The plugin also supports the following: | ---------- | -------------------------- | -------------------------------------------------------- | | `ta` | tmux attach -t | Attach new tmux session to already running named session | | `tad` | tmux attach -d -t | Detach named tmux session | -| `ts` | tmux new-session -s | Create a new named tmux session | -| `tl` | tmux list-sessions | Displays a list of running tmux sessions | -| `tksv` | tmux kill-server | Terminate all running tmux sessions | +| `tds` | `_tmux_directory_session` | Creates or attaches to a session for the current path | | `tkss` | tmux kill-session -t | Terminate named running tmux session | +| `tksv` | tmux kill-server | Terminate all running tmux sessions | +| `tl` | tmux list-sessions | Displays a list of running tmux sessions | | `tmux` | `_zsh_tmux_plugin_run` | Start a new tmux session | | `tmuxconf` | `$EDITOR $ZSH_TMUX_CONFIG` | Open .tmux.conf file with an editor | +| `ts` | tmux new-session -s | Create a new named tmux session | ## Configuration Variables -| Variable | Description | -| ----------------------------------- | ----------------------------------------------------------------------------- | -| `ZSH_TMUX_AUTOSTART` | Automatically starts tmux (default: `false`) | -| `ZSH_TMUX_AUTOSTART_ONCE` | Autostart only if tmux hasn't been started previously (default: `true`) | -| `ZSH_TMUX_AUTOCONNECT` | Automatically connect to a previous session if it exits (default: `true`) | -| `ZSH_TMUX_AUTOQUIT` | Automatically closes terminal once tmux exits (default: `ZSH_TMUX_AUTOSTART`) | -| `ZSH_TMUX_FIXTERM` | Sets `$TERM` to 256-color term or not based on current terminal support | -| `ZSH_TMUX_ITERM2` | Sets the `-CC` option for iTerm2 tmux integration (default: `false`) | -| `ZSH_TMUX_FIXTERM_WITHOUT_256COLOR` | `$TERM` to use for non 256-color terminals (default: `screen`) | -| `ZSH_TMUX_FIXTERM_WITH_256COLOR` | `$TERM` to use for 256-color terminals (default: `screen-256color` | -| `ZSH_TMUX_CONFIG` | Set the configuration path (default: `$HOME/.tmux.conf`) | -| `ZSH_TMUX_UNICODE` | Set `tmux -u` option to support unicode | -| `ZSH_TMUX_DEFAULT_SESSION_NAME` | Set tmux default session name when autostart is enabled | +| Variable | Description | +| ----------------------------------- | ----------------------------------------------------------------------------------------------------------- | +| `ZSH_TMUX_AUTOSTART` | Automatically starts tmux (default: `false`) | +| `ZSH_TMUX_AUTOSTART_ONCE` | Autostart only if tmux hasn't been started previously (default: `true`) | +| `ZSH_TMUX_AUTOCONNECT` | Automatically connect to a previous session if it exits (default: `true`) | +| `ZSH_TMUX_AUTOQUIT` | Automatically closes terminal once tmux exits (default: `ZSH_TMUX_AUTOSTART`) | +| `ZSH_TMUX_CONFIG` | Set the configuration path (default: `$HOME/.tmux.conf`, `$XDG_CONFIG_HOME/tmux/tmux.conf`) | +| `ZSH_TMUX_DEFAULT_SESSION_NAME` | Set tmux default session name when autostart is enabled | +| `ZSH_TMUX_AUTONAME_SESSION` | Automatically name new sessions based on the basename of `$PWD` (default: `false`) | +| `ZSH_TMUX_DETACHED` | Set the detached mode (default: `false`) | +| `ZSH_TMUX_FIXTERM` | Sets `$TERM` to 256-color term or not based on current terminal support | +| `ZSH_TMUX_FIXTERM_WITHOUT_256COLOR` | `$TERM` to use for non 256-color terminals (default: `tmux` if available, `screen` otherwise) | +| `ZSH_TMUX_FIXTERM_WITH_256COLOR` | `$TERM` to use for 256-color terminals (default: `tmux-256color` if available, `screen-256color` otherwise) | +| `ZSH_TMUX_ITERM2` | Sets the `-CC` option for iTerm2 tmux integration (default: `false`) | +| `ZSH_TMUX_UNICODE` | Set `tmux -u` option to support unicode | diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh index 311c2e6a9..f65598358 100644 --- a/plugins/tmux/tmux.plugin.zsh +++ b/plugins/tmux/tmux.plugin.zsh @@ -13,33 +13,63 @@ fi : ${ZSH_TMUX_AUTOCONNECT:=true} # Automatically close the terminal when tmux exits : ${ZSH_TMUX_AUTOQUIT:=$ZSH_TMUX_AUTOSTART} +# Automatically name the new session based on the basename of PWD +: ${ZSH_TMUX_AUTONAME_SESSION:=false} # Set term to screen or screen-256color based on current terminal support +: ${ZSH_TMUX_DETACHED:=false} +# Set detached mode : ${ZSH_TMUX_FIXTERM:=true} # Set '-CC' option for iTerm2 tmux integration : ${ZSH_TMUX_ITERM2:=false} # The TERM to use for non-256 color terminals. -# Tmux states this should be screen, but you may need to change it on +# Tmux states this should be tmux|screen, but you may need to change it on # systems without the proper terminfo -: ${ZSH_TMUX_FIXTERM_WITHOUT_256COLOR:=screen} +if [[ -e /usr/share/terminfo/t/tmux ]]; then + : ${ZSH_TMUX_FIXTERM_WITHOUT_256COLOR:=tmux} +else + : ${ZSH_TMUX_FIXTERM_WITHOUT_256COLOR:=screen} +fi # The TERM to use for 256 color terminals. -# Tmux states this should be screen-256color, but you may need to change it on +# Tmux states this should be (tmux|screen)-256color, but you may need to change it on # systems without the proper terminfo -: ${ZSH_TMUX_FIXTERM_WITH_256COLOR:=screen-256color} +if [[ -e /usr/share/terminfo/t/tmux-256color ]]; then + : ${ZSH_TMUX_FIXTERM_WITH_256COLOR:=tmux-256color} +else + : ${ZSH_TMUX_FIXTERM_WITH_256COLOR:=screen-256color} +fi # Set the configuration path -: ${ZSH_TMUX_CONFIG:=$HOME/.tmux.conf} +if [[ -e $HOME/.tmux.conf ]]; then + : ${ZSH_TMUX_CONFIG:=$HOME/.tmux.conf} +elif [[ -e ${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf ]]; then + : ${ZSH_TMUX_CONFIG:=${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf} +else + : ${ZSH_TMUX_CONFIG:=$HOME/.tmux.conf} +fi # Set -u option to support unicode : ${ZSH_TMUX_UNICODE:=false} # ALIASES +function _build_tmux_alias { + eval "function $1 { + if [[ -z \$1 ]] || [[ \${1:0:1} == '-' ]]; then + tmux $2 \"\$@\" + else + tmux $2 $3 \"\$@\" + fi + }" +} -alias ta='tmux attach -t' -alias tad='tmux attach -d -t' -alias ts='tmux new-session -s' -alias tl='tmux list-sessions' alias tksv='tmux kill-server' -alias tkss='tmux kill-session -t' +alias tl='tmux list-sessions' alias tmuxconf='$EDITOR $ZSH_TMUX_CONFIG' +_build_tmux_alias "ta" "attach" "-t" +_build_tmux_alias "tad" "attach -d" "-t" +_build_tmux_alias "ts" "new-session" "-s" +_build_tmux_alias "tkss" "kill-session" "-t" + +unfunction _build_tmux_alias + # Determine if the terminal supports 256 colors if [[ $terminfo[colors] == 256 ]]; then export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITH_256COLOR @@ -72,11 +102,26 @@ function _zsh_tmux_plugin_run() { [[ "$ZSH_TMUX_ITERM2" == "true" ]] && tmux_cmd+=(-CC) [[ "$ZSH_TMUX_UNICODE" == "true" ]] && tmux_cmd+=(-u) - # Try to connect to an existing session. - if [[ -n "$ZSH_TMUX_DEFAULT_SESSION_NAME" ]]; then - [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] && $tmux_cmd attach -t $ZSH_TMUX_DEFAULT_SESSION_NAME + local _detached="" + [[ "$ZSH_TMUX_DETACHED" == "true" ]] && _detached="-d" + + local session_name + if [[ "$ZSH_TMUX_AUTONAME_SESSION" == "true" ]]; then + # Name the session after the basename of the current directory + session_name=${PWD##*/} + # If the current directory is the home directory, name it 'HOME' + [[ "$PWD" == "$HOME" ]] && session_name="HOME" + # If the current directory is the root directory, name it 'ROOT' + [[ "$PWD" == "/" ]] && session_name="ROOT" else - [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] && $tmux_cmd attach + session_name="$ZSH_TMUX_DEFAULT_SESSION_NAME" + fi + + # Try to connect to an existing session. + if [[ -n "$session_name" ]]; then + [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] && $tmux_cmd attach $_detached -t "$session_name" + else + [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] && $tmux_cmd attach $_detached fi # If failed, just run tmux, fixing the TERM variable if requested. @@ -86,8 +131,9 @@ function _zsh_tmux_plugin_run() { elif [[ -e "$ZSH_TMUX_CONFIG" ]]; then tmux_cmd+=(-f "$ZSH_TMUX_CONFIG") fi - if [[ -n "$ZSH_TMUX_DEFAULT_SESSION_NAME" ]]; then - $tmux_cmd new-session -s $ZSH_TMUX_DEFAULT_SESSION_NAME + + if [[ -n "$session_name" ]]; then + $tmux_cmd new-session -s "$session_name" else $tmux_cmd new-session fi @@ -103,8 +149,21 @@ compdef _tmux _zsh_tmux_plugin_run # Alias tmux to our wrapper function. alias tmux=_zsh_tmux_plugin_run +function _tmux_directory_session() { + # current directory without leading path + local dir=${PWD##*/} + # md5 hash for the full working directory path + local md5=$(printf '%s' "$PWD" | md5sum | cut -d ' ' -f 1) + # human friendly unique session name for this directory + local session_name="${dir}-${md5:0:6}" + # create or attach to the session + tmux new -As "$session_name" +} + +alias tds=_tmux_directory_session + # Autostart if not already in tmux and enabled. -if [[ -z "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" && -z "$INSIDE_EMACS" && -z "$EMACS" && -z "$VIM" ]]; then +if [[ -z "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" && -z "$INSIDE_EMACS" && -z "$EMACS" && -z "$VIM" && -z "$INTELLIJ_ENVIRONMENT_READER" ]]; then # Actually don't autostart if we already did and multiple autostarts are disabled. if [[ "$ZSH_TMUX_AUTOSTART_ONCE" == "false" || "$ZSH_TMUX_AUTOSTARTED" != "true" ]]; then export ZSH_TMUX_AUTOSTARTED=true diff --git a/plugins/ubuntu/README.md b/plugins/ubuntu/README.md index 2401c102b..20f5c65ee 100644 --- a/plugins/ubuntu/README.md +++ b/plugins/ubuntu/README.md @@ -15,7 +15,7 @@ Commands that use `$APT` will use `apt` if installed or defer to `apt-get` other | Alias | Command | Description | |---------|--------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------| | age | `sudo $APT` | Run apt-get with sudo | -| acse | `apt-cache search` | Search the apt-cache with the specified criteria | +| acs | `apt-cache search` | Search the apt-cache with the specified criteria | | acsp | `apt-cache showpkg` | Shows information about the listed packages | | acp | `apt-cache policy` | Display the package source priorities | | afs | `apt-file search --regexp` | Perform a regular expression apt-file search | diff --git a/plugins/ubuntu/ubuntu.plugin.zsh b/plugins/ubuntu/ubuntu.plugin.zsh index 4d35da2ac..7b765a406 100644 --- a/plugins/ubuntu/ubuntu.plugin.zsh +++ b/plugins/ubuntu/ubuntu.plugin.zsh @@ -1,6 +1,6 @@ (( $+commands[apt] )) && APT=apt || APT=apt-get -alias acse='apt-cache search' +alias acs='apt-cache search' alias afs='apt-file search --regexp' diff --git a/plugins/ufw/README.md b/plugins/ufw/README.md index ac377cd17..ffcc6d6f7 100644 --- a/plugins/ufw/README.md +++ b/plugins/ufw/README.md @@ -10,7 +10,7 @@ plugins=(... ufw) Some of the commands include: -* `allow /` add an allow rule +* `allow /` add an allow rule * `default` set default policy * `delete /` delete RULE * `deny /` add deny rule diff --git a/plugins/vagrant-prompt/README.md b/plugins/vagrant-prompt/README.md index c5bc55d17..dd0ca363b 100644 --- a/plugins/vagrant-prompt/README.md +++ b/plugins/vagrant-prompt/README.md @@ -1,6 +1,6 @@ This plugin prompts the status of the Vagrant VMs. It supports single-host and multi-host configurations as well. -Look inside the source for documentation about custom variables. +Look inside the source for documentation about custom variables. Alberto Re diff --git a/plugins/vi-mode/README.md b/plugins/vi-mode/README.md index 0cb516751..6e781f296 100644 --- a/plugins/vi-mode/README.md +++ b/plugins/vi-mode/README.md @@ -37,6 +37,8 @@ plugins=(... vi-mode) - `INSERT_MODE_INDICATOR`: controls the string displayed when the shell is in insert mode. See [Mode indicators](#mode-indicators) for details. +- `VI_MODE_DISABLE_CLIPBOARD`: If set, disables clipboard integration on yank/paste + ## Mode indicators *Normal mode* is indicated with a red `<<<` mark at the right prompt, when it @@ -53,7 +55,7 @@ INSERT_MODE_INDICATOR="%F{yellow}+%f" ### Adding mode indicators to your prompt -`Vi-mode` by default will add mode indicators to `RPROMPT` **unless** that is defined by +`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. @@ -144,11 +146,17 @@ NOTE: this used to be bound to `v`. That is now the default (`visual-mode`). - `c{motion}` : Delete {motion} text and start insert - `cc` : Delete line and start insert - `C` : Delete to the end of the line and start insert +- `P` : Insert the contents of the clipboard before the cursor +- `p` : Insert the contents of the clipboard after the cursor - `r{char}` : Replace the character under the cursor with {char} - `R` : Enter replace mode: Each character replaces existing one - `x` : Delete `count` characters under and after the cursor - `X` : Delete `count` characters before the cursor +NOTE: delete/kill commands (`dd`, `D`, `c{motion}`, `C`, `x`,`X`) and yank commands +(`y`, `Y`) will copy to the clipboard. Contents can then be put back using paste commands +(`P`, `p`). + ## Known issues ### Low `$KEYTIMEOUT` diff --git a/plugins/vi-mode/vi-mode.plugin.zsh b/plugins/vi-mode/vi-mode.plugin.zsh index cc9817a74..5c104f7bb 100644 --- a/plugins/vi-mode/vi-mode.plugin.zsh +++ b/plugins/vi-mode/vi-mode.plugin.zsh @@ -147,9 +147,19 @@ function wrap_clipboard_widgets() { done } -wrap_clipboard_widgets copy vi-yank vi-yank-eol vi-backward-kill-word vi-change-whole-line vi-delete vi-delete-char -wrap_clipboard_widgets paste vi-put-{before,after} -unfunction wrap_clipboard_widgets +if [[ -z "${VI_MODE_DISABLE_CLIPBOARD:-}" ]]; then + wrap_clipboard_widgets copy \ + vi-yank vi-yank-eol vi-yank-whole-line \ + vi-change vi-change-eol vi-change-whole-line \ + vi-kill-line vi-kill-eol vi-backward-kill-word \ + vi-delete vi-delete-char vi-backward-delete-char + + wrap_clipboard_widgets paste \ + vi-put-{before,after} \ + put-replace-selection + + unfunction wrap_clipboard_widgets +fi # if mode indicator wasn't setup by theme, define default, we'll leave INSERT_MODE_INDICATOR empty by default if [[ -z "$MODE_INDICATOR" ]]; then diff --git a/plugins/vim-interaction/README.md b/plugins/vim-interaction/README.md index 681648018..c2b45f1d8 100644 --- a/plugins/vim-interaction/README.md +++ b/plugins/vim-interaction/README.md @@ -3,7 +3,7 @@ The plugin presents a function called `callvim` whose usage is: usage: callvim [-b cmd] [-a cmd] [file ... fileN] - + -b cmd Run this command in GVIM before editing the first file -a cmd Run this command in GVIM after editing the first file file The file to edit diff --git a/plugins/vim-interaction/vim-interaction.plugin.zsh b/plugins/vim-interaction/vim-interaction.plugin.zsh index b73f9b4da..a12b52bd5 100644 --- a/plugins/vim-interaction/vim-interaction.plugin.zsh +++ b/plugins/vim-interaction/vim-interaction.plugin.zsh @@ -2,7 +2,7 @@ # See README.md # # Derek Wyatt (derek@{myfirstnamemylastname}.org -# +# function callvim { if [[ $# == 0 ]]; then diff --git a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh index d359e0c21..1a3ae37b8 100644 --- a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh +++ b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh @@ -52,7 +52,7 @@ if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then else ENV_NAME="" fi - + if [[ -n $CD_VIRTUAL_ENV && "$ENV_NAME" != "$CD_VIRTUAL_ENV" ]]; then # We've just left the repo, deactivate the environment # Note: this only happens if the virtualenv was activated automatically @@ -88,4 +88,5 @@ if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then # http://zsh.sourceforge.net/Doc/Release/Functions.html autoload -U add-zsh-hook add-zsh-hook chpwd workon_cwd + [[ $PWD != ~ ]] && workon_cwd fi diff --git a/plugins/vscode/README.md b/plugins/vscode/README.md index e95ed5d4f..f91b533c9 100644 --- a/plugins/vscode/README.md +++ b/plugins/vscode/README.md @@ -1,6 +1,7 @@ # VS Code -This plugin provides useful aliases to simplify the interaction between the command line and VS Code or VSCodium editor. +This plugin provides useful aliases to simplify the interaction between the command line and VS Code or +VSCodium editor. To start using it, add the `vscode` plugin to your `plugins` array in `~/.zshrc`: @@ -14,26 +15,30 @@ This plugin requires to have a flavour of VS Code installed and it's executable You can install either: -* VS Code (code) -* VS Code Insiders (code-insiders) -* VSCodium (codium) +- VS Code (code) +- VS Code Insiders (code-insiders) +- VSCodium (codium) ### MacOS + While Linux installations will add the executable to PATH, MacOS users might still have to do this manually: -[For VS Code and VS Code Insiders](https://code.visualstudio.com/docs/setup/mac#_launching-from-the-command-line), open -the Command Palette via (F1 or ⇧⌘P) and type shell command to find the Shell Command: +[For VS Code and VS Code Insiders](https://code.visualstudio.com/docs/setup/mac#_launching-from-the-command-line), +open the Command Palette via (F1 or ⇧⌘P) and type shell command to find the Shell Command: + > Shell Command: Install 'code' command in PATH -[For VSCodium](https://github.com/VSCodium/vscodium/blob/master/DOCS.md#how-do-i-open-vscodium-from-the-terminal), open -the Command Palette via (F1 or ⇧⌘P) and type shell command to find the Shell Command: +[For VSCodium](https://github.com/VSCodium/vscodium/blob/master/DOCS.md#how-do-i-open-vscodium-from-the-terminal), +open the Command Palette via (F1 or ⇧⌘P) and type shell command to find the Shell Command: + > Shell Command: Install 'codium' command in PATH ## Using multiple flavours -If for any reason, you ever require to use multiple flavours of VS Code i.e. VS Code (stable) and VS Code Insiders, you can -manually specify the flavour's executable. Add the following line to the .zshrc file (between the `ZSH_THEME` and the `plugins=()` lines). -This will make the plugin use your manually defined executable. +If for any reason, you ever require to use multiple flavours of VS Code i.e. VS Code (stable) and VS Code +Insiders, you can manually specify the flavour's executable. Add the following line to the .zshrc file +(between the `ZSH_THEME` and the `plugins=()` lines). This will make the plugin use your manually defined +executable. ```zsh ZSH_THEME=... @@ -53,6 +58,7 @@ source $ZSH/oh-my-zsh.sh | Alias | Command | Description | | ----------------------- | ------------------------------ | ----------------------------------------------------------------------------------------------------------- | | vsc | code . | Open the current folder in VS code | +| vsc `dir` | code `dir` | Open passed folder in VS code | | vsca `dir` | code --add `dir` | Add folder(s) to the last active window | | vscd `file` `file` | code --diff `file` `file` | Compare two files with each other. | | vscg `file:line[:char]` | code --goto `file:line[:char]` | Open a file at the path on the specified line and character position. | @@ -60,6 +66,7 @@ source $ZSH/oh-my-zsh.sh | vscr | code --reuse-window | Force to open a file or folder in the last active window. | | vscw | code --wait | Wait for the files to be closed before returning. | | vscu `dir` | code --user-data-dir `dir` | Specifies the directory that user data is kept in. Can be used to open multiple distinct instances of Code. | +| vscp `profile` | code --profile `profile` | Specifies the profile to open Code with. | ## Extensions aliases diff --git a/plugins/vscode/vscode.plugin.zsh b/plugins/vscode/vscode.plugin.zsh index 48d904377..77367bcac 100644 --- a/plugins/vscode/vscode.plugin.zsh +++ b/plugins/vscode/vscode.plugin.zsh @@ -3,6 +3,7 @@ # https://github.com/MarsiBarsi (original author) # https://github.com/babakks # https://github.com/SteelShot +# https://github.com/AliSajid # Verify if any manual user choice of VS Code exists first. if [[ -n "$VSCODE" ]] && ! which $VSCODE &>/dev/null; then @@ -23,7 +24,14 @@ if [[ -z "$VSCODE" ]]; then fi fi -alias vsc="$VSCODE ." +function vsc { + if (( $# )); then + $VSCODE $@ + else + $VSCODE . + fi +} + alias vsca="$VSCODE --add" alias vscd="$VSCODE --diff" alias vscg="$VSCODE --goto" @@ -31,6 +39,7 @@ alias vscn="$VSCODE --new-window" alias vscr="$VSCODE --reuse-window" alias vscw="$VSCODE --wait" alias vscu="$VSCODE --user-data-dir" +alias vscp="$VSCODE --profile" alias vsced="$VSCODE --extensions-dir" alias vscie="$VSCODE --install-extension" diff --git a/plugins/wd/README.md b/plugins/wd/README.md index 1d1980632..0ad74e805 100644 --- a/plugins/wd/README.md +++ b/plugins/wd/README.md @@ -153,7 +153,7 @@ wd .. wd ... ``` -This is a wrapper for the zsh's `dirs` function. +This is a wrapper for the zsh's `dirs` function. _You might need to add `setopt AUTO_PUSHD` to your `.zshrc` if you are not using [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh)._ * Remove warp point: diff --git a/plugins/wd/_wd.sh b/plugins/wd/_wd.sh index 8d5cf15a2..52ecb12e6 100644 --- a/plugins/wd/_wd.sh +++ b/plugins/wd/_wd.sh @@ -77,7 +77,7 @@ function _wd() { # complete sub directories from the warp point _path_files -W "(${points[$target]})" -/ && ret=0 fi - + # don't complete anything if warp point is not valid ;; esac diff --git a/plugins/wd/wd.sh b/plugins/wd/wd.sh index e51cf906a..840e92d61 100644 --- a/plugins/wd/wd.sh +++ b/plugins/wd/wd.sh @@ -396,7 +396,7 @@ fi # disable extendedglob for the complete wd execution time setopt | grep -q extendedglob wd_extglob_is_set=$? -[[ $wd_extglob_is_set ]] && setopt noextendedglob +(( ! $wd_extglob_is_set )) && setopt noextendedglob # load warp points typeset -A points @@ -484,7 +484,7 @@ fi # if not, next time warp will pick up variables from this run # remember, there's no sub shell -[[ $wd_extglob_is_set ]] && setopt extendedglob +(( ! $wd_extglob_is_set )) && setopt extendedglob unset wd_extglob_is_set unset wd_warp diff --git a/plugins/web-search/README.md b/plugins/web-search/README.md index 0bf9f26ad..d21c81ca9 100644 --- a/plugins/web-search/README.md +++ b/plugins/web-search/README.md @@ -12,8 +12,8 @@ plugins=( ... web-search) You can use the `web-search` plugin in these two forms: -* `web_search [more terms if you want]` -* ` [more terms if you want]` +- `web_search [more terms if you want]` +- ` [more terms if you want]` For example, these two are equivalent: @@ -24,43 +24,47 @@ $ google oh-my-zsh Available search contexts are: -| Context | URL | -| --------------------- | ---------------------------------------- | -| `bing` | `https://www.bing.com/search?q=` | -| `google` | `https://www.google.com/search?q=` | -| `brs` or `brave` | `https://search.brave.com/search?q=` | -| `yahoo` | `https://search.yahoo.com/search?p=` | -| `ddg` or `duckduckgo` | `https://www.duckduckgo.com/?q=` | -| `sp` or `startpage` | `https://www.startpage.com/do/search?q=` | -| `yandex` | `https://yandex.ru/yandsearch?text=` | -| `github` | `https://github.com/search?q=` | -| `baidu` | `https://www.baidu.com/s?wd=` | -| `ecosia` | `https://www.ecosia.org/search?q=` | -| `goodreads` | `https://www.goodreads.com/search?q=` | -| `qwant` | `https://www.qwant.com/?q=` | -| `givero` | `https://www.givero.com/search?q=` | -| `stackoverflow` | `https://stackoverflow.com/search?q=` | -| `wolframalpha` | `https://wolframalpha.com/input?i=` | -| `archive` | `https://web.archive.org/web/*/` | -| `scholar` | `https://scholar.google.com/scholar?q=` | -| `ask` | `https://www.ask.com/web?q=` | +| Context | URL | +| --------------------- | ----------------------------------------------- | +| `bing` | `https://www.bing.com/search?q=` | +| `google` | `https://www.google.com/search?q=` | +| `brs` or `brave` | `https://search.brave.com/search?q=` | +| `yahoo` | `https://search.yahoo.com/search?p=` | +| `ddg` or `duckduckgo` | `https://www.duckduckgo.com/?q=` | +| `sp` or `startpage` | `https://www.startpage.com/do/search?q=` | +| `yandex` | `https://yandex.ru/yandsearch?text=` | +| `github` | `https://github.com/search?q=` | +| `baidu` | `https://www.baidu.com/s?wd=` | +| `ecosia` | `https://www.ecosia.org/search?q=` | +| `goodreads` | `https://www.goodreads.com/search?q=` | +| `qwant` | `https://www.qwant.com/?q=` | +| `givero` | `https://www.givero.com/search?q=` | +| `stackoverflow` | `https://stackoverflow.com/search?q=` | +| `wolframalpha` | `https://wolframalpha.com/input?i=` | +| `archive` | `https://web.archive.org/web/*/` | +| `scholar` | `https://scholar.google.com/scholar?q=` | +| `ask` | `https://www.ask.com/web?q=` | +| `youtube` | `https://www.youtube.com/results?search_query=` | +| `deepl` | `https://www.deepl.com/translator#auto/auto/` | +| `dockerhub` | `https://hub.docker.com/search?q=` | +| `npmpkg` | `https://www.npmjs.com/search?q=` | +| `packagist` | `https://packagist.org/?query=` | +| `gopkg` | `https://pkg.go.dev/search?m=package&q=` | Also there are aliases for bang-searching DuckDuckGo: | Context | Bang | -|-----------|-------| +| --------- | ----- | | `wiki` | `!w` | | `news` | `!n` | -| `youtube` | `!yt` | | `map` | `!m` | | `image` | `!i` | | `ducky` | `!` | ### Custom search engines -If you want to add other search contexts to the plugin, you can use the -`$ZSH_WEB_SEARCH_ENGINES` variable. Set it before Oh My Zsh is sourced, -with the following format: +If you want to add other search contexts to the plugin, you can use the `$ZSH_WEB_SEARCH_ENGINES` variable. +Set it before Oh My Zsh is sourced, with the following format: ```zsh ZSH_WEB_SEARCH_ENGINES=( @@ -69,13 +73,12 @@ ZSH_WEB_SEARCH_ENGINES=( ) ``` -where `` is the name of the search context, and `` a URL of -the same type as the search contexts above. For example, to add `reddit`, -you'd do: +where `` is the name of the search context, and `` a URL of the same type as the search contexts +above. For example, to add `reddit`, you'd do: ```zsh ZSH_WEB_SEARCH_ENGINES=(reddit "https://www.reddit.com/search/?q=") ``` -These custom search engines will also be turned to aliases, so you can -both do `web_search reddit ` or `reddit `. +These custom search engines will also be turned to aliases, so you can both do `web_search reddit ` or +`reddit `. diff --git a/plugins/web-search/web-search.plugin.zsh b/plugins/web-search/web-search.plugin.zsh index ec176dd68..c602e0623 100644 --- a/plugins/web-search/web-search.plugin.zsh +++ b/plugins/web-search/web-search.plugin.zsh @@ -25,6 +25,12 @@ function web_search() { archive "https://web.archive.org/web/*/" scholar "https://scholar.google.com/scholar?q=" ask "https://www.ask.com/web?q=" + youtube "https://www.youtube.com/results?search_query=" + deepl "https://www.deepl.com/translator#auto/auto/" + dockerhub "https://hub.docker.com/search?q=" + npmpkg "https://www.npmjs.com/search?q=" + packagist "https://packagist.org/?query=" + gopkg "https://pkg.go.dev/search?m=package&q=" ) # check whether the search engine is supported @@ -35,9 +41,14 @@ function web_search() { # search or go to main page depending on number of arguments passed if [[ $# -gt 1 ]]; then + # if search goes in the query string ==> space as +, otherwise %20 + # see https://stackoverflow.com/questions/1634271/url-encoding-the-space-character-or-20 + local param="-P" + [[ "$urls[$1]" == *\?*= ]] && param="" + # build search url: # join arguments passed with '+', then append to search engine URL - url="${urls[$1]}$(omz_urlencode ${@[2,-1]})" + url="${urls[$1]}$(omz_urlencode $param ${@[2,-1]})" else # build main page url: # split by '/', then rejoin protocol (1) and domain (2) parts with '//' @@ -66,11 +77,16 @@ alias wolframalpha='web_search wolframalpha' alias archive='web_search archive' alias scholar='web_search scholar' alias ask='web_search ask' +alias youtube='web_search youtube' +alias deepl='web_search deepl' +alias dockerhub='web_search dockerhub' +alias npmpkg='web_search npmpkg' +alias packagist='web_search packagist' +alias gopkg='web_search gopkg' #add your own !bang searches here alias wiki='web_search duckduckgo \!w' alias news='web_search duckduckgo \!n' -alias youtube='web_search duckduckgo \!yt' alias map='web_search duckduckgo \!m' alias image='web_search duckduckgo \!i' alias ducky='web_search duckduckgo \!' diff --git a/plugins/xcode/xcode.plugin.zsh b/plugins/xcode/xcode.plugin.zsh index 5d1f901a3..f09434e69 100644 --- a/plugins/xcode/xcode.plugin.zsh +++ b/plugins/xcode/xcode.plugin.zsh @@ -17,6 +17,13 @@ function xc { local active_path active_path=${"$(xcode-select -p)"%%/Contents/Developer*} echo "Found ${xcode_files[1]}. Opening with ${active_path}" + + # If Xcode is already opened in another Desk, we need this double call + # with -g to open the project window in the current Desk and focus it. + # See https://github.com/ohmyzsh/ohmyzsh/issues/10384 + if command pgrep -q "^Xcode"; then + open -g -a "$active_path" "${xcode_files[1]}" + fi open -a "$active_path" "${xcode_files[1]}" } diff --git a/plugins/yarn/_yarn b/plugins/yarn/_yarn index 1237ba672..9ffe5660c 100644 --- a/plugins/yarn/_yarn +++ b/plugins/yarn/_yarn @@ -86,7 +86,7 @@ _global_commands=( ) _yarn_find_package_json() { - local dir=$(cd "$1" && pwd) + local dir=$(builtin cd "$1" && pwd) while true do @@ -109,7 +109,7 @@ _yarn_commands_scripts() { if [[ -n $opt_args[--cwd] ]]; then packageJson=$(_yarn_find_package_json $opt_args[--cwd]) - binaries=($(cd $opt_args[--cwd] && echo node_modules/.bin/*(x:t))) + binaries=($(builtin cd $opt_args[--cwd] && echo node_modules/.bin/*(x:t))) else packageJson=$(_yarn_find_package_json $pwd) binaries=($(echo node_modules/.bin/*(x:t))) @@ -130,9 +130,9 @@ _yarn_scripts() { if [[ -n $_yarn_run_cwd ]]; then packageJson=$(_yarn_find_package_json $_yarn_run_cwd) if [[ -d "${_yarn_run_cwd}/node_modules" ]]; then - binaries=($(cd $_yarn_run_cwd && echo node_modules/.bin/*(x:t))) + binaries=($(builtin cd $_yarn_run_cwd && echo node_modules/.bin/*(x:t))) else - binaries=($(cd $_yarn_run_cwd && yarn bin | perl -wln -e 'm{^[^:]+: (\S+)$} and print $1')) + binaries=($(builtin cd $_yarn_run_cwd && yarn bin | perl -wln -e 'm{^[^:]+: (\S+)$} and print $1')) fi else packageJson=$(_yarn_find_package_json $pwd) @@ -144,7 +144,7 @@ _yarn_scripts() { fi if [[ -n $packageJson ]]; then - scripts=("${(@f)$(cat ${packageJson} | perl -0777 -MJSON::PP -n -E '%r=%{decode_json($_)->{scripts}}; do{$k=$_;($e=$k)=~s/:/\\:/g; printf "$e:$r{$k}\n"} for sort keys %r')}") + scripts=("${(@f)$(cat ${packageJson} | perl -0777 -MJSON::PP -n -E 'binmode(STDOUT, ":encoding(UTF-8)"); %r=%{decode_json($_)->{scripts}}; do{$k=$_;($e=$k)=~s/:/\\:/g; printf "$e:$r{$k}\n"} for sort keys %r')}") fi commands=('env' $scripts $binaries) diff --git a/plugins/z/MANUAL.md b/plugins/z/MANUAL.md index d367c3026..106d8c107 100644 --- a/plugins/z/MANUAL.md +++ b/plugins/z/MANUAL.md @@ -4,6 +4,8 @@ ![Zsh version 4.3.11 and higher](img/zsh_4.3.11_plus.svg) [![GitHub stars](https://img.shields.io/github/stars/agkozak/zsh-z.svg)](https://github.com/agkozak/zsh-z/stargazers) +![Zsh-z demo](img/demo.gif) + Zsh-z is a command line tool that allows you to jump quickly to directories that you have visited frequently in the past, or recently -- but most often a combination of the two (a concept known as ["frecency"](https://en.wikipedia.org/wiki/Frecency)). It works by keeping track of when you go to directories and how much time you spend in them. It is then in the position to guess where you want to go when you type a partial string, e.g., `z src` might take you to `~/src/zsh`. `z zsh` might also get you there, and `z c/z` might prove to be even more specific -- it all depends on your habits and how much time you have been using Zsh-z to build up a database. After using Zsh-z for a little while, you will get to where you want to be by typing considerably less than you would need if you were using `cd`. Zsh-z is a native Zsh port of [rupa/z](https://github.com/rupa/z), a tool written for `bash` and Zsh that uses embedded `awk` scripts to do the heavy lifting. It was quite possibly my most used command line tool for a couple of years. I decided to translate it, `awk` parts and all, into pure Zsh script, to see if by eliminating calls to external tools (`awk`, `sort`, `date`, `sed`, `mv`, `rm`, and `chown`) and reducing forking through subshells I could make it faster. The performance increase is impressive, particularly on systems where forking is slow, such as Cygwin, MSYS2, and WSL. I have found that, in those environments, switching directories using Zsh-z can be over 100% faster than it is using `rupa/z`. @@ -32,6 +34,12 @@ Zsh-z is a drop-in replacement for `rupa/z` and will, by default, use the same d
Here are the latest features and updates. +- August 24, 2023 + + Zsh-z will now run when `setopt NO_UNSET` has been enabled (props @ntninja). +- August 23, 2023 + + Better logic for loading `zsh/files` (props @z0rc) +- August 2, 2023 + + Zsh-z still uses the `zsh/files` module when possible, but will fall back on the standard `chown`, `mv`, and `rm` commands in its absence. - April 27, 2023 + Zsh-z now allows the user to specify the directory-changing command using the `ZSHZ_CD` environment variable (default: `builtin cd`; props @basnijholt). - January 27, 2023 @@ -64,7 +72,7 @@ Zsh-z is a drop-in replacement for `rupa/z` and will, by default, use the same d + Temporarily disabling use of `print -v`, which seems to be mangling CJK multibyte strings. - July 27, 2021 + Internal escaping of path names now works with older versions of ZSH. - + Zsh-z now detects and discards any incomplete or incorrectly formattted database entries. + + Zsh-z now detects and discards any incomplete or incorrectly formatted database entries. - July 10, 2021 + Setting `ZSHZ_TRAILING_SLASH=1` makes it so that a search pattern ending in `/` can match the end of a path; e.g. `z foo/` can match `/path/to/foo`. - June 25, 2021 @@ -85,7 +93,7 @@ Zsh-z is a drop-in replacement for `rupa/z` and will, by default, use the same d - January 11, 2021 + Major refactoring of the code. + `z -lr` and `z -lt` work as expected. - + `EXTENDED_GLOB` has been disabled within the plugin to accomodate old-fashioned Windows directories with names such as `Progra~1`. + + `EXTENDED_GLOB` has been disabled within the plugin to accommodate old-fashioned Windows directories with names such as `Progra~1`. + Removed `zshelldoc` documentation. - January 6, 2021 + I have corrected the frecency routine so that it matches `rupa/z`'s math, but for the present, Zsh-z will continue to display ranks as 1/10000th of what they are in `rupa/z` -- [they had to multiply theirs by 10000](https://github.com/rupa/z/commit/f1f113d9bae9effaef6b1e15853b5eeb445e0712) to work around `bash`'s inadequacies at dealing with decimal fractions. @@ -102,13 +110,13 @@ Zsh-z is a drop-in replacement for `rupa/z` and will, by default, use the same d ### General observations -This script can be installed simply by downloading it and sourcing it from your `.zshrc`: +This plugin can be installed simply by putting the various files in a directory together and by sourcing `zsh-z.plugin.zsh` in your `.zshrc`: source /path/to/zsh-z.plugin.zsh -For tab completion to work, you will want to have loaded `compinit`. The frameworks handle this themselves. If you are not using a framework, put +For tab completion to work, `_zshz` *must* be in the same directory as `zsh-z.plugin.zsh`, and you will want to have loaded `compinit`. The frameworks handle this themselves. If you are not using a framework, put - autoload -U compinit && compinit + autoload -U compinit; compinit in your .zshrc somewhere below where you source `zsh-z.plugin.zsh`. @@ -180,7 +188,7 @@ Add a backslash to the end of the last line add `'zsh-z'` to the list, e.g., Then relaunch `zsh`. ### For [zcomet](https://github.com/agkozak/zcomet) users - + Simply add zcomet load agkozak/zsh-z diff --git a/plugins/z/img/demo.gif b/plugins/z/img/demo.gif new file mode 100644 index 000000000..247f52f4d Binary files /dev/null and b/plugins/z/img/demo.gif differ diff --git a/plugins/z/z.plugin.zsh b/plugins/z/z.plugin.zsh index 60a630624..a41a4ae25 100644 --- a/plugins/z/z.plugin.zsh +++ b/plugins/z/z.plugin.zsh @@ -100,20 +100,30 @@ With no ARGUMENT, list the directory history in ascending rank. } # Load zsh/datetime module, if necessary -(( $+EPOCHSECONDS )) || zmodload zsh/datetime - -# Load zsh/files, if necessary -[[ ${builtins[zf_chown]} == 'defined' && - ${builtins[zf_mv]} == 'defined' && - ${builtins[zf_rm]} == 'defined' ]] || - zmodload -F zsh/files b:zf_chown b:zf_mv b:zf_rm - -# Load zsh/system, if necessary -[[ ${modules[zsh/system]} == 'loaded' ]] || zmodload zsh/system &> /dev/null +(( ${+EPOCHSECONDS} )) || zmodload zsh/datetime # Global associative array for internal use typeset -gA ZSHZ +# Fallback utilities in case Zsh lacks zsh/files (as is the case with MobaXterm) +ZSHZ[CHOWN]='chown' +ZSHZ[MV]='mv' +ZSHZ[RM]='rm' +# Try to load zsh/files utilities +if [[ ${builtins[zf_chown]-} != 'defined' || + ${builtins[zf_mv]-} != 'defined' || + ${builtins[zf_rm]-} != 'defined' ]]; then + zmodload -F zsh/files b:zf_chown b:zf_mv b:zf_rm &> /dev/null +fi +# Use zsh/files, if it is available +[[ ${builtins[zf_chown]-} == 'defined' ]] && ZSHZ[CHOWN]='zf_chown' +[[ ${builtins[zf_mv]-} == 'defined' ]] && ZSHZ[MV]='zf_mv' +[[ ${builtins[zf_rm]-} == 'defined' ]] && ZSHZ[RM]='zf_rm' + + +# Load zsh/system, if necessary +[[ ${modules[zsh/system]-} == 'loaded' ]] || zmodload zsh/system &> /dev/null + # Make sure ZSHZ_EXCLUDE_DIRS has been declared so that other scripts can # simply append to it (( ${+ZSHZ_EXCLUDE_DIRS} )) || typeset -gUa ZSHZ_EXCLUDE_DIRS @@ -145,7 +155,7 @@ is-at-least 5.3.0 && ZSHZ[PRINTV]=1 zshz() { # Don't use `emulate -L zsh' - it breaks PUSHD_IGNORE_DUPS - setopt LOCAL_OPTIONS NO_KSH_ARRAYS NO_SH_WORD_SPLIT EXTENDED_GLOB + setopt LOCAL_OPTIONS NO_KSH_ARRAYS NO_SH_WORD_SPLIT EXTENDED_GLOB UNSET (( ZSHZ_DEBUG )) && setopt LOCAL_OPTIONS WARN_CREATE_GLOBAL local REPLY @@ -277,7 +287,7 @@ zshz() { if (( ret != 0 )); then # Avoid clobbering the datafile if the write to tempfile failed - zf_rm -f "$tempfile" + ${ZSHZ[RM]} -f "$tempfile" return $ret fi @@ -285,16 +295,17 @@ zshz() { owner=${ZSHZ_OWNER:-${_Z_OWNER}} if (( ZSHZ[USE_FLOCK] )); then - zf_mv "$tempfile" "$datafile" 2> /dev/null || zf_rm -f "$tempfile" + ${ZSHZ[MV]} "$tempfile" "$datafile" 2> /dev/null || ${ZSHZ[RM]} -f "$tempfile" if [[ -n $owner ]]; then - zf_chown ${owner}:"$(id -ng ${owner})" "$datafile" + ${ZSHZ[CHOWN]} ${owner}:"$(id -ng ${owner})" "$datafile" fi else if [[ -n $owner ]]; then - zf_chown "${owner}":"$(id -ng "${owner}")" "$tempfile" + ${ZSHZ[CHOWN]} "${owner}":"$(id -ng "${owner}")" "$tempfile" fi - zf_mv -f "$tempfile" "$datafile" 2> /dev/null || zf_rm -f "$tempfile" + ${ZSHZ[MV]} -f "$tempfile" "$datafile" 2> /dev/null || + ${ZSHZ[RM]} -f "$tempfile" fi # In order to make z -x work, we have to disable zsh-z's adding @@ -306,7 +317,7 @@ zshz() { } ############################################################ - # Read the curent datafile contents, update them, "age" them + # Read the current datafile contents, update them, "age" them # when the total rank gets high enough, and print the new # contents to STDOUT. # @@ -884,6 +895,9 @@ alias ${ZSHZ_CMD:-${_Z_CMD:-z}}='zshz 2>&1' # ZSHZ ############################################################ _zshz_precmd() { + # Protect against `setopt NO_UNSET' + setopt LOCAL_OPTIONS UNSET + # Do not add PWD to datafile when in HOME directory, or # if `z -x' has just been run [[ $PWD == "$HOME" ]] || (( ZSHZ[DIRECTORY_REMOVED] )) && return @@ -931,7 +945,7 @@ add-zsh-hook chpwd _zshz_chpwd # Completion ############################################################ -# Standarized $0 handling +# Standardized $0 handling # https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html 0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}" 0="${${(M)0:#/*}:-$PWD/$0}" @@ -958,7 +972,7 @@ ZSHZ[FUNCTIONS]='_zshz_usage # Enable WARN_NESTED_VAR for functions listed in # ZSHZ[FUNCTIONS] ############################################################ -(( ZSHZ_DEBUG )) && () { +(( ${+ZSHZ_DEBUG} )) && () { if is-at-least 5.4.0; then local x for x in ${=ZSHZ[FUNCTIONS]}; do diff --git a/plugins/zoxide/README.md b/plugins/zoxide/README.md index f326effe6..45f77bdf5 100644 --- a/plugins/zoxide/README.md +++ b/plugins/zoxide/README.md @@ -10,5 +10,8 @@ To use it, add `zoxide` to the plugins array in your `.zshrc` file: ```zsh plugins=(... zoxide) ``` +## Overriding `z` Alias + +You can set the `ZOXIDE_CMD_OVERRIDE`, which will be passed to the `--cmd` flag of `zoxide init`. This allows you to set your `z` command to a default of `cd`. **Note:** you have to [install zoxide](https://github.com/ajeetdsouza/zoxide#step-1-install-zoxide) first. diff --git a/plugins/zoxide/zoxide.plugin.zsh b/plugins/zoxide/zoxide.plugin.zsh index e5658b8f0..25d2e8377 100644 --- a/plugins/zoxide/zoxide.plugin.zsh +++ b/plugins/zoxide/zoxide.plugin.zsh @@ -1,5 +1,5 @@ if (( $+commands[zoxide] )); then - eval "$(zoxide init zsh)" + eval "$(zoxide init --cmd ${ZOXIDE_CMD_OVERRIDE:-z} zsh)" else echo '[oh-my-zsh] zoxide not found, please install it from https://github.com/ajeetdsouza/zoxide' fi diff --git a/plugins/zsh-navigation-tools/n-list b/plugins/zsh-navigation-tools/n-list index f25db8f60..a852b083a 100644 --- a/plugins/zsh-navigation-tools/n-list +++ b/plugins/zsh-navigation-tools/n-list @@ -467,7 +467,7 @@ while (( 1 )); do elif [ -n "$keypad" ]; then final_key="$keypad" else - _nlist_status_msg "Inproper input detected" + _nlist_status_msg "Improper input detected" zcurses refresh main inner fi diff --git a/themes/Soliah.zsh-theme b/themes/Soliah.zsh-theme index c3dd6af89..e297fe9ca 100644 --- a/themes/Soliah.zsh-theme +++ b/themes/Soliah.zsh-theme @@ -5,10 +5,10 @@ ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[white]%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%})" # Text to display if the branch is dirty -ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}*%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}*%{$reset_color%}" # Text to display if the branch is clean -ZSH_THEME_GIT_PROMPT_CLEAN="" +ZSH_THEME_GIT_PROMPT_CLEAN="" # Colors vary depending on time lapsed. ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT="%{$fg[green]%}" @@ -36,7 +36,7 @@ function rvm_gemset() { GEMSET=`rvm gemset list | grep '=>' | cut -b4-` if [[ -n $GEMSET ]]; then echo "%{$fg[yellow]%}$GEMSET%{$reset_color%}|" - fi + fi fi } @@ -52,12 +52,12 @@ function git_time_since_commit() { # Totals MINUTES=$((seconds_since_last_commit / 60)) HOURS=$((seconds_since_last_commit/3600)) - + # Sub-hours and sub-minutes DAYS=$((seconds_since_last_commit / 86400)) SUB_HOURS=$((HOURS % 24)) SUB_MINUTES=$((MINUTES % 60)) - + if [[ -n $(git status -s 2> /dev/null) ]]; then if [ "$MINUTES" -gt 30 ]; then COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG" diff --git a/themes/adben.zsh-theme b/themes/adben.zsh-theme index c2fdbed23..cc097057f 100644 --- a/themes/adben.zsh-theme +++ b/themes/adben.zsh-theme @@ -79,7 +79,7 @@ ps1_command_tip() { command wget -qO- https://www.commandlinefu.com/commands/random/plaintext elif (( ${+commands[curl]} )); then command curl -fsL https://www.commandlinefu.com/commands/random/plaintext - fi + fi } | sed '1d;/^$/d' } diff --git a/themes/agnoster.zsh-theme b/themes/agnoster.zsh-theme index 88854eccd..c2a542163 100644 --- a/themes/agnoster.zsh-theme +++ b/themes/agnoster.zsh-theme @@ -96,7 +96,7 @@ prompt_context() { # Git: branch/detached head, dirty status prompt_git() { (( $+commands[git] )) || return - if [[ "$(git config --get oh-my-zsh.hide-status 2>/dev/null)" = 1 ]]; then + if [[ "$(command git config --get oh-my-zsh.hide-status 2>/dev/null)" = 1 ]]; then return fi local PL_BRANCH_CHAR @@ -106,10 +106,12 @@ prompt_git() { } local ref dirty mode repo_path - if [[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]]; then - repo_path=$(git rev-parse --git-dir 2>/dev/null) + if [[ "$(command git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]]; then + repo_path=$(command git rev-parse --git-dir 2>/dev/null) dirty=$(parse_git_dirty) - ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git rev-parse --short HEAD 2> /dev/null)" + ref=$(command git symbolic-ref HEAD 2> /dev/null) || \ + ref="◈ $(command git describe --exact-match --tags HEAD 2> /dev/null)" || \ + ref="➦ $(command git rev-parse --short HEAD 2> /dev/null)" if [[ -n $dirty ]]; then prompt_segment yellow black else @@ -117,8 +119,8 @@ prompt_git() { fi local ahead behind - ahead=$(git log --oneline @{upstream}.. 2>/dev/null) - behind=$(git log --oneline ..@{upstream} 2>/dev/null) + ahead=$(command git log --oneline @{upstream}.. 2>/dev/null) + behind=$(command git log --oneline ..@{upstream} 2>/dev/null) if [[ -n "$ahead" ]] && [[ -n "$behind" ]]; then PL_BRANCH_CHAR=$'\u21c5' elif [[ -n "$ahead" ]]; then @@ -161,10 +163,10 @@ prompt_bzr() { done local bzr_status status_mod status_all revision - if bzr_status=$(bzr status 2>&1); then + if bzr_status=$(command bzr status 2>&1); then status_mod=$(echo -n "$bzr_status" | head -n1 | grep "modified" | wc -m) status_all=$(echo -n "$bzr_status" | head -n1 | wc -m) - revision=${$(bzr log -r-1 --log-format line | cut -d: -f1):gs/%/%%} + revision=${$(command bzr log -r-1 --log-format line | cut -d: -f1):gs/%/%%} if [[ $status_mod -gt 0 ]] ; then prompt_segment yellow black "bzr@$revision ✚" else @@ -180,13 +182,13 @@ prompt_bzr() { prompt_hg() { (( $+commands[hg] )) || return local rev st branch - if $(hg id >/dev/null 2>&1); then - if $(hg prompt >/dev/null 2>&1); then - if [[ $(hg prompt "{status|unknown}") = "?" ]]; then + if $(command hg id >/dev/null 2>&1); then + if $(command hg prompt >/dev/null 2>&1); then + if [[ $(command hg prompt "{status|unknown}") = "?" ]]; then # if files are not added prompt_segment red white st='±' - elif [[ -n $(hg prompt "{status|modified}") ]]; then + elif [[ -n $(command hg prompt "{status|modified}") ]]; then # if any modification prompt_segment yellow black st='±' @@ -194,15 +196,15 @@ prompt_hg() { # if working copy is clean prompt_segment green $CURRENT_FG fi - echo -n ${$(hg prompt "☿ {rev}@{branch}"):gs/%/%%} $st + echo -n ${$(command hg prompt "☿ {rev}@{branch}"):gs/%/%%} $st else st="" - rev=$(hg id -n 2>/dev/null | sed 's/[^-0-9]//g') - branch=$(hg id -b 2>/dev/null) - if `hg st | grep -q "^\?"`; then + rev=$(command hg id -n 2>/dev/null | sed 's/[^-0-9]//g') + branch=$(command hg id -b 2>/dev/null) + if command hg st | command grep -q "^\?"; then prompt_segment red black st='±' - elif `hg st | grep -q "^[MA]"`; then + elif command hg st | command grep -q "^[MA]"; then prompt_segment yellow black st='±' else diff --git a/themes/avit.zsh-theme b/themes/avit.zsh-theme index 1279ea919..0e39d9077 100644 --- a/themes/avit.zsh-theme +++ b/themes/avit.zsh-theme @@ -11,7 +11,12 @@ $(_user_host)${_current_dir} $(git_prompt_info) $(ruby_prompt_info) PROMPT2='%{%(!.${fg[red]}.${fg[white]})%}◀%{$reset_color%} ' -RPROMPT='$(vi_mode_prompt_info)%{$(echotc UP 1)%}$(_git_time_since_commit) $(git_prompt_status) ${_return_status}%{$(echotc DO 1)%}' +__RPROMPT='$(vi_mode_prompt_info)%{$(echotc UP 1)%}$(_git_time_since_commit) $(git_prompt_status) ${_return_status}%{$(echotc DO 1)%}' +if [[ -z $RPROMPT ]]; then + RPROMPT=$__RPROMPT +else + RPROMPT="${RPROMPT} ${__RPROMPT}" +fi function _user_host() { local me diff --git a/themes/awesomepanda.zsh-theme b/themes/awesomepanda.zsh-theme index 85036e4ac..000697397 100644 --- a/themes/awesomepanda.zsh-theme +++ b/themes/awesomepanda.zsh-theme @@ -1,6 +1,6 @@ # the svn plugin has to be activated for this to work. local ret_status="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ %s)" -PROMPT='${ret_status}%{$fg_bold[green]%} %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%}$(svn_prompt_info)%{$reset_color%}' +PROMPT='%{${ret_status}%}%{$fg_bold[green]%} %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%}$(svn_prompt_info)%{$reset_color%}' ZSH_THEME_GIT_PROMPT_PREFIX="git:(%{$fg[red]%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" diff --git a/themes/bira.zsh-theme b/themes/bira.zsh-theme index 42a70a018..f909afa62 100644 --- a/themes/bira.zsh-theme +++ b/themes/bira.zsh-theme @@ -6,10 +6,15 @@ local current_dir="%B%{$fg[blue]%}%~ %{$reset_color%}" local vcs_branch='$(git_prompt_info)$(hg_prompt_info)' local rvm_ruby='$(ruby_prompt_info)' local venv_prompt='$(virtualenv_prompt_info)' +if [[ "${plugins[@]}" =~ 'kube-ps1' ]]; then + local kube_prompt='$(kube_ps1)' +else + local kube_prompt='' +fi ZSH_THEME_RVM_PROMPT_OPTIONS="i v g" -PROMPT="╭─${user_host}${current_dir}${rvm_ruby}${vcs_branch}${venv_prompt} +PROMPT="╭─${user_host}${current_dir}${rvm_ruby}${vcs_branch}${venv_prompt}${kube_prompt} ╰─%B${user_symbol}%b " RPROMPT="%B${return_code}%b" diff --git a/themes/crunch.zsh-theme b/themes/crunch.zsh-theme index 8278661ab..d86ce1e4a 100644 --- a/themes/crunch.zsh-theme +++ b/themes/crunch.zsh-theme @@ -1,15 +1,15 @@ # CRUNCH - created from Steve Eley's cat waxing. # Initially hacked from the Dallas theme. Thanks, Dallas Reedy. # -# This theme assumes you do most of your oh-my-zsh'ed "colorful" work at a single machine, -# and eschews the standard space-consuming user and hostname info. Instead, only the +# This theme assumes you do most of your oh-my-zsh'ed "colorful" work at a single machine, +# and eschews the standard space-consuming user and hostname info. Instead, only the # things that vary in my own workflow are shown: # # * The time (not the date) # * The RVM version and gemset (omitting the 'ruby' name if it's MRI) # * The current directory # * The Git branch and its 'dirty' state -# +# # Colors are at the top so you can mess with those separately if you like. # For the most part I stuck with Dallas's. diff --git a/themes/eastwood.zsh-theme b/themes/eastwood.zsh-theme index 88134f8e6..31e24fa7f 100644 --- a/themes/eastwood.zsh-theme +++ b/themes/eastwood.zsh-theme @@ -1,5 +1,5 @@ # RVM settings -if [[ -s ~/.rvm/scripts/rvm ]] ; then +if [[ -s ~/.rvm/scripts/rvm ]] ; then RPS1="%{$fg[yellow]%}rvm:%{$reset_color%}%{$fg[red]%}\$(~/.rvm/bin/rvm-prompt)%{$reset_color%} $EPS1" else if which rbenv &> /dev/null; then diff --git a/themes/emotty.zsh-theme b/themes/emotty.zsh-theme index ba0840950..0fea7d916 100644 --- a/themes/emotty.zsh-theme +++ b/themes/emotty.zsh-theme @@ -11,7 +11,7 @@ # # There are pre-defined different emoji sets to choose from, e.g.: # emoji, stellar, floral, zodiac, love (see emotty plugin). -# +# # To choose a different emotty set than the default (emoji) # % export emotty_set=nature # @@ -95,7 +95,7 @@ zstyle ':vcs_info:*' stagedstr "${green}${vcs_staged_glyph}" # %(k|f) reset (back|fore)ground color zstyle ':vcs_info:*' max-exports 3 zstyle ':vcs_info:*' nvcsformats "${prompt_glyph}" '%3~' '' -zstyle ':vcs_info:*' formats "${yellow}%u%c%b${vcs_branch_glyph}%f" '%S|' "$FX[bold]%r$FX[no-bold]" +zstyle ':vcs_info:*' formats "${yellow}%u%c%b${vcs_branch_glyph}%f" '%S|' "$FX[bold]%r$FX[no-bold]" zstyle ':vcs_info:*' actionformats "${red}%K{white}%a${vcs_action_glyph}%k%f" '%S|' "$FX[bold]%r$FX[no-bold]" red_if_root="%(!.%F{red}.)" diff --git a/themes/essembeh.zsh-theme b/themes/essembeh.zsh-theme index 43d4093b1..50b3f7772 100644 --- a/themes/essembeh.zsh-theme +++ b/themes/essembeh.zsh-theme @@ -8,7 +8,7 @@ # - prefix to detect docker containers or chroot # - git plugin to display current branch and status -# git plugin +# git plugin ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[cyan]%}(" ZSH_THEME_GIT_PROMPT_SUFFIX=") %{$reset_color%}" ZSH_THEME_GIT_PROMPT_UNTRACKED="%%" @@ -35,7 +35,7 @@ if [[ -n "$SSH_CONNECTION" ]]; then ZSH_ESSEMBEH_PREFIX="%{$fg[yellow]%}[$(echo $SSH_CONNECTION | awk '{print $1}')]%{$reset_color%} " # use red color to highlight a remote connection ZSH_ESSEMBEH_COLOR="red" -elif [[ -r /etc/debian_chroot ]]; then +elif [[ -r /etc/debian_chroot ]]; then # prefix prompt in case of chroot ZSH_ESSEMBEH_PREFIX="%{$fg[yellow]%}[chroot:$(cat /etc/debian_chroot)]%{$reset_color%} " elif [[ -r /.dockerenv ]]; then diff --git a/themes/fino-time.zsh-theme b/themes/fino-time.zsh-theme index c7e2d965e..3f9360ac5 100644 --- a/themes/fino-time.zsh-theme +++ b/themes/fino-time.zsh-theme @@ -12,6 +12,7 @@ # Also borrowing from http://stevelosh.com/blog/2010/02/my-extravagant-zsh-prompt/ function virtualenv_info { + [ $CONDA_DEFAULT_ENV ] && echo "($CONDA_DEFAULT_ENV) " [ $VIRTUAL_ENV ] && echo '('`basename $VIRTUAL_ENV`') ' } diff --git a/themes/fishy.zsh-theme b/themes/fishy.zsh-theme index 2b8d559e5..3b975c8f4 100644 --- a/themes/fishy.zsh-theme +++ b/themes/fishy.zsh-theme @@ -16,7 +16,8 @@ _fishy_collapsed_wd() { } local user_color='green'; [ $UID -eq 0 ] && user_color='red' -PROMPT='%n@%m %{$fg[$user_color]%}$(_fishy_collapsed_wd)%{$reset_color%}%(!.#.>) ' +local host_color='white'; [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ] && host_color='yellow' +PROMPT='%{$fg[$user_color]%}%n%{$reset_color%}@%{$fg[$host_color]%}%m %{$fg[$user_color]%}$(_fishy_collapsed_wd)%{$reset_color%}%(!.#.>) ' PROMPT2='%{$fg[red]%}\ %{$reset_color%}' local return_status="%{$fg_bold[red]%}%(?..%?)%{$reset_color%}" diff --git a/themes/gallois.zsh-theme b/themes/gallois.zsh-theme index bb97bfb17..3fc349072 100644 --- a/themes/gallois.zsh-theme +++ b/themes/gallois.zsh-theme @@ -1,24 +1,140 @@ # Depends on the git plugin for work_in_progress() (( $+functions[work_in_progress] )) || work_in_progress() {} -ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[green]%}[" -ZSH_THEME_GIT_PROMPT_SUFFIX="]%{$reset_color%}" -ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}*%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[cyan]%}[%{$fg[green]%}" +ZSH_THEME_GIT_PROMPT_SUFFIX="%{$fg[cyan]%}]" +ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}" ZSH_THEME_GIT_PROMPT_CLEAN="" # Customized git status, oh-my-zsh currently does not allow render dirty status before branch git_custom_status() { local branch=$(git_current_branch) [[ -n "$branch" ]] || return 0 - echo "$(parse_git_dirty)\ -%{${fg_bold[yellow]}%}$(work_in_progress)%{$reset_color%}\ -${ZSH_THEME_GIT_PROMPT_PREFIX}${branch}${ZSH_THEME_GIT_PROMPT_SUFFIX}" + print "%{${fg_bold[yellow]}%}$(work_in_progress)%{$reset_color%}\ +${ZSH_THEME_GIT_PROMPT_PREFIX}$(parse_git_dirty)${branch}\ +${ZSH_THEME_GIT_PROMPT_SUFFIX}" +} +autoload -U colors && colors + +#export VCS_PROMPT=hg_prompt_info +export VCS_PROMPT=git_custom_status + +base_prompt="%{$fg[cyan]%}[%~% ]%(?.%{$fg[green]%}.%{$fg[red]%})%B$%b " +custom_prompt="" +last_run_time="" +last_vcs_info="" + + +function pipestatus_parse { + PIPESTATUS="$pipestatus" + ERROR=0 + for i in "${(z)PIPESTATUS}"; do + if [[ "$i" -ne 0 ]]; then + ERROR=1 + fi + done + + if [[ "$ERROR" -ne 0 ]]; then + print "[%{$fg[red]%}$PIPESTATUS%{$fg[cyan]%}]" + fi } -# RVM component of prompt -ZSH_THEME_RUBY_PROMPT_PREFIX="%{$fg[red]%}[" -ZSH_THEME_RUBY_PROMPT_SUFFIX="]%{$reset_color%}" # Combine it all into a final right-side prompt -RPS1="\$(git_custom_status)\$(ruby_prompt_info)${RPS1:+ $RPS1}" PROMPT='%{$fg[cyan]%}[%~% ]%(?.%{$fg[green]%}.%{$fg[red]%})%B$%b ' +function preexec() { + last_run_time=$(perl -MTime::HiRes=time -e 'printf "%.9f\n", time') +} + +function duration() { + local duration + local now=$(perl -MTime::HiRes=time -e 'printf "%.9f\n", time') + local last=$1 + local last_split=("${(@s/./)last}") + local now_split=("${(@s/./)now}") + local T=$((now_split[1] - last_split[1])) + local D=$((T/60/60/24)) + local H=$((T/60/60%24)) + local M=$((T/60%60)) + local S=$((T%60)) + local s=$(((now_split[2] - last_split[2]) / 1000000000.)) + local m=$(((now_split[2] - last_split[2]) / 1000000.)) + + (( $D > 0 )) && duration+="${D}d" + (( $H > 0 )) && duration+="${H}h" + (( $M > 0 )) && duration+="${M}m" + + if [[ $S -le 0 ]]; then + printf "%ims" "$m" + else + if ! [[ -z $duration ]] && printf "%s" "$duration" + local sec_milli=$((S + s)) + printf "%.3fs" "$sec_milli" + fi +} + +function precmd() { + RETVAL=$(pipestatus_parse) + local info="" + + if [ ! -z "$last_run_time" ]; then + local elapsed=$(duration $last_run_time) + last_run_time=$(print $last_run_time | tr -d ".") + if [ $(( $(perl -MTime::HiRes=time -e 'printf "%.9f\n", time' | tr -d ".") - $last_run_time )) -gt $(( 120 * 1000 * 1000 * 1000 )) ]; then + local elapsed_color="%{$fg[magenta]%}" + elif [ $(( $(perl -MTime::HiRes=time -e 'printf "%.9f\n", time' | tr -d ".") - $last_run_time )) -gt $(( 60 * 1000 * 1000 * 1000 )) ]; then + local elapsed_color="%{$fg[red]%}" + elif [ $(( $(perl -MTime::HiRes=time -e 'printf "%.9f\n", time' | tr -d ".") - $last_run_time )) -gt $(( 10 * 1000 * 1000 * 1000 )) ]; then + local elapsed_color="%{$fg[yellow]%}" + else + local elapsed_color="%{$fg[green]%}" + fi + info=$(printf "%s%s%s%s%s" "%{$fg[cyan]%}[" "$elapsed_color" "$elapsed" "%{$fg[cyan]%}]" "$RETVAL") + unset last_run_time + fi + + if [ -z "$info" -a ! -z "$last_vcs_info" ]; then + custom_prompt="$last_vcs_info$base_prompt" + return; + fi + + if (( ${+VCS_PROMPT} )); then + last_vcs_info=$($VCS_PROMPT) + if [ ! -z "$last_vcs_info" ]; then + [ -z "$info" ] && info=$last_vcs_info || info="$info$last_vcs_info" + fi + fi + + [ -z "$info" ] && custom_prompt="$base_prompt" || custom_prompt="$info$base_prompt" +} + +function hg_prompt_info() { + unset output info parts branch_parts branch + + local output="" + if ! output="$(hg status 2> /dev/null)"; then + return + fi + + local info=$(hg log -l1 --template '{author}:{node|short}:{remotenames}:{phabdiff}') + local parts=(${(@s/:/)info}) + local branch_parts=(${(@s,/,)parts[3]}) + local branch=${branch_parts[-1]} + [ ! -z "${parts[3]}" ] && [[ "${parts[1]}" =~ "$USER@" ]] && branch=${parts[3]} + [ -z "${parts[3]}" ] && branch=${parts[2]} + + if [[ ! -z "$output" ]]; then + local color="%{$fg[red]%}" + elif [[ "${branch}" == "master" || "${branch}" == "warm" ]]; then + local color="%{$fg[yellow]%}" + else + local color="%{$fg[green]%}" + fi + + print "%{$fg[cyan]%}[${color}${branch}%{$fg[cyan]%}]" +} + +setopt PROMPT_SUBST +PROMPT='$custom_prompt' + + diff --git a/themes/gnzh.zsh-theme b/themes/gnzh.zsh-theme index 1e6c4e93b..ca62320e2 100644 --- a/themes/gnzh.zsh-theme +++ b/themes/gnzh.zsh-theme @@ -21,7 +21,7 @@ fi if [[ -n "$SSH_CLIENT" || -n "$SSH2_CLIENT" ]]; then PR_HOST='%F{red}%M%f' # SSH else - PR_HOST='%F{green}%M%f' # no SSH + PR_HOST='%F{green}%m%f' # no SSH fi diff --git a/themes/josh.zsh-theme b/themes/josh.zsh-theme index ea051c58e..df59280d7 100644 --- a/themes/josh.zsh-theme +++ b/themes/josh.zsh-theme @@ -15,7 +15,7 @@ function josh_prompt { branch_size=${#branch} ruby_size=${#ruby_version} user_machine_size=${#${(%):-%n@%m-}} - + if [[ ${#branch} -eq 0 ]] then (( ruby_size = ruby_size + 1 )) else @@ -24,15 +24,15 @@ function josh_prompt { (( branch_size = branch_size + 2 )) fi fi - + (( spare_width = ${spare_width} - (${user_machine_size} + ${path_size} + ${branch_size} + ${ruby_size}) )) while [ ${#prompt} -lt $spare_width ]; do prompt=" $prompt" done - + prompt="%{%F{green}%}$PWD$prompt%{%F{red}%}$(ruby_prompt_info)%{$reset_color%} $(git_current_branch)" - + echo $prompt } diff --git a/themes/junkfood.zsh-theme b/themes/junkfood.zsh-theme index 01fae4b95..e3b746c7a 100644 --- a/themes/junkfood.zsh-theme +++ b/themes/junkfood.zsh-theme @@ -3,10 +3,10 @@ # Grab the current date (%W) and time (%t): JUNKFOOD_TIME_="%{$fg_bold[red]%}#%{$fg_bold[white]%}( %{$fg_bold[yellow]%}%W%{$reset_color%}@%{$fg_bold[white]%}%t )( %{$reset_color%}" -# Grab the current machine name +# Grab the current machine name JUNKFOOD_MACHINE_="%{$fg_bold[blue]%}%m%{$fg[white]%} ):%{$reset_color%}" -# Grab the current username +# Grab the current username JUNKFOOD_CURRENT_USER_="%{$fg_bold[green]%}%n%{$reset_color%}" # Grab the current filepath, use shortcuts: ~/Desktop diff --git a/themes/michelebologna.zsh-theme b/themes/michelebologna.zsh-theme index bb86d68db..b13b2caf1 100644 --- a/themes/michelebologna.zsh-theme +++ b/themes/michelebologna.zsh-theme @@ -29,14 +29,13 @@ local cyan="%{$fg_bold[cyan]%}" local yellow="%{$fg_bold[yellow]%}" local blue="%{$fg_bold[blue]%}" local magenta="%{$fg_bold[magenta]%}" -local white="%{$fg_bold[white]%}" local reset="%{$reset_color%}" local -a color_array -color_array=($green $red $cyan $yellow $blue $magenta $white) +color_array=($green $red $cyan $yellow $blue $magenta) -local username_color=$white -local hostname_color=$color_array[$[((#HOST))%7+1]] # choose hostname color based on first character +local username_color=$blue +local hostname_color=$color_array[$[((#HOST))%6+1]] # choose hostname color based on first character local current_dir_color=$blue local username="%n" @@ -66,10 +65,10 @@ function michelebologna_git_prompt { local out=$(git_prompt_info)$(git_prompt_status)$(git_remote_status) [[ -n $out ]] || return printf " %s(%s%s%s)%s" \ - "%{$fg_bold[white]%}" \ + "%{$fg_bold[blue]%}" \ "%{$fg_bold[green]%}" \ "$out" \ - "%{$fg_bold[white]%}" \ + "%{$fg_bold[blue]%}" \ "%{$reset_color%}" } diff --git a/themes/mlh.zsh-theme b/themes/mlh.zsh-theme index c059bf850..94718f8f2 100644 --- a/themes/mlh.zsh-theme +++ b/themes/mlh.zsh-theme @@ -15,7 +15,7 @@ # To customize symbols (e.g MLH_AT_SYMBOL), simply set them as environment variables # for example in your ~/.zshrc file, like this: # MLH_AT_SYMBOL=" at " -# +# # Settings *must* be set before sourcing oh-my-zsh.sh the .zshrc file. # # To easily discover colors and their codes, type `spectrum_ls` in the terminal diff --git a/themes/mortalscumbag.zsh-theme b/themes/mortalscumbag.zsh-theme index d81a7ca06..c9994c0f9 100644 --- a/themes/mortalscumbag.zsh-theme +++ b/themes/mortalscumbag.zsh-theme @@ -1,6 +1,6 @@ function my_git_prompt() { tester=$(git rev-parse --git-dir 2> /dev/null) || return - + INDEX=$(git status --porcelain 2> /dev/null) STATUS="" @@ -51,8 +51,14 @@ function ssh_connection() { fi } +function _toolbox_prompt_info() { + if typeset -f toolbox_prompt_info > /dev/null; then + toolbox_prompt_info + fi +} + local ret_status="%(?:%{$fg_bold[green]%}:%{$fg_bold[red]%})%?%{$reset_color%}" -PROMPT=$'\n$(ssh_connection)%{$fg_bold[green]%}%n@%m%{$reset_color%}$(my_git_prompt) : %~\n[${ret_status}] %# ' +PROMPT=$'\n$(_toolbox_prompt_info)$(ssh_connection)%{$fg_bold[green]%}%n@%m%{$reset_color%}$(my_git_prompt) : %~\n[${ret_status}] %# ' ZSH_THEME_PROMPT_RETURNCODE_PREFIX="%{$fg_bold[red]%}" ZSH_THEME_GIT_PROMPT_PREFIX=" $fg[white]‹ %{$fg_bold[yellow]%}" diff --git a/themes/oldgallois.zsh-theme b/themes/oldgallois.zsh-theme new file mode 100644 index 000000000..bb97bfb17 --- /dev/null +++ b/themes/oldgallois.zsh-theme @@ -0,0 +1,24 @@ +# Depends on the git plugin for work_in_progress() +(( $+functions[work_in_progress] )) || work_in_progress() {} + +ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[green]%}[" +ZSH_THEME_GIT_PROMPT_SUFFIX="]%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}*%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_CLEAN="" + +# Customized git status, oh-my-zsh currently does not allow render dirty status before branch +git_custom_status() { + local branch=$(git_current_branch) + [[ -n "$branch" ]] || return 0 + echo "$(parse_git_dirty)\ +%{${fg_bold[yellow]}%}$(work_in_progress)%{$reset_color%}\ +${ZSH_THEME_GIT_PROMPT_PREFIX}${branch}${ZSH_THEME_GIT_PROMPT_SUFFIX}" +} + +# RVM component of prompt +ZSH_THEME_RUBY_PROMPT_PREFIX="%{$fg[red]%}[" +ZSH_THEME_RUBY_PROMPT_SUFFIX="]%{$reset_color%}" + +# Combine it all into a final right-side prompt +RPS1="\$(git_custom_status)\$(ruby_prompt_info)${RPS1:+ $RPS1}" +PROMPT='%{$fg[cyan]%}[%~% ]%(?.%{$fg[green]%}.%{$fg[red]%})%B$%b ' diff --git a/themes/rkj-repos.zsh-theme b/themes/rkj-repos.zsh-theme index 3cb452335..a9fe1a9af 100644 --- a/themes/rkj-repos.zsh-theme +++ b/themes/rkj-repos.zsh-theme @@ -1,7 +1,7 @@ # user, host, full path, and time/date on two lines for easier vgrepping function hg_prompt_info { - if (( $+commands[hg] )) && grep -q "prompt" ~/.hgrc; then + if (( $+commands[hg] )) && [[ -e ~/.hgrc ]] && grep -q "prompt" ~/.hgrc; then hg prompt --angle-brackets "\ %{$reset_color%}><:%{$fg[magenta]%}%{$reset_color%}>\ %{$reset_color%}>\ diff --git a/themes/robbyrussell.zsh-theme b/themes/robbyrussell.zsh-theme index 173e6d579..cfecfc892 100644 --- a/themes/robbyrussell.zsh-theme +++ b/themes/robbyrussell.zsh-theme @@ -1,7 +1,7 @@ -PROMPT="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ ) %{$fg[cyan]%}%c%{$reset_color%}" +PROMPT="%(?:%{$fg_bold[green]%}%1{➜%} :%{$fg_bold[red]%}%1{➜%} ) %{$fg[cyan]%}%c%{$reset_color%}" PROMPT+=' $(git_prompt_info)' ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}git:(%{$fg[red]%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} " -ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}✗" +ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}%1{✗%}" ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})" diff --git a/themes/sonicradish.zsh-theme b/themes/sonicradish.zsh-theme index 508611830..db6170969 100644 --- a/themes/sonicradish.zsh-theme +++ b/themes/sonicradish.zsh-theme @@ -1,4 +1,4 @@ -#!/usr/bin/env zsh +#!/usr/bin/env zsh #local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})" setopt promptsubst diff --git a/themes/wedisagree.zsh-theme b/themes/wedisagree.zsh-theme index e9e9d6ef8..358891992 100644 --- a/themes/wedisagree.zsh-theme +++ b/themes/wedisagree.zsh-theme @@ -5,9 +5,9 @@ # - Place that bundle in ~/Library/Application\ Support/SIMBL/Plugins (create that folder if it doesn't exist) # - Open Terminal preferences. Go to Settings -> Text -> More # - Change default colours to your liking. -# +# # Here are the colours from Textmate's Monokai theme: -# +# # Black: 0, 0, 0 # Red: 229, 34, 34 # Green: 166, 227, 45 @@ -28,7 +28,7 @@ PROMPT='%{$fg[magenta]%}[%c] %{$reset_color%}' RPROMPT='${time} %{$fg[magenta]%}$(git_prompt_info)%{$reset_color%}$(git_prompt_status)%{$reset_color%}$(git_prompt_ahead)%{$reset_color%}' # Add this at the start of RPROMPT to include rvm info showing ruby-version@gemset-name -# $(ruby_prompt_info) +# $(ruby_prompt_info) # local time, color coded by last return code time_enabled="%(?.%{$fg[green]%}.%{$fg[red]%})%*%{$reset_color%}" @@ -53,7 +53,7 @@ ZSH_THEME_RUBY_PROMPT_SUFFIX="%{$reset_color%}" # More symbols to choose from: # ☀ ✹ ☄ ♆ ♀ ♁ ♐ ♇ ♈ ♉ ♚ ♛ ♜ ♝ ♞ ♟ ♠ ♣ ⚢ ⚲ ⚳ ⚴ ⚥ ⚤ ⚦ ⚒ ⚑ ⚐ ♺ ♻ ♼ ☰ ☱ ☲ ☳ ☴ ☵ ☶ ☷ -# ✡ ✔ ✖ ✚ ✱ ✤ ✦ ❤ ➜ ➟ ➼ ✂ ✎ ✐ ⨀ ⨁ ⨂ ⨍ ⨎ ⨏ ⨷ ⩚ ⩛ ⩡ ⩱ ⩲ ⩵ ⩶ ⨠ +# ✡ ✔ ✖ ✚ ✱ ✤ ✦ ❤ ➜ ➟ ➼ ✂ ✎ ✐ ⨀ ⨁ ⨂ ⨍ ⨎ ⨏ ⨷ ⩚ ⩛ ⩡ ⩱ ⩲ ⩵ ⩶ ⨠ # ⬅ ⬆ ⬇ ⬈ ⬉ ⬊ ⬋ ⬒ ⬓ ⬔ ⬕ ⬖ ⬗ ⬘ ⬙ ⬟ ⬤ 〒 ǀ ǁ ǂ ĭ Ť Ŧ # Determine if we are using a gemset. @@ -61,7 +61,7 @@ function rvm_gemset() { GEMSET=`rvm gemset list | grep '=>' | cut -b4-` if [[ -n $GEMSET ]]; then echo "%{$fg[yellow]%}$GEMSET%{$reset_color%}|" - fi + fi } # Determine the time since last commit. If branch is clean, @@ -76,12 +76,12 @@ function git_time_since_commit() { # Totals MINUTES=$((seconds_since_last_commit / 60)) HOURS=$((seconds_since_last_commit/3600)) - + # Sub-hours and sub-minutes DAYS=$((seconds_since_last_commit / 86400)) SUB_HOURS=$((HOURS % 24)) SUB_MINUTES=$((MINUTES % 60)) - + if [[ -n $(git status -s 2> /dev/null) ]]; then if [ "$MINUTES" -gt 30 ]; then COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG" diff --git a/tools/changelog.sh b/tools/changelog.sh index 1af74e42d..c4b26079e 100755 --- a/tools/changelog.sh +++ b/tools/changelog.sh @@ -221,11 +221,16 @@ supports_hyperlinks() { # If $TERM_PROGRAM is set, these terminals support hyperlinks case "$TERM_PROGRAM" in - Hyper|iTerm.app|terminology|WezTerm) return 0 ;; + Hyper|iTerm.app|terminology|WezTerm|vscode) return 0 ;; esac - # kitty supports hyperlinks - if [ "$TERM" = xterm-kitty ]; then + # These termcap entries support hyperlinks + case "$TERM" in + xterm-kitty|alacritty|alacritty-direct) return 0 ;; + esac + + # xfce4-terminal supports hyperlinks + if [ "$COLORTERM" = "xfce4-terminal" ]; then return 0 fi @@ -292,16 +297,17 @@ function display-release { function fmt:hash { #* Uses $hash from outer scope local hash="${1:-$hash}" + local short_hash="${hash:0:7}" # 7 characters sha, top level sha is 12 characters case "$output" in - raw) printf '%s' "$hash" ;; + raw) printf '%s' "$short_hash" ;; text) - local text="\e[33m$hash\e[0m"; # red + local text="\e[33m$short_hash\e[0m"; # red if supports_hyperlinks; then printf "\e]8;;%s\a%s\e]8;;\a" "https://github.com/ohmyzsh/ohmyzsh/commit/$hash" $text; else echo $text; fi ;; - md) printf '[`%s`](https://github.com/ohmyzsh/ohmyzsh/commit/%s)' "$hash" "$hash" ;; + md) printf '[`%s`](https://github.com/ohmyzsh/ohmyzsh/commit/%s)' "$short_hash" "$hash" ;; esac } @@ -366,7 +372,7 @@ function display-release { # In text mode, highlight (#) and dim text between `backticks` text) if supports_hyperlinks; then - sed -E $'s|#([0-9]+)|\e]8;;https://github.com/ohmyzsh/ohmyzsh/issues/\\1\a\e[32m#\\1\e[0m\e]8;;\a|g' <<< "$subject" + sed -E $'s|#([0-9]+)|\e]8;;https://github.com/ohmyzsh/ohmyzsh/issues/\\1\a\e[32m#\\1\e[0m\e]8;;\a|g;s|`([^`]+)`|`\e[2m\\1\e[0m`|g' <<< "$subject" else sed -E $'s|#([0-9]+)|\e[32m#\\1\e[0m|g;s|`([^`]+)`|`\e[2m\\1\e[0m`|g' <<< "$subject" fi ;; @@ -512,13 +518,13 @@ function main { # Git log options # -z: commits are delimited by null bytes # --format: [7-char hash][ref names][subject][body] - # --abbrev=7: force commit hashes to be 7 characters long + # --abbrev=7: force commit hashes to be 12 characters long # --no-merges: merge commits are omitted # --first-parent: commits from merged branches are omitted local SEP="0mZmAgIcSeP" local -a raw_commits raw_commits=(${(0)"$(command git -c log.showSignature=false log -z \ - --format="%h${SEP}%D${SEP}%s${SEP}%b" --abbrev=7 \ + --format="%h${SEP}%D${SEP}%s${SEP}%b" --abbrev=12 \ --no-merges --first-parent $range)"}) local raw_commit diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh index 3210e4375..1ecab5c0b 100644 --- a/tools/check_for_upgrade.sh +++ b/tools/check_for_upgrade.sh @@ -9,6 +9,7 @@ fi # - prompt (default): the user is asked before updating when it's time to update # - auto: the update is performed automatically when it's time # - reminder: a reminder is shown to the user when it's time to update +# - background-alpha: an experimental update-on-the-background option # - disabled: automatic update is turned off zstyle -s ':omz:update' mode update_mode || { update_mode=prompt @@ -19,14 +20,16 @@ zstyle -s ':omz:update' mode update_mode || { } # Cancel update if: -# - the automatic update is disabled. -# - the current user doesn't have write permissions nor owns the $ZSH directory. +# - the automatic update is disabled +# - the current user doesn't have write permissions nor owns the $ZSH directory # - is not run from a tty -# - git is unavailable on the system. +# - git is unavailable on the system +# - $ZSH is not a git repository if [[ "$update_mode" = disabled ]] \ || [[ ! -w "$ZSH" || ! -O "$ZSH" ]] \ || [[ ! -t 1 ]] \ - || ! command git --version 2>&1 >/dev/null; then + || ! command git --version 2>&1 >/dev/null \ + || (builtin cd -q "$ZSH"; ! command git rev-parse --is-inside-work-tree &>/dev/null); then unset update_mode return fi @@ -91,13 +94,37 @@ function is_update_available() { } function update_last_updated_file() { - echo "LAST_EPOCH=$(current_epoch)" >! "${ZSH_CACHE_DIR}/.zsh-update" + local exit_status="$1" error="$2" + + if [[ -z "${1}${2}" ]]; then + echo "LAST_EPOCH=$(current_epoch)" >! "${ZSH_CACHE_DIR}/.zsh-update" + return + fi + + cat >! "${ZSH_CACHE_DIR}/.zsh-update" <&1); then + update_last_updated_file 0 "Update successful" + else + exit_status=$? + update_last_updated_file $exit_status "$error" + return $exit_status fi } @@ -126,88 +153,145 @@ function has_typed_input() { } } -() { - emulate -L zsh +function handle_update() { + () { + emulate -L zsh - local epoch_target mtime option LAST_EPOCH + local epoch_target mtime option LAST_EPOCH - # Remove lock directory if older than a day - zmodload zsh/datetime - zmodload -F zsh/stat b:zstat - if mtime=$(zstat +mtime "$ZSH/log/update.lock" 2>/dev/null); then - if (( (mtime + 3600 * 24) < EPOCHSECONDS )); then - command rm -rf "$ZSH/log/update.lock" + # Remove lock directory if older than a day + zmodload zsh/datetime + zmodload -F zsh/stat b:zstat + if mtime=$(zstat +mtime "$ZSH/log/update.lock" 2>/dev/null); then + if (( (mtime + 3600 * 24) < EPOCHSECONDS )); then + command rm -rf "$ZSH/log/update.lock" + fi fi - fi - # Check for lock directory - if ! command mkdir "$ZSH/log/update.lock" 2>/dev/null; then - return - fi + # Check for lock directory + if ! command mkdir "$ZSH/log/update.lock" 2>/dev/null; then + return + fi - # Remove lock directory on exit. `return $ret` is important for when trapping a SIGINT: - # The return status from the function is handled specially. If it is zero, the signal is - # assumed to have been handled, and execution continues normally. Otherwise, the shell - # will behave as interrupted except that the return status of the trap is retained. - # This means that for a CTRL+C, the trap needs to return the same exit status so that - # the shell actually exits what it's running. - trap " - ret=\$? - unset update_mode - unset -f current_epoch is_update_available update_last_updated_file update_ohmyzsh 2>/dev/null - command rm -rf '$ZSH/log/update.lock' - return \$ret - " EXIT INT QUIT + # Remove lock directory on exit. `return $ret` is important for when trapping a SIGINT: + # The return status from the function is handled specially. If it is zero, the signal is + # assumed to have been handled, and execution continues normally. Otherwise, the shell + # will behave as interrupted except that the return status of the trap is retained. + # This means that for a CTRL+C, the trap needs to return the same exit status so that + # the shell actually exits what it's running. + trap " + ret=\$? + unset update_mode + unset -f current_epoch is_update_available update_last_updated_file update_ohmyzsh handle_update 2>/dev/null + command rm -rf '$ZSH/log/update.lock' + return \$ret + " EXIT INT QUIT - # Create or update .zsh-update file if missing or malformed - if ! source "${ZSH_CACHE_DIR}/.zsh-update" 2>/dev/null || [[ -z "$LAST_EPOCH" ]]; then - update_last_updated_file - return - fi + # Create or update .zsh-update file if missing or malformed + if ! source "${ZSH_CACHE_DIR}/.zsh-update" 2>/dev/null || [[ -z "$LAST_EPOCH" ]]; then + update_last_updated_file + return + fi - # Number of days before trying to update again - zstyle -s ':omz:update' frequency epoch_target || epoch_target=${UPDATE_ZSH_DAYS:-13} - # Test if enough time has passed until the next update - if (( ( $(current_epoch) - $LAST_EPOCH ) < $epoch_target )); then - return - fi + # Number of days before trying to update again + zstyle -s ':omz:update' frequency epoch_target || epoch_target=${UPDATE_ZSH_DAYS:-13} + # Test if enough time has passed until the next update + if (( ( $(current_epoch) - $LAST_EPOCH ) < $epoch_target )); then + return + fi - # Test if Oh My Zsh directory is a git repository - if ! (builtin cd -q "$ZSH" && LANG= git rev-parse &>/dev/null); then - echo >&2 "[oh-my-zsh] Can't update: not a git repository." - return - fi + # Test if Oh My Zsh directory is a git repository + if ! (builtin cd -q "$ZSH" && LANG= git rev-parse &>/dev/null); then + echo >&2 "[oh-my-zsh] Can't update: not a git repository." + return + fi - # Check if there are updates available before proceeding - if ! is_update_available; then - update_last_updated_file - return - fi + # Check if there are updates available before proceeding + if ! is_update_available; then + update_last_updated_file + return + fi - # If in reminder mode or user has typed input, show reminder and exit - if [[ "$update_mode" = reminder ]] || has_typed_input; then - printf '\r\e[0K' # move cursor to first column and clear whole line - echo "[oh-my-zsh] It's time to update! You can do that by running \`omz update\`" - return 0 - fi + # If in reminder mode or user has typed input, show reminder and exit + if [[ "$update_mode" = reminder ]] || { [[ "$update_mode" != background-alpha ]] && has_typed_input }; then + printf '\r\e[0K' # move cursor to first column and clear whole line + echo "[oh-my-zsh] It's time to update! You can do that by running \`omz update\`" + return 0 + fi - # Don't ask for confirmation before updating if in auto mode - if [[ "$update_mode" = auto ]]; then - update_ohmyzsh - return $? - fi + # Don't ask for confirmation before updating if in auto mode + if [[ "$update_mode" = (auto|background-alpha) ]]; then + update_ohmyzsh + return $? + fi - # Ask for confirmation and only update on 'y', 'Y' or Enter - # Otherwise just show a reminder for how to update - echo -n "[oh-my-zsh] Would you like to update? [Y/n] " - read -r -k 1 option - [[ "$option" = $'\n' ]] || echo - case "$option" in - [yY$'\n']) update_ohmyzsh ;; - [nN]) update_last_updated_file ;& - *) echo "[oh-my-zsh] You can update manually by running \`omz update\`" ;; - esac + # Ask for confirmation and only update on 'y', 'Y' or Enter + # Otherwise just show a reminder for how to update + echo -n "[oh-my-zsh] Would you like to update? [Y/n] " + read -r -k 1 option + [[ "$option" = $'\n' ]] || echo + case "$option" in + [yY$'\n']) update_ohmyzsh ;; + [nN]) update_last_updated_file ;& + *) echo "[oh-my-zsh] You can update manually by running \`omz update\`" ;; + esac + } + + unset update_mode + unset -f current_epoch is_update_available update_last_updated_file update_ohmyzsh handle_update } -unset update_mode -unset -f current_epoch is_update_available update_last_updated_file update_ohmyzsh +case "$update_mode" in + background-alpha) + autoload -Uz add-zsh-hook + + _omz_bg_update() { + # do the update in a subshell + (handle_update) &| + + # register update results function + add-zsh-hook precmd _omz_bg_update_status + + # deregister background function + add-zsh-hook -d precmd _omz_bg_update + unset -f _omz_bg_update + } + + _omz_bg_update_status() { + { + local LAST_EPOCH EXIT_STATUS ERROR + if [[ ! -f "$ZSH_CACHE_DIR"/.zsh-update ]]; then + return 1 + fi + + # check update results until timeout is reached + . "$ZSH_CACHE_DIR/.zsh-update" + if [[ -z "$EXIT_STATUS" || -z "$ERROR" ]]; then + return 1 + fi + + if [[ "$EXIT_STATUS" -eq 0 ]]; then + print -P "\n%F{green}[oh-my-zsh] Update successful.%f" + return 0 + elif [[ "$EXIT_STATUS" -ne 0 ]]; then + print -P "\n%F{red}[oh-my-zsh] There was an error updating:%f" + printf "\n${fg[yellow]}%s${reset_color}" "$ERROR" + return 0 + fi + } always { + if (( TRY_BLOCK_ERROR == 0 )); then + # if last update results have been handled, remove them from the status file + update_last_updated_file + + # deregister background function + add-zsh-hook -d precmd _omz_bg_update_status + unset -f _omz_bg_update_status + fi + } + } + + add-zsh-hook precmd _omz_bg_update + ;; + *) + handle_update ;; +esac diff --git a/tools/install.sh b/tools/install.sh index fcfbcf778..e3613a28b 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -63,7 +63,9 @@ zdot="${ZDOTDIR:-$HOME}" # Default value for $ZSH # a) if $ZDOTDIR is supplied and not $HOME: $ZDOTDIR/ohmyzsh # b) otherwise, $HOME/.oh-my-zsh -[ "$ZDOTDIR" = "$HOME" ] || ZSH="${ZSH:-${ZDOTDIR:+$ZDOTDIR/ohmyzsh}}" +if [ -n "$ZDOTDIR" ] && [ "$ZDOTDIR" != "$HOME" ]; then + ZSH="${ZSH:-$ZDOTDIR/ohmyzsh}" +fi ZSH="${ZSH:-$HOME/.oh-my-zsh}" # Default settings @@ -164,11 +166,16 @@ supports_hyperlinks() { # If $TERM_PROGRAM is set, these terminals support hyperlinks case "$TERM_PROGRAM" in - Hyper|iTerm.app|terminology|WezTerm) return 0 ;; + Hyper|iTerm.app|terminology|WezTerm|vscode) return 0 ;; esac - # kitty supports hyperlinks - if [ "$TERM" = xterm-kitty ]; then + # These termcap entries support hyperlinks + case "$TERM" in + xterm-kitty|alacritty|alacritty-direct) return 0 ;; + esac + + # xfce4-terminal supports hyperlinks + if [ "$COLORTERM" = "xfce4-terminal" ]; then return 0 fi diff --git a/tools/upgrade.sh b/tools/upgrade.sh index 34ff3f027..5eb90ab41 100755 --- a/tools/upgrade.sh +++ b/tools/upgrade.sh @@ -1,4 +1,5 @@ #!/usr/bin/env zsh +set +u # disable nounset local ret=0 # exit code @@ -9,9 +10,14 @@ fi # Protect against unwanted sourcing case "$ZSH_EVAL_CONTEXT" in - *:file) echo "error: this file should not be sourced" && return ;; + *:file) echo "error: this file should not be sourced" && return 1 ;; esac +# Define "$ZSH" if not defined -- in theory this should be `export`ed by the calling script +if [[ -z "$ZSH" ]]; then + ZSH="${0:a:h:h}" +fi + cd "$ZSH" verbose_mode="default" @@ -89,11 +95,16 @@ supports_hyperlinks() { # If $TERM_PROGRAM is set, these terminals support hyperlinks case "$TERM_PROGRAM" in - Hyper|iTerm.app|terminology|WezTerm) return 0 ;; + Hyper|iTerm.app|terminology|WezTerm|vscode) return 0 ;; esac - # kitty supports hyperlinks - if [ "$TERM" = xterm-kitty ]; then + # These termcap entries support hyperlinks + case "$TERM" in + xterm-kitty|alacritty|alacritty-direct) return 0 ;; + esac + + # xfce4-terminal supports hyperlinks + if [ "$COLORTERM" = "xfce4-terminal" ]; then return 0 fi