mirror of
https://github.com/robbyrussell/oh-my-zsh.git
synced 2026-12-03 21:58:56 +01:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c184381d0 |
No files matched your search
@@ -1,57 +1,21 @@
|
|||||||
<!--
|
## Standards checklist:
|
||||||
Thanks for contributing! Read CONTRIBUTING.md first.
|
|
||||||
Keep this proportional to the change: short paragraphs or bullets are welcome.
|
|
||||||
Remove these instructions before submitting.
|
|
||||||
|
|
||||||
Report only evidence you have. Distinguish agent-run checks from personal
|
<!-- Fill with an x the ones that apply. Example: [x] -->
|
||||||
testing, identify missing checks or demos, and leave unconfirmed items
|
|
||||||
unchecked. Don't promise follow-up work on someone else's behalf.
|
|
||||||
-->
|
|
||||||
|
|
||||||
## What and why
|
- [ ] The PR title is descriptive.
|
||||||
|
- [ ] The PR doesn't replicate another PR which is already open.
|
||||||
|
- [ ] I have read the contribution guide and followed all the instructions.
|
||||||
|
- [ ] The code follows the code style guide detailed in the wiki.
|
||||||
|
- [ ] The code is mine or it's from somewhere with an MIT-compatible license.
|
||||||
|
- [ ] If I used AI tools (ChatGPT, Claude, Gemini, etc.) to assist with this contribution, I've disclosed it below.
|
||||||
|
- [ ] The code is efficient, to the best of my ability, and does not waste computer resources.
|
||||||
|
- [ ] The code is stable and I have tested it myself, to the best of my abilities.
|
||||||
|
- [ ] If the code introduces new aliases, I provide a valid use case for all plugin users down below.
|
||||||
|
|
||||||
<!-- What changes, who benefits, and how does it make their command-line
|
## Changes:
|
||||||
experience easier or more delightful? A few sentences are usually enough.
|
|
||||||
Link related issues or requests if available; don't invent demand.
|
|
||||||
|
|
||||||
A personal itch is a welcome starting point. Explain why the change belongs
|
- [...]
|
||||||
in the shared project. For aliases, describe common workflows they support. -->
|
|
||||||
|
|
||||||
## Demo and verification
|
## Other comments:
|
||||||
|
|
||||||
<!-- For user-facing changes, include before/after screenshots, a GIF,
|
...
|
||||||
or a short video. For new features, show an example in use.
|
|
||||||
If a visual isn't useful, briefly explain why. If it's missing, say so.
|
|
||||||
|
|
||||||
Describe checks actually run and their results, relevant versions, and
|
|
||||||
testing gaps. Distinguish agent-run checks from personal testing.
|
|
||||||
For documentation-only changes, describe what you checked. -->
|
|
||||||
|
|
||||||
## Other notes
|
|
||||||
|
|
||||||
<!-- Include only what applies:
|
|
||||||
- Compatibility concerns or areas needing particular attention.
|
|
||||||
- How users can discover a feature: README update, example, or shared demo.
|
|
||||||
- Meaningful AI assistance and its role; basic autocomplete doesn't count.
|
|
||||||
|
|
||||||
Delete this section if it isn't needed. -->
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>Submission checklist</summary>
|
|
||||||
|
|
||||||
<!-- Check confirmed items with [x]. For conditional items, check them if
|
|
||||||
the condition doesn't apply. Otherwise, mark inapplicable items "N/A"
|
|
||||||
with a brief reason. -->
|
|
||||||
|
|
||||||
- [ ] The PR title follows the [commit conventions](https://github.com/ohmyzsh/ohmyzsh/blob/master/CONTRIBUTING.md#commit-guidelines) and clearly describes the change.
|
|
||||||
- [ ] I've searched for existing PRs and confirmed this isn't a duplicate.
|
|
||||||
- [ ] I've read and followed the [contribution guidelines](https://github.com/ohmyzsh/ohmyzsh/blob/master/CONTRIBUTING.md).
|
|
||||||
- [ ] My code follows the [code style guide](https://github.com/ohmyzsh/ohmyzsh/wiki/Code-Style-Guide).
|
|
||||||
- [ ] I wrote this code or can contribute it under an MIT-compatible license.
|
|
||||||
- [ ] If I meaningfully used AI tools, I've disclosed their role above.
|
|
||||||
- [ ] I've included a visual demonstration or explained why a visual isn't useful.
|
|
||||||
- [ ] I've considered performance and avoided unnecessary work or resource use.
|
|
||||||
- [ ] I've personally tested the change and described results and limitations above.
|
|
||||||
- [ ] If I've added aliases, I've explained their usefulness for common workflows.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
@@ -6,8 +6,6 @@ updates:
|
|||||||
interval: "weekly"
|
interval: "weekly"
|
||||||
day: "sunday"
|
day: "sunday"
|
||||||
labels: []
|
labels: []
|
||||||
cooldown:
|
|
||||||
default-days: 7
|
|
||||||
groups:
|
groups:
|
||||||
gha-minor:
|
gha-minor:
|
||||||
patterns:
|
patterns:
|
||||||
@@ -21,8 +19,6 @@ updates:
|
|||||||
interval: "weekly"
|
interval: "weekly"
|
||||||
day: "sunday"
|
day: "sunday"
|
||||||
labels: []
|
labels: []
|
||||||
cooldown:
|
|
||||||
default-days: 7
|
|
||||||
groups:
|
groups:
|
||||||
py-minor:
|
py-minor:
|
||||||
patterns:
|
patterns:
|
||||||
@@ -30,19 +26,3 @@ updates:
|
|||||||
update-types:
|
update-types:
|
||||||
- minor
|
- minor
|
||||||
- patch
|
- patch
|
||||||
- package-ecosystem: npm
|
|
||||||
directory: "/.github/workflows/installer"
|
|
||||||
schedule:
|
|
||||||
interval: "weekly"
|
|
||||||
day: "sunday"
|
|
||||||
labels: []
|
|
||||||
cooldown:
|
|
||||||
default-days: 7
|
|
||||||
groups:
|
|
||||||
npm-minor:
|
|
||||||
patterns:
|
|
||||||
- "*"
|
|
||||||
update-types:
|
|
||||||
- major
|
|
||||||
- minor
|
|
||||||
- patch
|
|
||||||
@@ -75,7 +75,7 @@ dependencies:
|
|||||||
plugins/zsh-syntax-highlighting:
|
plugins/zsh-syntax-highlighting:
|
||||||
repo: zsh-users/zsh-syntax-highlighting
|
repo: zsh-users/zsh-syntax-highlighting
|
||||||
branch: master
|
branch: master
|
||||||
version: e6683f20e5c38d3e5447f45845d04ddda75d0f23
|
version: 2fc57d63067c18b1100ecdbf684fa5baf49459d1
|
||||||
precopy: |
|
precopy: |
|
||||||
set -e
|
set -e
|
||||||
version=$(<.version)
|
version=$(<.version)
|
||||||
|
|||||||
@@ -1,66 +0,0 @@
|
|||||||
# Workflow checks
|
|
||||||
|
|
||||||
The `Workflow lint` workflow runs jactionlint on pull requests and pushes to
|
|
||||||
`master`. It checks workflows and Dependabot configuration with the default
|
|
||||||
profile, including ShellCheck for inline shell scripts. It runs without online
|
|
||||||
checks or publishing credentials.
|
|
||||||
|
|
||||||
To run the same checks locally, install jactionlint 2.6.0 and ShellCheck, then run
|
|
||||||
from the repository root:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
jactionlint --profile=default --no-online
|
|
||||||
```
|
|
||||||
|
|
||||||
Keep the local jactionlint version aligned with the pinned action in `lint.yml`.
|
|
||||||
There is no baseline: new findings fail the check. Any rule exception should be
|
|
||||||
limited to the relevant line and explain why it is needed.
|
|
||||||
|
|
||||||
## Action lockfile
|
|
||||||
|
|
||||||
`actions.lock` records the commit for every action the workflows use, including
|
|
||||||
actions called by other actions. Workflows reference release tags; the lockfile
|
|
||||||
holds the commit that runs. Do not edit it by hand.
|
|
||||||
|
|
||||||
After adding a workflow or changing any `uses:` line, regenerate it with the
|
|
||||||
[`gh actions-lock`](https://github.com/github/gh-actions-lock) extension and
|
|
||||||
commit the result:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
gh extension install github/gh-actions-lock
|
|
||||||
gh actions-lock
|
|
||||||
```
|
|
||||||
|
|
||||||
Dependabot updates the lockfile entry in the same pull request when it bumps an
|
|
||||||
action.
|
|
||||||
|
|
||||||
The `Workflow lint` workflow verifies the lockfile on every pull request and
|
|
||||||
fails when it does not match the workflows.
|
|
||||||
|
|
||||||
## Project tracking
|
|
||||||
|
|
||||||
`project.yml` intentionally uses `pull_request_target` so the GitHub App can add
|
|
||||||
fork contributions to the project board. It must not check out or execute PR
|
|
||||||
code. Project IDs are validated before passing them through step outputs, and
|
|
||||||
PR-derived plugin/theme names are restricted to letters, digits, dots, underscores
|
|
||||||
and hyphens.
|
|
||||||
|
|
||||||
The App tokens request explicit permissions: project tracking needs organization
|
|
||||||
projects write access and issues/pull requests read access; dependency updates
|
|
||||||
need contents read access and issues/pull requests write access. Dependency pushes
|
|
||||||
use the job's separate `GITHUB_TOKEN` with contents write access.
|
|
||||||
|
|
||||||
## Installer deployment
|
|
||||||
|
|
||||||
The Vercel CLI is pinned in `installer/package.json` and `installer/package-lock.json`.
|
|
||||||
Dependabot checks this dependency weekly, with a seven-day cooldown for version
|
|
||||||
updates, like the other configured ecosystems. Deployment installs the lockfile
|
|
||||||
with `npm ci --ignore-scripts`; `.vercelignore` uploads only `install.sh`.
|
|
||||||
|
|
||||||
After changing the CLI version, update its lockfile and verify the CLI locally:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
npm install --package-lock-only --ignore-scripts --prefix .github/workflows/installer
|
|
||||||
npm ci --ignore-scripts --prefix .github/workflows/installer
|
|
||||||
.github/workflows/installer/node_modules/.bin/vercel --version
|
|
||||||
```
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
# This file is machine-generated by `gh actions-lock`.
|
|
||||||
# Do not edit by hand; run `gh actions-lock` to update.
|
|
||||||
# Docs: https://gh.io/actions-lockfile
|
|
||||||
version: 'v0.0.3'
|
|
||||||
workflows:
|
|
||||||
'.github/workflows/dependencies.yml':
|
|
||||||
- 'actions/checkout@v7.0.1'
|
|
||||||
- 'actions/create-github-app-token@v3.4.0'
|
|
||||||
- 'actions/setup-python@v7.1.0'
|
|
||||||
- 'step-security/harden-runner@v2.23.0'
|
|
||||||
'.github/workflows/installer.yml':
|
|
||||||
- 'actions/checkout@v7.0.1'
|
|
||||||
- 'actions/setup-node@v7.1.0'
|
|
||||||
- 'step-security/harden-runner@v2.23.0'
|
|
||||||
'.github/workflows/lint.yml':
|
|
||||||
- 'actions/checkout@v7.0.1'
|
|
||||||
- 'github/gh-actions-lock@verify/v0.5.1'
|
|
||||||
- 'jdx/jactionlint@v2.6.0'
|
|
||||||
- 'step-security/harden-runner@v2.23.0'
|
|
||||||
'.github/workflows/main.yml':
|
|
||||||
- 'actions/checkout@v7.0.1'
|
|
||||||
- 'actions/setup-python@v7.1.0'
|
|
||||||
- 'step-security/harden-runner@v2.23.0'
|
|
||||||
'.github/workflows/project.yml':
|
|
||||||
- 'actions/create-github-app-token@v3.4.0'
|
|
||||||
- 'step-security/harden-runner@v2.23.0'
|
|
||||||
'.github/workflows/scorecard.yml':
|
|
||||||
- 'actions/checkout@v7.0.1'
|
|
||||||
- 'actions/upload-artifact@v7.0.2'
|
|
||||||
- 'github/codeql-action@v4.39.5'
|
|
||||||
- 'ossf/scorecard-action@v2.6.0'
|
|
||||||
- 'step-security/harden-runner@v2.23.0'
|
|
||||||
dependencies:
|
|
||||||
'actions/checkout@v7.0.1':
|
|
||||||
ref: 'v7.0.1'
|
|
||||||
commit: 'sha1-3d3c42e5aac5ba805825da76410c181273ba90b1'
|
|
||||||
owner_id: 44036562
|
|
||||||
repo_id: 197814629
|
|
||||||
'actions/create-github-app-token@v3.4.0':
|
|
||||||
ref: 'v3.4.0'
|
|
||||||
commit: 'sha1-f418cff399f7aef4c2f0ad47e25ca7a6abbdd6fc'
|
|
||||||
owner_id: 44036562
|
|
||||||
repo_id: 642580244
|
|
||||||
'actions/setup-node@v7.1.0':
|
|
||||||
ref: 'v7.1.0'
|
|
||||||
commit: 'sha1-949feb2413d6458794dcd2491c4babbbce0c15c1'
|
|
||||||
owner_id: 44036562
|
|
||||||
repo_id: 189476904
|
|
||||||
'actions/setup-python@v7.1.0':
|
|
||||||
ref: 'v7.1.0'
|
|
||||||
commit: 'sha1-6d4fd22b20465ccc0f7354476588e8df7c9ca0e0'
|
|
||||||
owner_id: 44036562
|
|
||||||
repo_id: 192625525
|
|
||||||
'actions/upload-artifact@v7.0.2':
|
|
||||||
ref: 'v7.0.2'
|
|
||||||
commit: 'sha1-cf430e030ddbb5b0abf93d22962f4752f3646cd9'
|
|
||||||
owner_id: 44036562
|
|
||||||
repo_id: 192625955
|
|
||||||
'github/codeql-action@2892aa5e19bbd11bc0cff5427e3b750a04d9e3c2':
|
|
||||||
ref: 'v4.38.2'
|
|
||||||
commit: 'sha1-2892aa5e19bbd11bc0cff5427e3b750a04d9e3c2'
|
|
||||||
owner_id: 9919
|
|
||||||
repo_id: 259445878
|
|
||||||
'github/codeql-action@v4.39.5':
|
|
||||||
ref: 'v4.39.5'
|
|
||||||
commit: 'sha1-915412ff23e8b7659517e607487dbeae018f2934'
|
|
||||||
owner_id: 9919
|
|
||||||
repo_id: 259445878
|
|
||||||
'github/gh-actions-lock@verify/v0.5.1':
|
|
||||||
ref: 'verify/v0.5.1'
|
|
||||||
commit: 'sha1-5fa07d19c267d19e29f4341f10fdf7f516375038'
|
|
||||||
owner_id: 9919
|
|
||||||
repo_id: 1217640442
|
|
||||||
'jdx/jactionlint@v2.6.0':
|
|
||||||
ref: 'v2.6.0'
|
|
||||||
commit: 'sha1-72c00452809bcca05b8bc12acdcf15dd7a9c1c5e'
|
|
||||||
owner_id: 216188
|
|
||||||
repo_id: 1404951382
|
|
||||||
uses:
|
|
||||||
- 'github/codeql-action@2892aa5e19bbd11bc0cff5427e3b750a04d9e3c2'
|
|
||||||
'ossf/scorecard-action@v2.6.0':
|
|
||||||
ref: 'v2.6.0'
|
|
||||||
commit: 'sha1-23f22cd43608bae7a1f1fa2603d7314dee9538a5'
|
|
||||||
owner_id: 67707773
|
|
||||||
repo_id: 421101922
|
|
||||||
'step-security/harden-runner@v2.23.0':
|
|
||||||
ref: 'v2.23.0'
|
|
||||||
commit: 'sha1-aebdcf6156ab6691adf63218240e476564a1ed4c'
|
|
||||||
owner_id: 88700172
|
|
||||||
repo_id: 422287306
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
# default known collisions file
|
|
||||||
known_collisions.json
|
|
||||||
@@ -1,170 +0,0 @@
|
|||||||
"""Check for alias collisions within the codebase"""
|
|
||||||
|
|
||||||
from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser
|
|
||||||
from pathlib import Path
|
|
||||||
from dataclasses import dataclass
|
|
||||||
import itertools
|
|
||||||
import re
|
|
||||||
import json
|
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
ERROR_MESSAGE_TEMPLATE = (
|
|
||||||
"Alias `%s` defined in `%s` already exists as alias `%s` in `%s`."
|
|
||||||
)
|
|
||||||
|
|
||||||
KNOWN_COLLISIONS_PATH = Path(__file__).resolve().parent / "known_collisions.json"
|
|
||||||
|
|
||||||
|
|
||||||
def dir_path(path_string: str) -> Path:
|
|
||||||
if Path(path_string).is_dir():
|
|
||||||
return Path(path_string)
|
|
||||||
else:
|
|
||||||
raise NotADirectoryError(path_string)
|
|
||||||
|
|
||||||
|
|
||||||
def parse_arguments():
|
|
||||||
parser = ArgumentParser(
|
|
||||||
description=__doc__,
|
|
||||||
formatter_class=ArgumentDefaultsHelpFormatter,
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"folder",
|
|
||||||
type=dir_path,
|
|
||||||
help="Folder to check",
|
|
||||||
)
|
|
||||||
group = parser.add_mutually_exclusive_group(required=True)
|
|
||||||
group.add_argument(
|
|
||||||
"--known-collisions",
|
|
||||||
type=Path,
|
|
||||||
default=None,
|
|
||||||
help="Json-serialized list of known collision to compare to",
|
|
||||||
)
|
|
||||||
group.add_argument(
|
|
||||||
"--known-collisions-output-path",
|
|
||||||
type=Path,
|
|
||||||
default=KNOWN_COLLISIONS_PATH,
|
|
||||||
help="Output path for a json-serialized list of known collisions",
|
|
||||||
)
|
|
||||||
return parser.parse_args()
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
|
||||||
class Alias:
|
|
||||||
alias: str
|
|
||||||
value: str
|
|
||||||
module: Path
|
|
||||||
|
|
||||||
def to_dict(self) -> dict:
|
|
||||||
return {
|
|
||||||
"alias": self.alias,
|
|
||||||
"value": self.value,
|
|
||||||
"module": str(self.module),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
|
||||||
class Collision:
|
|
||||||
existing_alias: Alias
|
|
||||||
new_alias: Alias
|
|
||||||
|
|
||||||
def is_new_collision(self, known_collision_aliases: list[str]) -> bool:
|
|
||||||
return self.new_alias.alias not in known_collision_aliases
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def from_dict(cls, collision_dict: dict) -> "Collision":
|
|
||||||
return cls(
|
|
||||||
Alias(**collision_dict["existing_alias"]),
|
|
||||||
Alias(**collision_dict["new_alias"]),
|
|
||||||
)
|
|
||||||
|
|
||||||
def to_dict(self) -> dict:
|
|
||||||
return {
|
|
||||||
"existing_alias": self.existing_alias.to_dict(),
|
|
||||||
"new_alias": self.new_alias.to_dict(),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def find_aliases_in_file(file: Path) -> list[Alias]:
|
|
||||||
matches = re.findall(
|
|
||||||
r"^[ \t]*alias (?:-[gs] )?([^ =]+)=['\"]?(.*?)['\"]?$",
|
|
||||||
file.read_text(),
|
|
||||||
re.MULTILINE,
|
|
||||||
)
|
|
||||||
return [Alias(match[0], match[1], file) for match in matches]
|
|
||||||
|
|
||||||
|
|
||||||
def load_known_collisions(collision_file: Path) -> list[Collision]:
|
|
||||||
collision_list = json.loads(collision_file.read_text())
|
|
||||||
return [Collision.from_dict(collision_dict) for collision_dict in collision_list]
|
|
||||||
|
|
||||||
|
|
||||||
def find_all_aliases(path: Path) -> list:
|
|
||||||
aliases = [find_aliases_in_file(file) for file in path.rglob("*.zsh")]
|
|
||||||
return list(itertools.chain(*aliases))
|
|
||||||
|
|
||||||
|
|
||||||
def check_for_duplicates(aliases: list[Alias]) -> list[Collision]:
|
|
||||||
elements = {}
|
|
||||||
collisions = []
|
|
||||||
for alias in aliases:
|
|
||||||
if alias.alias in elements:
|
|
||||||
existing = elements[alias.alias]
|
|
||||||
collisions.append(Collision(existing, alias))
|
|
||||||
else:
|
|
||||||
elements[alias.alias] = alias
|
|
||||||
return collisions
|
|
||||||
|
|
||||||
|
|
||||||
def print_collisions(collisions: dict[Alias, Alias]) -> None:
|
|
||||||
if collisions:
|
|
||||||
print(f"Found {len(collisions)} alias collisions:\n")
|
|
||||||
for collision in collisions:
|
|
||||||
print(
|
|
||||||
ERROR_MESSAGE_TEMPLATE
|
|
||||||
% (
|
|
||||||
f"{collision.new_alias.alias}={collision.new_alias.value}",
|
|
||||||
collision.new_alias.module.name,
|
|
||||||
f"{collision.existing_alias.alias}={collision.existing_alias.value}",
|
|
||||||
collision.existing_alias.module.name,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
print("\nConsider renaming your aliases.")
|
|
||||||
else:
|
|
||||||
print("Found no collisions")
|
|
||||||
|
|
||||||
|
|
||||||
def check_for_new_collisions(
|
|
||||||
known_collisions: Path, collisions: list[Collision]
|
|
||||||
) -> list[Collision]:
|
|
||||||
known_collisions = load_known_collisions(known_collisions)
|
|
||||||
known_collision_aliases = [
|
|
||||||
collision.new_alias.alias for collision in known_collisions
|
|
||||||
]
|
|
||||||
|
|
||||||
return [
|
|
||||||
collision
|
|
||||||
for collision in collisions
|
|
||||||
if collision.is_new_collision(known_collision_aliases)
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> int:
|
|
||||||
"""main"""
|
|
||||||
args = parse_arguments()
|
|
||||||
aliases = find_all_aliases(args.folder)
|
|
||||||
collisions = check_for_duplicates(aliases)
|
|
||||||
|
|
||||||
if args.known_collisions is not None:
|
|
||||||
new_collisions = check_for_new_collisions(args.known_collisions, collisions)
|
|
||||||
print_collisions(new_collisions)
|
|
||||||
return -1 if new_collisions else 0
|
|
||||||
|
|
||||||
args.known_collisions_output_path.write_text(
|
|
||||||
json.dumps([collision.to_dict() for collision in collisions])
|
|
||||||
)
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
sys.exit(main())
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
pyfakefs
|
|
||||||
pytest
|
|
||||||
@@ -1,166 +0,0 @@
|
|||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from pyfakefs.fake_filesystem import FakeFilesystem
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from check_alias_collision import (
|
|
||||||
dir_path,
|
|
||||||
find_all_aliases,
|
|
||||||
find_aliases_in_file,
|
|
||||||
check_for_duplicates,
|
|
||||||
Alias,
|
|
||||||
Collision,
|
|
||||||
load_known_collisions,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
THREE_ALIASES = """
|
|
||||||
alias g='git'
|
|
||||||
|
|
||||||
alias ga='git add'
|
|
||||||
alias gaa='git add --all'
|
|
||||||
"""
|
|
||||||
|
|
||||||
CONDITIONAL_ALIAS = """
|
|
||||||
is-at-least 2.8 "$git_version" \
|
|
||||||
&& alias gfa='git fetch --all --prune --jobs=10' \
|
|
||||||
|| alias gfa='git fetch --all --prune'
|
|
||||||
"""
|
|
||||||
|
|
||||||
ONE_KNOWN_COLLISION = """
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"existing_alias": {
|
|
||||||
"alias": "gcd",
|
|
||||||
"value": "git checkout $(git_develop_branch)",
|
|
||||||
"module": "plugins/git/git.plugin.zsh"
|
|
||||||
},
|
|
||||||
"new_alias": {
|
|
||||||
"alias": "gcd",
|
|
||||||
"value": "git checkout $(git config gitflow.branch.develop)",
|
|
||||||
"module": "plugins/git-flow/git-flow.plugin.zsh"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
def test_dir_path__is_dir__input_path(fs: FakeFilesystem) -> None:
|
|
||||||
fs.create_dir("test")
|
|
||||||
assert Path("test") == dir_path("test")
|
|
||||||
|
|
||||||
|
|
||||||
def test_dir_path__is_file__raise_not_a_directory_error(fs: FakeFilesystem) -> None:
|
|
||||||
fs.create_file("test")
|
|
||||||
with pytest.raises(NotADirectoryError):
|
|
||||||
dir_path("test")
|
|
||||||
|
|
||||||
|
|
||||||
def test_dir_path__does_not_exist__raise_not_a_directory_error(
|
|
||||||
fs: FakeFilesystem,
|
|
||||||
) -> None:
|
|
||||||
with pytest.raises(NotADirectoryError):
|
|
||||||
dir_path("test")
|
|
||||||
|
|
||||||
|
|
||||||
def test_find_all_aliases__empty_folder_should_return_empty_list(
|
|
||||||
fs: FakeFilesystem,
|
|
||||||
) -> None:
|
|
||||||
fs.create_dir("test")
|
|
||||||
result = find_all_aliases(Path("test"))
|
|
||||||
assert [] == result
|
|
||||||
|
|
||||||
|
|
||||||
def test_find_aliases_in_file__empty_text_should_return_empty_list(
|
|
||||||
fs: FakeFilesystem,
|
|
||||||
) -> None:
|
|
||||||
fs.create_file("empty.zsh")
|
|
||||||
result = find_aliases_in_file(Path("empty.zsh"))
|
|
||||||
assert [] == result
|
|
||||||
|
|
||||||
|
|
||||||
def test_find_aliases_in_file__one_alias_should_find_one(fs: FakeFilesystem) -> None:
|
|
||||||
fs.create_file("one.zsh", contents="alias g='git'")
|
|
||||||
result = find_aliases_in_file(Path("one.zsh"))
|
|
||||||
assert [Alias("g", "git", Path("one.zsh"))] == result
|
|
||||||
|
|
||||||
|
|
||||||
def test_find_aliases_in_file__three_aliases_should_find_three(
|
|
||||||
fs: FakeFilesystem,
|
|
||||||
) -> None:
|
|
||||||
fs.create_file("three.zsh", contents=THREE_ALIASES)
|
|
||||||
result = find_aliases_in_file(Path("three.zsh"))
|
|
||||||
assert [
|
|
||||||
Alias("g", "git", Path("three.zsh")),
|
|
||||||
Alias("ga", "git add", Path("three.zsh")),
|
|
||||||
Alias("gaa", "git add --all", Path("three.zsh")),
|
|
||||||
] == result
|
|
||||||
|
|
||||||
|
|
||||||
def test_find_aliases_in_file__one_conditional_alias_should_find_none(
|
|
||||||
fs: FakeFilesystem,
|
|
||||||
) -> None:
|
|
||||||
fs.create_file("conditional.zsh", contents=CONDITIONAL_ALIAS)
|
|
||||||
result = find_aliases_in_file(Path("conditional.zsh"))
|
|
||||||
assert [] == result
|
|
||||||
|
|
||||||
|
|
||||||
def test_check_for_duplicates__no_duplicates_should_return_empty_dict() -> None:
|
|
||||||
result = check_for_duplicates(
|
|
||||||
[
|
|
||||||
Alias("g", "git", Path("git.zsh")),
|
|
||||||
Alias("ga", "git add", Path("git.zsh")),
|
|
||||||
Alias("gaa", "git add --all", Path("git.zsh")),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
assert result == []
|
|
||||||
|
|
||||||
|
|
||||||
def test_check_for_duplicates__duplicates_should_have_one_collision() -> None:
|
|
||||||
result = check_for_duplicates(
|
|
||||||
[
|
|
||||||
Alias("gc", "git commit", Path("git.zsh")),
|
|
||||||
Alias("gc", "git clone", Path("git.zsh")),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
assert result == [
|
|
||||||
Collision(
|
|
||||||
Alias("gc", "git commit", Path("git.zsh")),
|
|
||||||
Alias("gc", "git clone", Path("git.zsh")),
|
|
||||||
)
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def test_is_new_collision__new_alias_not_in_known_collisions__should_return_true() -> (
|
|
||||||
None
|
|
||||||
):
|
|
||||||
known_collisions = ["gc", "gd"]
|
|
||||||
new_alias = Alias("ga", "git add", Path("git.zsh"))
|
|
||||||
collision = Collision(Alias("gd", "git diff", Path("git.zsh")), new_alias)
|
|
||||||
assert collision.is_new_collision(known_collisions) is True
|
|
||||||
|
|
||||||
|
|
||||||
def test_is_new_collision__new_alias_in_known_collisions__should_return_false() -> None:
|
|
||||||
known_collisions = ["gc", "gd", "ga"]
|
|
||||||
new_alias = Alias("ga", "git add", Path("git.zsh"))
|
|
||||||
collision = Collision(Alias("gd", "git diff", Path("git.zsh")), new_alias)
|
|
||||||
assert collision.is_new_collision(known_collisions) is False
|
|
||||||
|
|
||||||
|
|
||||||
def test_load_known_collisions__empty_file__should_return_empty_list(
|
|
||||||
fs: FakeFilesystem,
|
|
||||||
) -> None:
|
|
||||||
empty_list = Path("empty.json")
|
|
||||||
fs.create_file(empty_list, contents="[]")
|
|
||||||
result = load_known_collisions(empty_list)
|
|
||||||
assert [] == result
|
|
||||||
|
|
||||||
|
|
||||||
def test_load_known_collisions__one_collision__should_return_one_collision(
|
|
||||||
fs: FakeFilesystem,
|
|
||||||
) -> None:
|
|
||||||
known_collisions_file = Path("known_collisions.json")
|
|
||||||
fs.create_file(known_collisions_file, contents=ONE_KNOWN_COLLISION)
|
|
||||||
result = load_known_collisions(known_collisions_file)
|
|
||||||
assert 1 == len(result)
|
|
||||||
assert "gcd" == result[0].existing_alias.alias
|
|
||||||
@@ -11,31 +11,27 @@ jobs:
|
|||||||
check:
|
check:
|
||||||
name: Check for updates
|
name: Check for updates
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 30
|
|
||||||
if: github.repository == 'ohmyzsh/ohmyzsh'
|
if: github.repository == 'ohmyzsh/ohmyzsh'
|
||||||
permissions:
|
permissions:
|
||||||
contents: write # this is needed to push commits and branches
|
contents: write # this is needed to push commits and branches
|
||||||
steps:
|
steps:
|
||||||
- name: Harden the runner (Audit all outbound calls)
|
- name: Harden the runner (Audit all outbound calls)
|
||||||
uses: step-security/harden-runner@v2.23.0
|
uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v7.0.1
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: Authenticate as @ohmyzsh
|
- name: Authenticate as @ohmyzsh
|
||||||
id: generate-token
|
id: generate-token
|
||||||
uses: actions/create-github-app-token@v3.4.0
|
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
|
||||||
with:
|
with:
|
||||||
client-id: ${{ secrets.OHMYZSH_CLIENT_ID }}
|
client-id: ${{ secrets.OHMYZSH_CLIENT_ID }}
|
||||||
private-key: ${{ secrets.OHMYZSH_APP_PRIVATE_KEY }}
|
private-key: ${{ secrets.OHMYZSH_APP_PRIVATE_KEY }}
|
||||||
permission-contents: read
|
|
||||||
permission-issues: write
|
|
||||||
permission-pull-requests: write
|
|
||||||
- name: Setup Python
|
- name: Setup Python
|
||||||
uses: actions/setup-python@v7.1.0
|
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
|
||||||
with:
|
with:
|
||||||
python-version: "3.12"
|
python-version: "3.12"
|
||||||
cache: "pip"
|
cache: "pip"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
certifi==2026.11.20
|
certifi==2026.7.22
|
||||||
charset-normalizer==3.5.3
|
charset-normalizer==3.5.2
|
||||||
idna==3.20
|
idna==3.20
|
||||||
PyYAML==6.0.4
|
PyYAML==6.0.3
|
||||||
requests==2.34.2
|
requests==2.34.2
|
||||||
semver==3.1.3
|
semver==3.1.0
|
||||||
urllib3==2.8.0
|
urllib3==2.8.0
|
||||||
@@ -19,7 +19,6 @@ jobs:
|
|||||||
name: Test installer
|
name: Test installer
|
||||||
if: github.repository == 'ohmyzsh/ohmyzsh'
|
if: github.repository == 'ohmyzsh/ohmyzsh'
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
timeout-minutes: 15
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os:
|
os:
|
||||||
@@ -27,12 +26,12 @@ jobs:
|
|||||||
- macos-latest
|
- macos-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Harden the runner (Audit all outbound calls)
|
- name: Harden the runner (Audit all outbound calls)
|
||||||
uses: step-security/harden-runner@v2.23.0
|
uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: Set up git repository
|
- name: Set up git repository
|
||||||
uses: actions/checkout@v7.0.1
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
- name: Install zsh
|
- name: Install zsh
|
||||||
if: runner.os == 'Linux'
|
if: runner.os == 'Linux'
|
||||||
run: sudo apt-get update; sudo apt-get install zsh
|
run: sudo apt-get update; sudo apt-get install zsh
|
||||||
@@ -43,28 +42,19 @@ jobs:
|
|||||||
name: Deploy installer in install.ohmyz.sh
|
name: Deploy installer in install.ohmyz.sh
|
||||||
if: github.ref == 'refs/heads/master'
|
if: github.ref == 'refs/heads/master'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 15
|
|
||||||
environment: vercel
|
environment: vercel
|
||||||
needs:
|
needs:
|
||||||
- test
|
- test
|
||||||
steps:
|
steps:
|
||||||
- name: Harden the runner (Audit all outbound calls)
|
- name: Harden the runner (Audit all outbound calls)
|
||||||
uses: step-security/harden-runner@v2.23.0
|
uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v7.0.1
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- name: Set up Node.js
|
|
||||||
uses: actions/setup-node@v7.1.0
|
|
||||||
with:
|
|
||||||
node-version: "24"
|
|
||||||
package-manager-cache: false
|
|
||||||
- name: Install Vercel CLI
|
- name: Install Vercel CLI
|
||||||
working-directory: .github/workflows/installer
|
run: npm install -g vercel
|
||||||
run: npm ci --ignore-scripts --no-audit --no-fund
|
|
||||||
- name: Setup project and deploy
|
- name: Setup project and deploy
|
||||||
env:
|
env:
|
||||||
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
|
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
|
||||||
@@ -73,4 +63,4 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
cp tools/install.sh .github/workflows/installer/install.sh
|
cp tools/install.sh .github/workflows/installer/install.sh
|
||||||
cd .github/workflows/installer
|
cd .github/workflows/installer
|
||||||
./node_modules/.bin/vercel deploy --prod -t "$VERCEL_TOKEN"
|
vc deploy --prod -t "$VERCEL_TOKEN"
|
||||||
@@ -1,2 +1 @@
|
|||||||
install.sh
|
install.sh
|
||||||
node_modules/
|
|
||||||
-5585
File diff suppressed because it is too large.
Load diff
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "ohmyzsh-installer-deploy",
|
|
||||||
"private": true,
|
|
||||||
"devDependencies": {
|
|
||||||
"vercel": "66.6.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
name: Workflow lint
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
|
||||||
cancel-in-progress: true
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
jactionlint:
|
|
||||||
name: Lint GitHub Actions
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
timeout-minutes: 10
|
|
||||||
steps:
|
|
||||||
- name: Harden the runner (Audit all outbound calls)
|
|
||||||
uses: step-security/harden-runner@v2.23.0
|
|
||||||
with:
|
|
||||||
egress-policy: audit
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v7.0.1
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- name: Lint workflows and Dependabot configuration
|
|
||||||
uses: jdx/jactionlint@v2.6.0
|
|
||||||
with:
|
|
||||||
profile: default
|
|
||||||
online: "false"
|
|
||||||
- name: Verify action lockfile
|
|
||||||
uses: github/gh-actions-lock@verify/v0.5.1
|
|
||||||
@@ -21,55 +21,23 @@ jobs:
|
|||||||
tests:
|
tests:
|
||||||
name: Run tests
|
name: Run tests
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 10
|
|
||||||
if: github.repository == 'ohmyzsh/ohmyzsh'
|
if: github.repository == 'ohmyzsh/ohmyzsh'
|
||||||
steps:
|
steps:
|
||||||
- name: Harden the runner (Audit all outbound calls)
|
- name: Harden the runner (Audit all outbound calls)
|
||||||
uses: step-security/harden-runner@v2.23.0
|
uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: Set up git repository
|
- name: Set up git repository
|
||||||
uses: actions/checkout@v7.0.1
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
- name: Install zsh
|
- name: Install zsh
|
||||||
run: sudo apt-get update; sudo apt-get install zsh
|
run: sudo apt-get update; sudo apt-get install zsh
|
||||||
- name: Check syntax
|
- name: Check syntax
|
||||||
run: |
|
run: |
|
||||||
for file in ./oh-my-zsh.sh \
|
for file in ./oh-my-zsh.sh \
|
||||||
./lib/*.zsh \
|
./lib/*.zsh \
|
||||||
./functions/* \
|
|
||||||
./completions/_* \
|
|
||||||
./plugins/*/*.plugin.zsh \
|
./plugins/*/*.plugin.zsh \
|
||||||
./plugins/*/_* \
|
./plugins/*/_* \
|
||||||
./themes/*.zsh-theme; do
|
./themes/*.zsh-theme; do
|
||||||
zsh -n "$file" || exit 1
|
zsh -n "$file" || return 1
|
||||||
done
|
done
|
||||||
|
|
||||||
collisions:
|
|
||||||
name: Check alias collisions
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
timeout-minutes: 10
|
|
||||||
steps:
|
|
||||||
- name: Set up git repository
|
|
||||||
uses: actions/checkout@v7.0.1
|
|
||||||
- name: Set up Python
|
|
||||||
uses: actions/setup-python@v7.1.0
|
|
||||||
with:
|
|
||||||
python-version: '3.14'
|
|
||||||
- name: Install dependencies
|
|
||||||
run: |
|
|
||||||
python -m pip install --upgrade pip
|
|
||||||
pip install -r .github/workflows/alias_collision/requirements.txt
|
|
||||||
- name: Run unit tests
|
|
||||||
run: |
|
|
||||||
cd .github/workflows/alias_collision/
|
|
||||||
python -m pytest
|
|
||||||
- name: Checkout target branch
|
|
||||||
uses: actions/checkout@v7.0.1
|
|
||||||
with:
|
|
||||||
path: ohmyzsh-target-branch
|
|
||||||
ref: master
|
|
||||||
- name: Check for alias collisions on target branch
|
|
||||||
run: python .github/workflows/alias_collision/check_alias_collision.py ohmyzsh-target-branch/plugins --known-collisions-output-path known_alias_collisions.json
|
|
||||||
- name: Compare known collisions to new collisions on source branch
|
|
||||||
run: python .github/workflows/alias_collision/check_alias_collision.py plugins --known-collisions known_alias_collisions.json
|
|
||||||
@@ -2,8 +2,6 @@ name: Project tracking
|
|||||||
on:
|
on:
|
||||||
issues:
|
issues:
|
||||||
types: [opened, reopened]
|
types: [opened, reopened]
|
||||||
# Board updates need an App token for fork PRs; no PR code is checked out or run.
|
|
||||||
# jactionlint ignore=dangerous-triggers
|
|
||||||
pull_request_target:
|
pull_request_target:
|
||||||
types: [opened, reopened, synchronize]
|
types: [opened, reopened, synchronize]
|
||||||
|
|
||||||
@@ -16,35 +14,25 @@ jobs:
|
|||||||
add-to-project:
|
add-to-project:
|
||||||
name: Add to project
|
name: Add to project
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 10
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
shell: bash
|
|
||||||
if: github.repository == 'ohmyzsh/ohmyzsh'
|
if: github.repository == 'ohmyzsh/ohmyzsh'
|
||||||
steps:
|
steps:
|
||||||
- name: Harden the runner (Audit all outbound calls)
|
- name: Harden the runner (Audit all outbound calls)
|
||||||
uses: step-security/harden-runner@v2.23.0
|
uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
- name: Authenticate as @ohmyzsh
|
- name: Authenticate as @ohmyzsh
|
||||||
id: generate-token
|
id: generate-token
|
||||||
uses: actions/create-github-app-token@v3.4.0
|
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
|
||||||
with:
|
with:
|
||||||
client-id: ${{ secrets.OHMYZSH_CLIENT_ID }}
|
client-id: ${{ secrets.OHMYZSH_CLIENT_ID }}
|
||||||
private-key: ${{ secrets.OHMYZSH_APP_PRIVATE_KEY }}
|
private-key: ${{ secrets.OHMYZSH_APP_PRIVATE_KEY }}
|
||||||
permission-organization-projects: write
|
|
||||||
permission-issues: read
|
|
||||||
permission-pull-requests: read
|
|
||||||
- name: Read project data
|
- name: Read project data
|
||||||
id: project
|
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
|
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
|
||||||
ORGANIZATION: ohmyzsh
|
ORGANIZATION: ohmyzsh
|
||||||
PROJECT_NUMBER: "1"
|
PROJECT_NUMBER: "1"
|
||||||
run: |
|
run: |
|
||||||
# Get Project data
|
# Get Project data
|
||||||
# GraphQL variables must reach GitHub literally.
|
|
||||||
# shellcheck disable=SC2016
|
|
||||||
gh api graphql -f query='
|
gh api graphql -f query='
|
||||||
query($org: String!, $number: Int!) {
|
query($org: String!, $number: Int!) {
|
||||||
organization(login: $org){
|
organization(login: $org){
|
||||||
@@ -60,29 +48,19 @@ jobs:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}' -f org="$ORGANIZATION" -F number="$PROJECT_NUMBER" > project_data.json
|
}' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json
|
||||||
|
|
||||||
# Parse project data
|
# Parse project data
|
||||||
PROJECT_ID=$(jq -er '.data.organization.projectV2.id' project_data.json)
|
cat >> "$GITHUB_ENV" <<EOF
|
||||||
PLUGIN_FIELD_ID=$(jq -er '.data.organization.projectV2.fields.nodes[] | select(.name == "Plugin") | .id' project_data.json)
|
PROJECT_ID=$(jq '.data.organization.projectV2.id' project_data.json)
|
||||||
THEME_FIELD_ID=$(jq -er '.data.organization.projectV2.fields.nodes[] | select(.name == "Theme") | .id' project_data.json)
|
PLUGIN_FIELD_ID=$(jq '.data.organization.projectV2.fields.nodes[] | select(.name == "Plugin") | .id' project_data.json)
|
||||||
for id in "$PROJECT_ID" "$PLUGIN_FIELD_ID" "$THEME_FIELD_ID"; do
|
THEME_FIELD_ID=$(jq '.data.organization.projectV2.fields.nodes[] | select(.name == "Theme") | .id' project_data.json)
|
||||||
[[ "$id" =~ ^[A-Za-z0-9_=/+-]+$ ]] || exit 1
|
EOF
|
||||||
done
|
|
||||||
{
|
|
||||||
echo "PROJECT_ID=$PROJECT_ID"
|
|
||||||
echo "PLUGIN_FIELD_ID=$PLUGIN_FIELD_ID"
|
|
||||||
echo "THEME_FIELD_ID=$THEME_FIELD_ID"
|
|
||||||
} >> "$GITHUB_OUTPUT"
|
|
||||||
- name: Add to project
|
- name: Add to project
|
||||||
id: item
|
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
|
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
|
||||||
ISSUE_OR_PR_ID: ${{ github.event.issue.node_id || github.event.pull_request.node_id }}
|
ISSUE_OR_PR_ID: ${{ github.event.issue.node_id || github.event.pull_request.node_id }}
|
||||||
PROJECT_ID: ${{ steps.project.outputs.PROJECT_ID }}
|
|
||||||
run: |
|
run: |
|
||||||
# GraphQL variables must reach GitHub literally.
|
|
||||||
# shellcheck disable=SC2016
|
|
||||||
item_id="$(gh api graphql -f query='
|
item_id="$(gh api graphql -f query='
|
||||||
mutation($project: ID!, $content: ID!) {
|
mutation($project: ID!, $content: ID!) {
|
||||||
addProjectV2ItemById(input: {projectId: $project, contentId: $content}) {
|
addProjectV2ItemById(input: {projectId: $project, contentId: $content}) {
|
||||||
@@ -91,12 +69,10 @@ jobs:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
' -f project="$PROJECT_ID" -f content="$ISSUE_OR_PR_ID" --jq '.data.addProjectV2ItemById.item.id // error("missing project item ID")')"
|
' -f project="$PROJECT_ID" -f content="$ISSUE_OR_PR_ID" --jq '.data.addProjectV2ItemById.item.id')"
|
||||||
|
|
||||||
[[ "$item_id" =~ ^[A-Za-z0-9_=/+-]+$ ]] || exit 1
|
echo "ITEM_ID=$item_id" >> $GITHUB_ENV
|
||||||
echo "ITEM_ID=$item_id" >> "$GITHUB_OUTPUT"
|
|
||||||
- name: Classify Pull Request
|
- name: Classify Pull Request
|
||||||
id: classify
|
|
||||||
if: github.event_name == 'pull_request_target'
|
if: github.event_name == 'pull_request_target'
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
|
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
|
||||||
@@ -133,20 +109,12 @@ jobs:
|
|||||||
print "THEME=" theme
|
print "THEME=" theme
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
' >> "$GITHUB_OUTPUT"
|
' >> "$GITHUB_ENV"
|
||||||
- name: Fill Pull Request fields in project
|
- name: Fill Pull Request fields in project
|
||||||
if: github.event_name == 'pull_request_target'
|
if: github.event_name == 'pull_request_target'
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
|
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
|
||||||
PROJECT_ID: ${{ steps.project.outputs.PROJECT_ID }}
|
|
||||||
ITEM_ID: ${{ steps.item.outputs.ITEM_ID }}
|
|
||||||
PLUGIN_FIELD_ID: ${{ steps.project.outputs.PLUGIN_FIELD_ID }}
|
|
||||||
PLUGIN: ${{ steps.classify.outputs.PLUGIN }}
|
|
||||||
THEME_FIELD_ID: ${{ steps.project.outputs.THEME_FIELD_ID }}
|
|
||||||
THEME: ${{ steps.classify.outputs.THEME }}
|
|
||||||
run: |
|
run: |
|
||||||
# GraphQL variables must reach GitHub literally.
|
|
||||||
# shellcheck disable=SC2016
|
|
||||||
gh api graphql -f query='
|
gh api graphql -f query='
|
||||||
mutation (
|
mutation (
|
||||||
$project: ID!
|
$project: ID!
|
||||||
|
|||||||
@@ -14,18 +14,13 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches: ["master"]
|
branches: ["master"]
|
||||||
|
|
||||||
concurrency:
|
# Declare default permissions as read only.
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
permissions: read-all
|
||||||
cancel-in-progress: true
|
|
||||||
|
|
||||||
# Permissions are granted only to the analysis job.
|
|
||||||
permissions: {}
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
analysis:
|
analysis:
|
||||||
name: Scorecard analysis
|
name: Scorecard analysis
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 15
|
|
||||||
permissions:
|
permissions:
|
||||||
# Needed to upload the results to code-scanning dashboard.
|
# Needed to upload the results to code-scanning dashboard.
|
||||||
security-events: write
|
security-events: write
|
||||||
@@ -41,30 +36,30 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden the runner (Audit all outbound calls)
|
- name: Harden the runner (Audit all outbound calls)
|
||||||
uses: step-security/harden-runner@v2.23.0
|
uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
- name: "Checkout code"
|
- name: "Checkout code"
|
||||||
uses: actions/checkout@v7.0.1
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
- name: "Run analysis"
|
- name: "Run analysis"
|
||||||
uses: ossf/scorecard-action@v2.6.0
|
uses: ossf/scorecard-action@2d1146689b8cda280b9bc96326124645441f03bc # v2.4.4
|
||||||
with:
|
with:
|
||||||
results_file: results.sarif
|
results_file: results.sarif
|
||||||
results_format: sarif
|
results_format: sarif
|
||||||
publish_results: true
|
publish_results: true
|
||||||
|
|
||||||
- name: "Upload artifact"
|
- name: "Upload artifact"
|
||||||
uses: actions/upload-artifact@v7.0.2
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||||
with:
|
with:
|
||||||
name: SARIF file
|
name: SARIF file
|
||||||
path: results.sarif
|
path: results.sarif
|
||||||
retention-days: 5
|
retention-days: 5
|
||||||
|
|
||||||
- name: "Upload to code-scanning"
|
- name: "Upload to code-scanning"
|
||||||
uses: github/codeql-action/upload-sarif@v4.39.5
|
uses: github/codeql-action/upload-sarif@2892aa5e19bbd11bc0cff5427e3b750a04d9e3c2 # v4.38.2
|
||||||
with:
|
with:
|
||||||
sarif_file: results.sarif
|
sarif_file: results.sarif
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
# Instructions for coding agents
|
|
||||||
|
|
||||||
Oh My Zsh is maintained by a small team of volunteers. A person reviews every
|
|
||||||
pull request, so help the contributor send one that is easy to review.
|
|
||||||
|
|
||||||
## Before opening a pull request
|
|
||||||
|
|
||||||
1. Read [CONTRIBUTING.md](CONTRIBUTING.md) and follow it.
|
|
||||||
2. Search open pull requests and issues for the same change. If one exists,
|
|
||||||
tell the contributor instead of opening a duplicate.
|
|
||||||
3. Fill in [.github/PULL_REQUEST_TEMPLATE.md](.github/PULL_REQUEST_TEMPLATE.md).
|
|
||||||
Keep its sections and its checklist.
|
|
||||||
4. Use the [commit format](CONTRIBUTING.md#commit-guidelines) for commits and
|
|
||||||
for the pull request title.
|
|
||||||
|
|
||||||
## Writing the description
|
|
||||||
|
|
||||||
- Report only evidence you have. Don't invent user requests, test results,
|
|
||||||
or demo links.
|
|
||||||
- Separate checks you ran from testing the contributor did. Don't claim
|
|
||||||
personal testing or confirmation on their behalf.
|
|
||||||
- Leave unconfirmed checklist items unchecked, and name any missing testing
|
|
||||||
or demo.
|
|
||||||
- Don't commit the contributor to follow-up work they haven't agreed to.
|
|
||||||
- Disclose meaningful AI assistance in "Other notes".
|
|
||||||
- Put file names and paths in backticks so they render as code.
|
|
||||||
|
|
||||||
## Keeping the change reviewable
|
|
||||||
|
|
||||||
- One purpose per pull request. Keep the diff small, and leave unrelated
|
|
||||||
files alone.
|
|
||||||
- Follow the [code style guide](https://github.com/ohmyzsh/ohmyzsh/wiki/Code-Style-Guide).
|
|
||||||
- The contributor must be able to explain the change. If they can't yet,
|
|
||||||
explain it to them before the pull request is opened.
|
|
||||||
@@ -20,7 +20,6 @@ you would make is not already covered.
|
|||||||
- [Getting started](#getting-started)
|
- [Getting started](#getting-started)
|
||||||
- [You have a solution](#you-have-a-solution)
|
- [You have a solution](#you-have-a-solution)
|
||||||
- [You have an addition](#you-have-an-addition)
|
- [You have an addition](#you-have-an-addition)
|
||||||
- [Writing your PR description](#writing-your-pr-description)
|
|
||||||
- [A note on AI-assisted contributions](#a-note-on-ai-assisted-contributions)
|
- [A note on AI-assisted contributions](#a-note-on-ai-assisted-contributions)
|
||||||
- [Use the Search, Luke](#use-the-search-luke)
|
- [Use the Search, Luke](#use-the-search-luke)
|
||||||
- [Commit Guidelines](#commit-guidelines)
|
- [Commit Guidelines](#commit-guidelines)
|
||||||
@@ -127,34 +126,6 @@ Because of this, from now on, we require that new aliases follow these condition
|
|||||||
This list is not exhaustive! Please remember that your alias will be in the machines of many people,
|
This list is not exhaustive! Please remember that your alias will be in the machines of many people,
|
||||||
so it should be justified why they should have it.
|
so it should be justified why they should have it.
|
||||||
|
|
||||||
### Writing your PR description
|
|
||||||
|
|
||||||
Use the [PR template](.github/PULL_REQUEST_TEMPLATE.md) to help people understand
|
|
||||||
the purpose of your change before they reach the submission checklist. Keep answers
|
|
||||||
short and proportional to the change; a sentence or two per section is often enough.
|
|
||||||
|
|
||||||
Oh My Zsh should make the command line more delightful. Tell us whose day your
|
|
||||||
change makes easier, clearer, or more enjoyable, and how. Scratching your own itch
|
|
||||||
is a welcome starting point! Your change doesn't need to help everyone, but explain
|
|
||||||
why it would be useful to others and belongs in the shared project. Link relevant
|
|
||||||
requests or examples when you have them; otherwise, explain the expected benefit
|
|
||||||
without claiming demand you haven't seen.
|
|
||||||
|
|
||||||
For user-facing changes, include screenshots, a GIF, or a short video showing
|
|
||||||
before/after behavior. For a new feature, demonstrate it in use. Label the examples,
|
|
||||||
keep terminal text readable, and remove private information. For low-level or other
|
|
||||||
non-visual changes, explain why a visual wouldn't be useful. If a demo is needed
|
|
||||||
but you can't capture it yet, say so rather than marking it inapplicable.
|
|
||||||
|
|
||||||
Describe the checks actually run and their results, relevant environment versions,
|
|
||||||
and any testing gaps. Distinguish automated or agent-run checks from testing you
|
|
||||||
personally performed. For documentation-only changes, describe what you checked.
|
|
||||||
Only check the personal-testing item after you've done that testing yourself.
|
|
||||||
|
|
||||||
For features and enhancements, tell us how you'll help users discover and use them.
|
|
||||||
A plugin README update, a usage example, or sharing your demo are good ways to help.
|
|
||||||
Be clear about what's included in the PR and what's planned for later.
|
|
||||||
|
|
||||||
## A note on AI-assisted contributions
|
## A note on AI-assisted contributions
|
||||||
|
|
||||||
We'll admit it: AI tools can be pretty helpful for coding tasks, and we're not here to gatekeep how you get your work done. We use these tools ourselves! 🤖
|
We'll admit it: AI tools can be pretty helpful for coding tasks, and we're not here to gatekeep how you get your work done. We use these tools ourselves! 🤖
|
||||||
@@ -179,9 +150,6 @@ The disclosure helps us know how much guidance to offer. If we're just reviewing
|
|||||||
|
|
||||||
As always, we reserve the right to decline any contribution. PRs that appear to be unreviewed AI output, or code the contributor can't explain, may be closed without extensive feedback.
|
As always, we reserve the right to decline any contribution. PRs that appear to be unreviewed AI output, or code the contributor can't explain, may be closed without extensive feedback.
|
||||||
|
|
||||||
**For coding agents:** follow [AGENTS.md](AGENTS.md). It covers what to read
|
|
||||||
before drafting a PR and how to keep the description grounded in evidence.
|
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
## Use the Search, Luke
|
## Use the Search, Luke
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ Twitter), and join us on [Discord](https://discord.gg/ohmyzsh).
|
|||||||
- [Using Plugins](#using-plugins)
|
- [Using Plugins](#using-plugins)
|
||||||
- [Themes](#themes)
|
- [Themes](#themes)
|
||||||
- [Selecting A Theme](#selecting-a-theme)
|
- [Selecting A Theme](#selecting-a-theme)
|
||||||
- [Shellsavers](#shellsavers)
|
|
||||||
- [FAQ](#faq)
|
- [FAQ](#faq)
|
||||||
- [Advanced Topics](#advanced-topics)
|
- [Advanced Topics](#advanced-topics)
|
||||||
- [Advanced Installation](#advanced-installation)
|
- [Advanced Installation](#advanced-installation)
|
||||||
@@ -242,33 +241,6 @@ If you only know which themes you don't like, you can add them similarly to an i
|
|||||||
ZSH_THEME_RANDOM_IGNORED=(pygmalion tjkirch_mod)
|
ZSH_THEME_RANDOM_IGNORED=(pygmalion tjkirch_mod)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Shellsavers
|
|
||||||
|
|
||||||
Give your terminal a little downtime with `omz shellsaver`—our playful name for
|
|
||||||
terminal screensavers. The aquarium is the default; choose another scene to change the mood:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
omz shellsaver # A quiet aquarium full of sea shells
|
|
||||||
omz shellsaver logo # The updater's rainbow logo, bouncing around
|
|
||||||
omz shellsaver hermit # A slightly lost hermit crab
|
|
||||||
omz shellsaver party # A rainbow stage and a dancing crowd
|
|
||||||
```
|
|
||||||
|
|
||||||
Press any key or Ctrl-C to return to your shell. Screensavers run only when invoked
|
|
||||||
and restore the terminal when they exit. No plugin or configuration change is needed.
|
|
||||||
Use `omz help` to discover the command, and Tab to complete scene names and options.
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
omz shellsaver aquarium --seconds 30 # Stop automatically after 30 seconds
|
|
||||||
omz shellsaver logo --mono # Use the terminal's foreground color
|
|
||||||
omz shellsaver --list # List scenes (aquarium is the default)
|
|
||||||
omz shellsaver --help # Show all scenes and options
|
|
||||||
```
|
|
||||||
|
|
||||||
Requires Zsh 5.8 or newer, `stty`, and an xterm-compatible terminal with alternate-screen
|
|
||||||
support. No additional animation package is required. `NO_COLOR` is respected.
|
|
||||||
A window of at least 49 columns by 18 rows is recommended.
|
|
||||||
|
|
||||||
### FAQ
|
### FAQ
|
||||||
|
|
||||||
If you have some more questions or issues, you might find a solution in our
|
If you have some more questions or issues, you might find a solution in our
|
||||||
@@ -552,20 +524,6 @@ omz update
|
|||||||
|
|
||||||
Magic! 🎉
|
Magic! 🎉
|
||||||
|
|
||||||
## Diagnostics
|
|
||||||
|
|
||||||
If something looks off (glitched characters, completions misbehaving), run:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
omz diagnose
|
|
||||||
```
|
|
||||||
|
|
||||||
It runs a few quick checks and tells you what to fix — for example, it will warn you when
|
|
||||||
your locale is not UTF-8, which is a common cause of duplicated characters at the prompt
|
|
||||||
(see the [FAQ](https://github.com/ohmyzsh/ohmyzsh/wiki/FAQ#i-see-duplicate-typed-characters-after-i-complete-a-command)).
|
|
||||||
|
|
||||||
For a full report suitable for attaching to a bug report, use `omz_diagnostic_dump`.
|
|
||||||
|
|
||||||
## Uninstalling Oh My Zsh
|
## Uninstalling Oh My Zsh
|
||||||
|
|
||||||
Oh My Zsh isn't for everyone. We'll miss you, but we want to make this an easy breakup.
|
Oh My Zsh isn't for everyone. We'll miss you, but we want to make this an easy breakup.
|
||||||
|
|||||||
@@ -1,104 +0,0 @@
|
|||||||
#compdef omz
|
|
||||||
|
|
||||||
local -a cmds subcmds
|
|
||||||
cmds=(
|
|
||||||
'changelog:Print the changelog'
|
|
||||||
'diagnose:Run configuration diagnostics'
|
|
||||||
'help:Usage information'
|
|
||||||
'plugin:Manage plugins'
|
|
||||||
'pr:Manage Oh My Zsh Pull Requests'
|
|
||||||
'reload:Reload the current zsh session'
|
|
||||||
'shellsaver:Launch a whimsical terminal screensaver'
|
|
||||||
'shop:Open the Oh My Zsh shop'
|
|
||||||
'theme:Manage themes'
|
|
||||||
'update:Update Oh My Zsh'
|
|
||||||
'version:Show the version'
|
|
||||||
)
|
|
||||||
|
|
||||||
if [[ "$words[2]" == (screensaver|shellsaver) ]] && (( CURRENT > 2 )); then
|
|
||||||
_arguments \
|
|
||||||
'1:command:' \
|
|
||||||
'2::scene:(aquarium logo hermit party)' \
|
|
||||||
'--list[List available scenes]' \
|
|
||||||
'--mono[Use the default foreground color]' \
|
|
||||||
'--seconds[Exit after a number of seconds]:seconds:' \
|
|
||||||
'--snapshot[Print a plain-text still]::frame:' \
|
|
||||||
'--help[Show Shellsaver help]'
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
if (( CURRENT == 2 )); then
|
|
||||||
_describe 'command' cmds
|
|
||||||
elif (( CURRENT == 3 )); then
|
|
||||||
case "$words[2]" in
|
|
||||||
changelog) local -a refs
|
|
||||||
refs=("${(@f)$(builtin cd -q "$ZSH"; command git for-each-ref --format="%(refname:short):%(subject)" refs/heads refs/tags)}")
|
|
||||||
_describe 'command' refs ;;
|
|
||||||
plugin) subcmds=(
|
|
||||||
'disable:Disable plugin(s)'
|
|
||||||
'enable:Enable plugin(s)'
|
|
||||||
'info:Get plugin information'
|
|
||||||
'list:List plugins'
|
|
||||||
'load:Load plugin(s)'
|
|
||||||
)
|
|
||||||
_describe 'command' subcmds ;;
|
|
||||||
pr) subcmds=('clean:Delete all Pull Request branches' 'test:Test a Pull Request')
|
|
||||||
_describe 'command' subcmds ;;
|
|
||||||
theme) subcmds=('list:List themes' 'set:Set a theme in your .zshrc file' 'use:Load a theme')
|
|
||||||
_describe 'command' subcmds ;;
|
|
||||||
esac
|
|
||||||
elif (( CURRENT == 4 )); then
|
|
||||||
case "${words[2]}::${words[3]}" in
|
|
||||||
plugin::(disable|enable|load))
|
|
||||||
local -aU valid_plugins
|
|
||||||
|
|
||||||
if [[ "${words[3]}" = disable ]]; then
|
|
||||||
# if command is "disable", only offer already enabled plugins
|
|
||||||
valid_plugins=($plugins)
|
|
||||||
else
|
|
||||||
valid_plugins=("$ZSH"/plugins/*/{_*,*.plugin.zsh}(-.N:h:t) "$ZSH_CUSTOM"/plugins/*/{_*,*.plugin.zsh}(-.N:h:t))
|
|
||||||
# if command is "enable", remove already enabled plugins
|
|
||||||
[[ "${words[3]}" = enable ]] && valid_plugins=(${valid_plugins:|plugins})
|
|
||||||
fi
|
|
||||||
|
|
||||||
_describe 'plugin' valid_plugins ;;
|
|
||||||
plugin::info)
|
|
||||||
local -aU plugins
|
|
||||||
plugins=("$ZSH"/plugins/*/{_*,*.plugin.zsh}(-.N:h:t) "$ZSH_CUSTOM"/plugins/*/{_*,*.plugin.zsh}(-.N:h:t))
|
|
||||||
_describe 'plugin' plugins ;;
|
|
||||||
plugin::list)
|
|
||||||
local -a opts
|
|
||||||
opts=('--enabled:List enabled plugins only')
|
|
||||||
_describe -o 'options' opts ;;
|
|
||||||
theme::(set|use))
|
|
||||||
local -aU themes
|
|
||||||
themes=("$ZSH"/themes/*.zsh-theme(-.N:t:r) "$ZSH_CUSTOM"/**/*.zsh-theme(-.N:r:gs:"$ZSH_CUSTOM"/themes/:::gs:"$ZSH_CUSTOM"/:::))
|
|
||||||
_describe 'theme' themes ;;
|
|
||||||
esac
|
|
||||||
elif (( CURRENT > 4 )); then
|
|
||||||
case "${words[2]}::${words[3]}" in
|
|
||||||
plugin::(enable|disable|load))
|
|
||||||
local -aU valid_plugins
|
|
||||||
|
|
||||||
if [[ "${words[3]}" = disable ]]; then
|
|
||||||
# if command is "disable", only offer already enabled plugins
|
|
||||||
valid_plugins=($plugins)
|
|
||||||
else
|
|
||||||
valid_plugins=("$ZSH"/plugins/*/{_*,*.plugin.zsh}(-.N:h:t) "$ZSH_CUSTOM"/plugins/*/{_*,*.plugin.zsh}(-.N:h:t))
|
|
||||||
# if command is "enable", remove already enabled plugins
|
|
||||||
[[ "${words[3]}" = enable ]] && valid_plugins=(${valid_plugins:|plugins})
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Remove plugins already passed as arguments
|
|
||||||
# NOTE: $(( CURRENT - 1 )) is the last plugin argument completely passed, i.e. that which
|
|
||||||
# has a space after them. This is to avoid removing plugins partially passed, which makes
|
|
||||||
# the completion not add a space after the completed plugin.
|
|
||||||
local -a args
|
|
||||||
args=(${words[4,$(( CURRENT - 1))]})
|
|
||||||
valid_plugins=(${valid_plugins:|args})
|
|
||||||
|
|
||||||
_describe 'plugin' valid_plugins ;;
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
|
|
||||||
return 0
|
|
||||||
-897
@@ -1,897 +0,0 @@
|
|||||||
function omz {
|
|
||||||
setopt localoptions noksharrays
|
|
||||||
[[ $# -gt 0 ]] || {
|
|
||||||
_omz::help
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
local command="$1"
|
|
||||||
shift
|
|
||||||
|
|
||||||
# Subcommand functions start with _ so that they don't
|
|
||||||
# appear as completion entries when looking for `omz`
|
|
||||||
(( ${+functions[_omz::$command]} )) || {
|
|
||||||
_omz::help
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
_omz::$command "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
## Utility functions
|
|
||||||
|
|
||||||
function _omz::confirm {
|
|
||||||
# If question supplied, ask it before reading the answer
|
|
||||||
# NOTE: uses the logname of the caller function
|
|
||||||
if [[ -n "$1" ]]; then
|
|
||||||
_omz::log prompt "$1" "${${functrace[1]#_}%:*}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Read one character
|
|
||||||
read -r -k 1
|
|
||||||
|
|
||||||
# If no newline entered, add a newline
|
|
||||||
if [[ "$REPLY" != $'\n' ]]; then
|
|
||||||
echo
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function _omz::log {
|
|
||||||
# if promptsubst is set, a message with `` or $()
|
|
||||||
# will be run even if quoted due to `print -P`
|
|
||||||
setopt localoptions nopromptsubst
|
|
||||||
|
|
||||||
# $1 = info|warn|error|debug
|
|
||||||
# $2 = text
|
|
||||||
# $3 = (optional) name of the logger
|
|
||||||
|
|
||||||
local logtype=$1
|
|
||||||
local logname=${3:-${${functrace[1]#_}%:*}}
|
|
||||||
|
|
||||||
# Don't print anything if debug is not active
|
|
||||||
if [[ $logtype = debug && -z $_OMZ_DEBUG ]]; then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Choose coloring based on log type
|
|
||||||
case "$logtype" in
|
|
||||||
prompt) print -Pn "%S%F{blue}$logname%f%s: $2" ;;
|
|
||||||
debug) print -P "%F{white}$logname%f: $2" ;;
|
|
||||||
info) print -P "%F{green}$logname%f: $2" ;;
|
|
||||||
warn) print -P "%S%F{yellow}$logname%f%s: $2" ;;
|
|
||||||
error) print -P "%S%F{red}$logname%f%s: $2" ;;
|
|
||||||
esac >&2
|
|
||||||
}
|
|
||||||
|
|
||||||
## User-facing commands
|
|
||||||
|
|
||||||
function _omz::diagnose {
|
|
||||||
# Check the runtime locale: non-UTF-8 charsets are known to cause glitches
|
|
||||||
# such as duplicated characters at the prompt after completions.
|
|
||||||
# https://github.com/ohmyzsh/ohmyzsh/wiki/FAQ#i-see-duplicate-typed-characters-after-i-complete-a-command
|
|
||||||
#
|
|
||||||
# `lib/functions.zsh` loads the zsh/langinfo module at startup, so the
|
|
||||||
# CODESET parameter is already available without any subprocess; only fall
|
|
||||||
# back to `locale charmap` when that module is unavailable (zsh built without it).
|
|
||||||
local codeset="${langinfo[CODESET]:-}"
|
|
||||||
if [[ -z "$codeset" ]] && (( $+commands[locale] )); then
|
|
||||||
codeset="$(locale charmap 2>/dev/null)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "${codeset:l}" = (utf-8|utf8) ]]; then
|
|
||||||
_omz::log info "locale charmap is UTF-8"
|
|
||||||
else
|
|
||||||
_omz::log warn "your locale is not UTF-8 (charmap: ${codeset:-unknown})"
|
|
||||||
_omz::log info "non-UTF-8 locales may cause glitches in completions and international characters"
|
|
||||||
_omz::log info "consider setting a UTF-8 locale, e.g.: export LANG=C.UTF-8"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function _omz::help {
|
|
||||||
cat >&2 <<EOF
|
|
||||||
Usage: omz <command> [options]
|
|
||||||
|
|
||||||
Available commands:
|
|
||||||
|
|
||||||
diagnose Run configuration diagnostics
|
|
||||||
help Print this help message
|
|
||||||
changelog Print the changelog
|
|
||||||
plugin <command> Manage plugins
|
|
||||||
pr <command> Manage Oh My Zsh Pull Requests
|
|
||||||
reload Reload the current zsh session
|
|
||||||
shellsaver [scene] Launch a Shellsaver (aquarium by default)
|
|
||||||
shop Open the Oh My Zsh shop
|
|
||||||
theme <command> Manage themes
|
|
||||||
update Update Oh My Zsh
|
|
||||||
version Show the version
|
|
||||||
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
function _omz::shellsaver {
|
|
||||||
command zsh -f "$ZSH/tools/shellsaver.zsh" "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Hidden alias; only shellsaver is advertised in help and command completion.
|
|
||||||
function _omz::screensaver {
|
|
||||||
_omz::shellsaver "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
function _omz::changelog {
|
|
||||||
local version=${1:-HEAD} format=${3:-"--text"}
|
|
||||||
|
|
||||||
if (
|
|
||||||
builtin cd -q "$ZSH"
|
|
||||||
! command git show-ref --verify refs/heads/$version && \
|
|
||||||
! command git show-ref --verify refs/tags/$version && \
|
|
||||||
! command git rev-parse --verify "${version}^{commit}"
|
|
||||||
) &>/dev/null; then
|
|
||||||
cat >&2 <<EOF
|
|
||||||
Usage: ${(j: :)${(s.::.)0#_}} [version]
|
|
||||||
|
|
||||||
NOTE: <version> must be a valid branch, tag or commit.
|
|
||||||
EOF
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
ZSH="$ZSH" command zsh -f "$ZSH/tools/changelog.sh" "$version" "${2:-}" "$format"
|
|
||||||
}
|
|
||||||
|
|
||||||
function _omz::plugin {
|
|
||||||
(( $# > 0 && $+functions[$0::$1] )) || {
|
|
||||||
cat >&2 <<EOF
|
|
||||||
Usage: ${(j: :)${(s.::.)0#_}} <command> [options]
|
|
||||||
|
|
||||||
Available commands:
|
|
||||||
|
|
||||||
disable <plugin> Disable plugin(s)
|
|
||||||
enable <plugin> Enable plugin(s)
|
|
||||||
info <plugin> Get information of a plugin
|
|
||||||
list [--enabled] List Oh My Zsh plugins
|
|
||||||
load <plugin> Load plugin(s)
|
|
||||||
|
|
||||||
EOF
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
local command="$1"
|
|
||||||
shift
|
|
||||||
|
|
||||||
$0::$command "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
function _omz::plugin::disable {
|
|
||||||
if [[ -z "$1" ]]; then
|
|
||||||
echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <plugin> [...]"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check that plugin is in $plugins
|
|
||||||
local -a dis_plugins
|
|
||||||
for plugin in "$@"; do
|
|
||||||
if [[ ${plugins[(Ie)$plugin]} -eq 0 ]]; then
|
|
||||||
_omz::log warn "plugin '$plugin' is not enabled."
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
dis_plugins+=("$plugin")
|
|
||||||
done
|
|
||||||
|
|
||||||
# Exit if there are no enabled plugins to disable
|
|
||||||
if [[ ${#dis_plugins} -eq 0 ]]; then
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Remove plugins substitution awk script
|
|
||||||
# A match consumes the whitespace around the plugin, so adjacent plugins
|
|
||||||
# can't match in the same pass: repeat until the line stops changing.
|
|
||||||
local awk_subst_plugins="\
|
|
||||||
do {
|
|
||||||
prev = \$0
|
|
||||||
|
|
||||||
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
|
|
||||||
} while (\$0 != prev)
|
|
||||||
"
|
|
||||||
|
|
||||||
# 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 }
|
|
||||||
"
|
|
||||||
|
|
||||||
local zdot="${ZDOTDIR:-$HOME}"
|
|
||||||
local zshrc="${${:-"${zdot}/.zshrc"}:A}"
|
|
||||||
awk "$awk_script" "$zshrc" > "$zdot/.zshrc.new" \
|
|
||||||
&& command cp -f "$zshrc" "$zdot/.zshrc.bck" \
|
|
||||||
&& command mv -f "$zdot/.zshrc.new" "$zshrc"
|
|
||||||
|
|
||||||
# Exit if the new .zshrc file wasn't created correctly
|
|
||||||
[[ $? -eq 0 ]] || {
|
|
||||||
local ret=$?
|
|
||||||
_omz::log error "error disabling plugins."
|
|
||||||
return $ret
|
|
||||||
}
|
|
||||||
|
|
||||||
# Exit if the new .zshrc file has syntax errors
|
|
||||||
if ! command zsh -n "$zdot/.zshrc"; then
|
|
||||||
_omz::log error "broken syntax in '"${zdot/#$HOME/\~}/.zshrc"'. Rolling back changes..."
|
|
||||||
command mv -f "$zdot/.zshrc.bck" "$zshrc"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Restart the zsh session if there were no errors
|
|
||||||
_omz::log info "plugins disabled: ${(j:, :)dis_plugins}."
|
|
||||||
|
|
||||||
# Only reload zsh if run in an interactive session
|
|
||||||
[[ ! -o interactive ]] || _omz::reload
|
|
||||||
}
|
|
||||||
|
|
||||||
function _omz::plugin::enable {
|
|
||||||
if [[ -z "$1" ]]; then
|
|
||||||
echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <plugin> [...]"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check that plugin is not in $plugins
|
|
||||||
local -a add_plugins
|
|
||||||
for plugin in "$@"; do
|
|
||||||
if [[ ${plugins[(Ie)$plugin]} -ne 0 ]]; then
|
|
||||||
_omz::log warn "plugin '$plugin' is already enabled."
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
add_plugins+=("$plugin")
|
|
||||||
done
|
|
||||||
|
|
||||||
# Exit if there are no plugins to enable
|
|
||||||
if [[ ${#add_plugins} -eq 0 ]]; then
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Enable plugins awk script
|
|
||||||
local awk_script="
|
|
||||||
# if plugins=() is in oneline form (empty or not), substitute ) with new plugins and go to the next line
|
|
||||||
/^[ \t]*plugins=\([^#]*\).*\$/ {
|
|
||||||
sub(/\)/, \" $add_plugins&\")
|
|
||||||
print \$0
|
|
||||||
next
|
|
||||||
}
|
|
||||||
|
|
||||||
# if plugins=() is in multiline form, enable multi flag and indent by default with 2 spaces
|
|
||||||
/^[ \t]*plugins=\(/ {
|
|
||||||
multi=1
|
|
||||||
indent=\" \"
|
|
||||||
print \$0
|
|
||||||
next
|
|
||||||
}
|
|
||||||
|
|
||||||
# if multi flag is enabled and we find a valid closing parenthesis,
|
|
||||||
# add new plugins with proper indent and disable multi flag
|
|
||||||
multi == 1 && /^[^#]*\)/ {
|
|
||||||
multi=0
|
|
||||||
split(\"$add_plugins\",p,\" \")
|
|
||||||
for (i in p) {
|
|
||||||
print indent p[i]
|
|
||||||
}
|
|
||||||
print \$0
|
|
||||||
next
|
|
||||||
}
|
|
||||||
|
|
||||||
# if multi flag is enabled and we didn't find a closing parenthesis,
|
|
||||||
# get the indentation level to match when adding plugins
|
|
||||||
multi == 1 && /^[^#]*/ {
|
|
||||||
indent=\"\"
|
|
||||||
for (i = 1; i <= length(\$0); i++) {
|
|
||||||
char=substr(\$0, i, 1)
|
|
||||||
if (char == \" \" || char == \"\t\") {
|
|
||||||
indent = indent char
|
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{ print \$0 }
|
|
||||||
"
|
|
||||||
|
|
||||||
local zdot="${ZDOTDIR:-$HOME}"
|
|
||||||
local zshrc="${${:-"${zdot}/.zshrc"}:A}"
|
|
||||||
awk "$awk_script" "$zshrc" > "$zdot/.zshrc.new" \
|
|
||||||
&& command cp -f "$zshrc" "$zdot/.zshrc.bck" \
|
|
||||||
&& command mv -f "$zdot/.zshrc.new" "$zshrc"
|
|
||||||
|
|
||||||
# Exit if the new .zshrc file wasn't created correctly
|
|
||||||
[[ $? -eq 0 ]] || {
|
|
||||||
local ret=$?
|
|
||||||
_omz::log error "error enabling plugins."
|
|
||||||
return $ret
|
|
||||||
}
|
|
||||||
|
|
||||||
# Exit if the new .zshrc file has syntax errors
|
|
||||||
if ! command zsh -n "$zdot/.zshrc"; then
|
|
||||||
_omz::log error "broken syntax in '"${zdot/#$HOME/\~}/.zshrc"'. Rolling back changes..."
|
|
||||||
command mv -f "$zdot/.zshrc.bck" "$zshrc"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Restart the zsh session if there were no errors
|
|
||||||
_omz::log info "plugins enabled: ${(j:, :)add_plugins}."
|
|
||||||
|
|
||||||
# Only reload zsh if run in an interactive session
|
|
||||||
[[ ! -o interactive ]] || _omz::reload
|
|
||||||
}
|
|
||||||
|
|
||||||
function _omz::plugin::info {
|
|
||||||
if [[ -z "$1" ]]; then
|
|
||||||
echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <plugin>"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
local readme
|
|
||||||
for readme in "$ZSH_CUSTOM/plugins/$1/README.md" "$ZSH/plugins/$1/README.md"; do
|
|
||||||
if [[ -f "$readme" ]]; then
|
|
||||||
# If being piped, just cat the README
|
|
||||||
if [[ ! -t 1 ]]; then
|
|
||||||
cat "$readme"
|
|
||||||
return $?
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Enrich the README display depending on the tools we have
|
|
||||||
# - glow: https://github.com/charmbracelet/glow
|
|
||||||
# - bat: https://github.com/sharkdp/bat
|
|
||||||
# - less: typical pager command
|
|
||||||
case 1 in
|
|
||||||
${+commands[glow]}) glow -p "$readme" ;;
|
|
||||||
${+commands[bat]}) bat -l md --style plain "$readme" ;;
|
|
||||||
${+commands[less]}) less "$readme" ;;
|
|
||||||
*) cat "$readme" ;;
|
|
||||||
esac
|
|
||||||
return $?
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [[ -d "$ZSH_CUSTOM/plugins/$1" || -d "$ZSH/plugins/$1" ]]; then
|
|
||||||
_omz::log error "the '$1' plugin doesn't have a README file"
|
|
||||||
else
|
|
||||||
_omz::log error "'$1' plugin not found"
|
|
||||||
fi
|
|
||||||
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
function _omz::plugin::list {
|
|
||||||
local -a custom_plugins builtin_plugins
|
|
||||||
|
|
||||||
# If --enabled is provided, only list what's enabled
|
|
||||||
if [[ "$1" == "--enabled" ]]; then
|
|
||||||
local plugin
|
|
||||||
for plugin in "${plugins[@]}"; do
|
|
||||||
if [[ -d "${ZSH_CUSTOM}/plugins/${plugin}" ]]; then
|
|
||||||
custom_plugins+=("${plugin}")
|
|
||||||
elif [[ -d "${ZSH}/plugins/${plugin}" ]]; then
|
|
||||||
builtin_plugins+=("${plugin}")
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
else
|
|
||||||
custom_plugins=("$ZSH_CUSTOM"/plugins/*(-/N:t))
|
|
||||||
builtin_plugins=("$ZSH"/plugins/*(-/N:t))
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If the command is being piped, print all found line by line
|
|
||||||
if [[ ! -t 1 ]]; then
|
|
||||||
print -l ${(q-)custom_plugins} ${(q-)builtin_plugins}
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
if (( ${#custom_plugins} )); then
|
|
||||||
print -P "%U%BCustom plugins%b%u:"
|
|
||||||
print -lac ${(q-)custom_plugins}
|
|
||||||
fi
|
|
||||||
|
|
||||||
if (( ${#builtin_plugins} )); then
|
|
||||||
(( ${#custom_plugins} )) && echo # add a line of separation
|
|
||||||
|
|
||||||
print -P "%U%BBuilt-in plugins%b%u:"
|
|
||||||
print -lac ${(q-)builtin_plugins}
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function _omz::plugin::load {
|
|
||||||
if [[ -z "$1" ]]; then
|
|
||||||
echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <plugin> [...]"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
local plugin base has_completion=0
|
|
||||||
for plugin in "$@"; do
|
|
||||||
if [[ -d "$ZSH_CUSTOM/plugins/$plugin" ]]; then
|
|
||||||
base="$ZSH_CUSTOM/plugins/$plugin"
|
|
||||||
elif [[ -d "$ZSH/plugins/$plugin" ]]; then
|
|
||||||
base="$ZSH/plugins/$plugin"
|
|
||||||
else
|
|
||||||
_omz::log warn "plugin '$plugin' not found"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if its a valid plugin
|
|
||||||
if [[ ! -f "$base/_$plugin" && ! -f "$base/$plugin.plugin.zsh" ]]; then
|
|
||||||
_omz::log warn "'$plugin' is not a valid plugin"
|
|
||||||
continue
|
|
||||||
# It is a valid plugin, add its directory to $fpath unless it is already there
|
|
||||||
elif (( ! ${fpath[(Ie)$base]} )); then
|
|
||||||
fpath=("$base" $fpath)
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if it has completion to reload compinit
|
|
||||||
local -a comp_files
|
|
||||||
comp_files=($base/_*(N))
|
|
||||||
(( has_completion )) || has_completion=$(( $#comp_files > 0 ))
|
|
||||||
|
|
||||||
# Load the plugin
|
|
||||||
if [[ -f "$base/$plugin.plugin.zsh" ]]; then
|
|
||||||
source "$base/$plugin.plugin.zsh"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# If we have completion, we need to reload the completion
|
|
||||||
# We pass -D to avoid generating a new dump file, which would overwrite our
|
|
||||||
# current one for the next session (and we don't want that because we're not
|
|
||||||
# actually enabling the plugins for the next session).
|
|
||||||
# Note that we still have to pass -d "$_comp_dumpfile", so that compinit
|
|
||||||
# doesn't use the default zcompdump location (${ZDOTDIR:-$HOME}/.zcompdump).
|
|
||||||
if (( has_completion )); then
|
|
||||||
compinit -D -d "$_comp_dumpfile"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function _omz::pr {
|
|
||||||
(( $# > 0 && $+functions[$0::$1] )) || {
|
|
||||||
cat >&2 <<EOF
|
|
||||||
Usage: ${(j: :)${(s.::.)0#_}} <command> [options]
|
|
||||||
|
|
||||||
Available commands:
|
|
||||||
|
|
||||||
clean Delete all PR branches (ohmyzsh/pull-*)
|
|
||||||
test <PR_number_or_URL> Fetch PR #NUMBER and rebase against master
|
|
||||||
|
|
||||||
EOF
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
local command="$1"
|
|
||||||
shift
|
|
||||||
|
|
||||||
$0::$command "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
function _omz::pr::clean {
|
|
||||||
(
|
|
||||||
set -e
|
|
||||||
builtin cd -q "$ZSH"
|
|
||||||
|
|
||||||
# Check if there are PR branches
|
|
||||||
local fmt branches
|
|
||||||
fmt="%(color:bold blue)%(align:18,right)%(refname:short)%(end)%(color:reset) %(color:dim bold red)%(objectname:short)%(color:reset) %(color:yellow)%(contents:subject)"
|
|
||||||
branches="$(command git for-each-ref --sort=-committerdate --color --format="$fmt" "refs/heads/ohmyzsh/pull-*")"
|
|
||||||
|
|
||||||
# Exit if there are no PR branches
|
|
||||||
if [[ -z "$branches" ]]; then
|
|
||||||
_omz::log info "there are no Pull Request branches to remove."
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Print found PR branches
|
|
||||||
echo "$branches\n"
|
|
||||||
# Confirm before removing the branches
|
|
||||||
_omz::confirm "do you want remove these Pull Request branches? [Y/n] "
|
|
||||||
# Only proceed if the answer is a valid yes option
|
|
||||||
[[ "$REPLY" != [yY$'\n'] ]] && return
|
|
||||||
|
|
||||||
_omz::log info "removing all Oh My Zsh Pull Request branches..."
|
|
||||||
command git branch --list 'ohmyzsh/pull-*' | while read branch; do
|
|
||||||
command git branch -D "$branch"
|
|
||||||
done
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function _omz::pr::test {
|
|
||||||
# Allow $1 to be a URL to the pull request
|
|
||||||
if [[ "$1" = https://* ]]; then
|
|
||||||
1="${1:t}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check the input
|
|
||||||
if ! [[ -n "$1" && "$1" =~ ^[[:digit:]]+$ ]]; then
|
|
||||||
echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <PR_NUMBER_or_URL>"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Save current git HEAD
|
|
||||||
local branch
|
|
||||||
branch=$(builtin cd -q "$ZSH"; git symbolic-ref --short HEAD) || {
|
|
||||||
_omz::log error "error when getting the current git branch. Aborting..."
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Fetch PR onto ohmyzsh/pull-<PR_NUMBER> branch and rebase against master
|
|
||||||
# If any of these operations fail, undo the changes made
|
|
||||||
(
|
|
||||||
set -e
|
|
||||||
builtin cd -q "$ZSH"
|
|
||||||
|
|
||||||
# Get the ohmyzsh git remote
|
|
||||||
command git remote -v | while read remote url _; do
|
|
||||||
case "$url" in
|
|
||||||
https://github.com/ohmyzsh/ohmyzsh(|.git)) found=1; break ;;
|
|
||||||
git@github.com:ohmyzsh/ohmyzsh(|.git)) found=1; break ;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
(( $found )) || {
|
|
||||||
_omz::log error "could not find the ohmyzsh git remote. Aborting..."
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Check if Pull Request has the "testers needed" label
|
|
||||||
_omz::log info "checking if PR #$1 has the 'testers needed' label..."
|
|
||||||
local pr_json label label_id="MDU6TGFiZWw4NzY1NTkwNA=="
|
|
||||||
pr_json=$(
|
|
||||||
curl -fsSL \
|
|
||||||
-H "Accept: application/vnd.github+json" \
|
|
||||||
-H "X-GitHub-Api-Version: 2022-11-28" \
|
|
||||||
"https://api.github.com/repos/ohmyzsh/ohmyzsh/pulls/$1"
|
|
||||||
)
|
|
||||||
|
|
||||||
if [[ $? -gt 0 || -z "$pr_json" ]]; then
|
|
||||||
_omz::log error "error when trying to fetch PR #$1 from GitHub."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if the label is present with jq or grep
|
|
||||||
if (( $+commands[jq] )); then
|
|
||||||
label="$(command jq ".labels.[] | select(.node_id == \"$label_id\")" <<< "$pr_json")"
|
|
||||||
else
|
|
||||||
label="$(command grep "\"$label_id\"" <<< "$pr_json" 2>/dev/null)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If a maintainer hasn't labeled the PR to test, explain the security risk
|
|
||||||
if [[ -z "$label" ]]; then
|
|
||||||
_omz::log warn "PR #$1 does not have the 'testers needed' label. This means that the PR"
|
|
||||||
_omz::log warn "has not been reviewed by a maintainer and may contain malicious code."
|
|
||||||
|
|
||||||
# Ask for explicit confirmation: user needs to type "yes" to continue
|
|
||||||
_omz::log prompt "Do you want to continue testing it? [yes/N] "
|
|
||||||
builtin read -r
|
|
||||||
if [[ "${REPLY:l}" != yes ]]; then
|
|
||||||
_omz::log error "PR test canceled. Please ask a maintainer to review and label the PR."
|
|
||||||
return 1
|
|
||||||
else
|
|
||||||
_omz::log warn "Continuing to check out and test PR #$1. Be careful!"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Fetch pull request head
|
|
||||||
_omz::log info "fetching PR #$1 to ohmyzsh/pull-$1..."
|
|
||||||
command git fetch -f "$remote" refs/pull/$1/head:ohmyzsh/pull-$1 || {
|
|
||||||
_omz::log error "error when trying to fetch PR #$1."
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Rebase pull request branch against the current master
|
|
||||||
_omz::log info "rebasing PR #$1..."
|
|
||||||
local ret gpgsign
|
|
||||||
{
|
|
||||||
# Back up commit.gpgsign setting: use --local to get the current repository
|
|
||||||
# setting, not the global one. If --local is not a known option, it will
|
|
||||||
# exit with a 129 status code.
|
|
||||||
gpgsign=$(command git config --local commit.gpgsign 2>/dev/null) || ret=$?
|
|
||||||
[[ $ret -ne 129 ]] || gpgsign=$(command git config commit.gpgsign 2>/dev/null)
|
|
||||||
command git config commit.gpgsign false
|
|
||||||
|
|
||||||
command git rebase master ohmyzsh/pull-$1 || {
|
|
||||||
command git rebase --abort &>/dev/null
|
|
||||||
_omz::log warn "could not rebase PR #$1 on top of master."
|
|
||||||
_omz::log warn "you might not see the latest stable changes."
|
|
||||||
_omz::log info "run \`zsh\` to test the changes."
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
} always {
|
|
||||||
case "$gpgsign" in
|
|
||||||
"") command git config --unset commit.gpgsign ;;
|
|
||||||
*) command git config commit.gpgsign "$gpgsign" ;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
_omz::log info "fetch of PR #${1} successful."
|
|
||||||
)
|
|
||||||
|
|
||||||
# If there was an error, abort running zsh to test the PR
|
|
||||||
[[ $? -eq 0 ]] || return 1
|
|
||||||
|
|
||||||
# Run zsh to test the changes
|
|
||||||
_omz::log info "running \`zsh\` to test the changes. Run \`exit\` to go back."
|
|
||||||
command zsh -l
|
|
||||||
|
|
||||||
# After testing, go back to the previous HEAD if the user wants
|
|
||||||
_omz::confirm "do you want to go back to the previous branch? [Y/n] "
|
|
||||||
# Only proceed if the answer is a valid yes option
|
|
||||||
[[ "$REPLY" != [yY$'\n'] ]] && return
|
|
||||||
|
|
||||||
(
|
|
||||||
set -e
|
|
||||||
builtin cd -q "$ZSH"
|
|
||||||
|
|
||||||
command git checkout "$branch" -- || {
|
|
||||||
_omz::log error "could not go back to the previous branch ('$branch')."
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function _omz::shop {
|
|
||||||
local shop_url="https://commitgoods.com/collections/oh-my-zsh"
|
|
||||||
|
|
||||||
_omz::log info "Opening Oh My Zsh shop in your browser..."
|
|
||||||
_omz::log info "$shop_url"
|
|
||||||
|
|
||||||
open_command "$shop_url"
|
|
||||||
}
|
|
||||||
|
|
||||||
function _omz::reload {
|
|
||||||
# Delete current completion cache
|
|
||||||
command rm -f $_comp_dumpfile $ZSH_COMPDUMP
|
|
||||||
|
|
||||||
# Old zsh versions don't have ZSH_ARGZERO
|
|
||||||
local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"
|
|
||||||
# ZSH_ARGZERO is how zsh was invoked, not the path to it, so re-resolve
|
|
||||||
# anything that is not absolute via $PATH at exec time (see #13919)
|
|
||||||
[[ "${zsh#-}" != /* ]] && (( $+commands[zsh] )) && zsh="zsh"
|
|
||||||
# Check whether to run a login shell
|
|
||||||
[[ "$zsh" = -* || -o login ]] && exec -l "${zsh#-}" || exec "$zsh"
|
|
||||||
}
|
|
||||||
|
|
||||||
function _omz::theme {
|
|
||||||
(( $# > 0 && $+functions[$0::$1] )) || {
|
|
||||||
cat >&2 <<EOF
|
|
||||||
Usage: ${(j: :)${(s.::.)0#_}} <command> [options]
|
|
||||||
|
|
||||||
Available commands:
|
|
||||||
|
|
||||||
list List all available Oh My Zsh themes
|
|
||||||
set <theme> Set a theme in your .zshrc file
|
|
||||||
use <theme> Load a theme
|
|
||||||
|
|
||||||
EOF
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
local command="$1"
|
|
||||||
shift
|
|
||||||
|
|
||||||
$0::$command "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
function _omz::theme::list {
|
|
||||||
local -a custom_themes builtin_themes
|
|
||||||
custom_themes=("$ZSH_CUSTOM"/**/*.zsh-theme(-.N:r:gs:"$ZSH_CUSTOM"/themes/:::gs:"$ZSH_CUSTOM"/:::))
|
|
||||||
builtin_themes=("$ZSH"/themes/*.zsh-theme(-.N:t:r))
|
|
||||||
|
|
||||||
# If the command is being piped, print all found line by line
|
|
||||||
if [[ ! -t 1 ]]; then
|
|
||||||
print -l ${(q-)custom_themes} ${(q-)builtin_themes}
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Print theme in use
|
|
||||||
if [[ -n "$ZSH_THEME" ]]; then
|
|
||||||
print -Pn "%U%BCurrent theme%b%u: "
|
|
||||||
[[ $ZSH_THEME = random ]] && echo "$RANDOM_THEME (via random)" || echo "$ZSH_THEME"
|
|
||||||
echo
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Print custom themes if there are any
|
|
||||||
if (( ${#custom_themes} )); then
|
|
||||||
print -P "%U%BCustom themes%b%u:"
|
|
||||||
print -lac ${(q-)custom_themes}
|
|
||||||
echo
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Print built-in themes
|
|
||||||
print -P "%U%BBuilt-in themes%b%u:"
|
|
||||||
print -lac ${(q-)builtin_themes}
|
|
||||||
}
|
|
||||||
|
|
||||||
function _omz::theme::set {
|
|
||||||
if [[ -z "$1" ]]; then
|
|
||||||
echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <theme>"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check that theme exists
|
|
||||||
if [[ ! -f "$ZSH_CUSTOM/$1.zsh-theme" ]] \
|
|
||||||
&& [[ ! -f "$ZSH_CUSTOM/themes/$1.zsh-theme" ]] \
|
|
||||||
&& [[ ! -f "$ZSH/themes/$1.zsh-theme" ]]; then
|
|
||||||
_omz::log error "%B$1%b theme not found"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Enable theme in .zshrc
|
|
||||||
local awk_script='
|
|
||||||
!set && /^[ \t]*ZSH_THEME=[^#]+.*$/ {
|
|
||||||
set=1
|
|
||||||
sub(/^[ \t]*ZSH_THEME=[^#]+.*$/, "ZSH_THEME=\"'$1'\" # set by `omz`")
|
|
||||||
print $0
|
|
||||||
next
|
|
||||||
}
|
|
||||||
|
|
||||||
{ print $0 }
|
|
||||||
|
|
||||||
END {
|
|
||||||
# If no ZSH_THEME= line was found, return an error
|
|
||||||
if (!set) exit 1
|
|
||||||
}
|
|
||||||
'
|
|
||||||
|
|
||||||
local zdot="${ZDOTDIR:-$HOME}"
|
|
||||||
local zshrc="${${:-"${zdot}/.zshrc"}:A}"
|
|
||||||
awk "$awk_script" "$zshrc" > "$zdot/.zshrc.new" \
|
|
||||||
|| {
|
|
||||||
# Prepend ZSH_THEME= line to .zshrc if it doesn't exist
|
|
||||||
cat <<EOF
|
|
||||||
ZSH_THEME="$1" # set by \`omz\`
|
|
||||||
|
|
||||||
EOF
|
|
||||||
cat "$zdot/.zshrc"
|
|
||||||
} > "$zdot/.zshrc.new" \
|
|
||||||
&& command cp -f "$zshrc" "$zdot/.zshrc.bck" \
|
|
||||||
&& command mv -f "$zdot/.zshrc.new" "$zshrc"
|
|
||||||
|
|
||||||
# Exit if the new .zshrc file wasn't created correctly
|
|
||||||
[[ $? -eq 0 ]] || {
|
|
||||||
local ret=$?
|
|
||||||
_omz::log error "error setting theme."
|
|
||||||
return $ret
|
|
||||||
}
|
|
||||||
|
|
||||||
# Exit if the new .zshrc file has syntax errors
|
|
||||||
if ! command zsh -n "$zdot/.zshrc"; then
|
|
||||||
_omz::log error "broken syntax in '"${zdot/#$HOME/\~}/.zshrc"'. Rolling back changes..."
|
|
||||||
command mv -f "$zdot/.zshrc.bck" "$zshrc"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Restart the zsh session if there were no errors
|
|
||||||
_omz::log info "'$1' theme set correctly."
|
|
||||||
|
|
||||||
# Only reload zsh if run in an interactive session
|
|
||||||
[[ ! -o interactive ]] || _omz::reload
|
|
||||||
}
|
|
||||||
|
|
||||||
function _omz::theme::use {
|
|
||||||
if [[ -z "$1" ]]; then
|
|
||||||
echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <theme>"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Respect compatibility with old lookup order
|
|
||||||
if [[ -f "$ZSH_CUSTOM/$1.zsh-theme" ]]; then
|
|
||||||
source "$ZSH_CUSTOM/$1.zsh-theme"
|
|
||||||
elif [[ -f "$ZSH_CUSTOM/themes/$1.zsh-theme" ]]; then
|
|
||||||
source "$ZSH_CUSTOM/themes/$1.zsh-theme"
|
|
||||||
elif [[ -f "$ZSH/themes/$1.zsh-theme" ]]; then
|
|
||||||
source "$ZSH/themes/$1.zsh-theme"
|
|
||||||
else
|
|
||||||
_omz::log error "%B$1%b theme not found"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Update theme settings
|
|
||||||
ZSH_THEME="$1"
|
|
||||||
[[ $1 = random ]] || unset RANDOM_THEME
|
|
||||||
}
|
|
||||||
|
|
||||||
function _omz::update {
|
|
||||||
# Check if git command is available
|
|
||||||
(( $+commands[git] )) || {
|
|
||||||
_omz::log error "git is not installed. Aborting..."
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Check if --unattended was passed
|
|
||||||
[[ "$1" != --unattended ]] || {
|
|
||||||
_omz::log error "the \`\e[2m--unattended\e[0m\` flag is no longer supported, use the \`\e[2mupgrade.sh\e[0m\` script instead."
|
|
||||||
_omz::log error "for more information see https://github.com/ohmyzsh/ohmyzsh/wiki/FAQ#how-do-i-update-oh-my-zsh"
|
|
||||||
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
|
|
||||||
local verbose_mode cooldown_days
|
|
||||||
zstyle -s ':omz:update' verbose verbose_mode || verbose_mode=default
|
|
||||||
zstyle -s ':omz:update' cooldown cooldown_days || cooldown_days=0
|
|
||||||
[[ $cooldown_days == <-> ]] || cooldown_days=0
|
|
||||||
ZSH="$ZSH" command zsh -f "$ZSH/tools/upgrade.sh" -i -v $verbose_mode -c $cooldown_days || return $?
|
|
||||||
|
|
||||||
# Update last updated file
|
|
||||||
zmodload zsh/datetime
|
|
||||||
echo "LAST_EPOCH=$(( EPOCHSECONDS / 60 / 60 / 24 ))" >! "${ZSH_CACHE_DIR}/.zsh-update"
|
|
||||||
# Remove update lock if it exists
|
|
||||||
command rm -rf "$ZSH/log/update.lock"
|
|
||||||
|
|
||||||
# Restart the zsh session if there were changes
|
|
||||||
if [[ "$(builtin cd -q "$ZSH"; git rev-parse HEAD)" != "$last_commit" ]]; then
|
|
||||||
# Old zsh versions don't have ZSH_ARGZERO
|
|
||||||
local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"
|
|
||||||
# ZSH_ARGZERO is how zsh was invoked, not the path to it, so re-resolve
|
|
||||||
# anything that is not absolute via $PATH at exec time (see #13919)
|
|
||||||
[[ "${zsh#-}" != /* ]] && (( $+commands[zsh] )) && zsh="zsh"
|
|
||||||
# Check whether to run a login shell
|
|
||||||
[[ "$zsh" = -* || -o login ]] && exec -l "${zsh#-}" || exec "$zsh"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function _omz::version {
|
|
||||||
(
|
|
||||||
builtin cd -q "$ZSH"
|
|
||||||
|
|
||||||
# Get the version name:
|
|
||||||
# 1) try tag-like version
|
|
||||||
# 2) try branch name
|
|
||||||
# 3) try name-rev (tag~<rev> or branch~<rev>)
|
|
||||||
local version
|
|
||||||
version=$(command git describe --tags HEAD 2>/dev/null) \
|
|
||||||
|| version=$(command git symbolic-ref --quiet --short HEAD 2>/dev/null) \
|
|
||||||
|| version=$(command git name-rev --no-undefined --name-only --exclude="remotes/*" HEAD 2>/dev/null) \
|
|
||||||
|| version="<detached>"
|
|
||||||
|
|
||||||
# Get short hash for the current HEAD
|
|
||||||
local commit=$(command git rev-parse --short HEAD 2>/dev/null)
|
|
||||||
|
|
||||||
# Show version and commit hash
|
|
||||||
printf "%s (%s)\n" "$version" "$commit"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
omz "$@"
|
|
||||||
@@ -1,356 +0,0 @@
|
|||||||
# omz_diagnostic_dump
|
|
||||||
#
|
|
||||||
# Diagnostic and debugging support for oh-my-zsh
|
|
||||||
|
|
||||||
# omz_diagnostic_dump()
|
|
||||||
#
|
|
||||||
# Author: Andrew Janke <andrew@apjanke.net>
|
|
||||||
#
|
|
||||||
# Usage:
|
|
||||||
#
|
|
||||||
# omz_diagnostic_dump [-v] [-V] [file]
|
|
||||||
#
|
|
||||||
# NOTE: This is a work in progress. Its interface and behavior are going to change,
|
|
||||||
# and probably in non-back-compatible ways.
|
|
||||||
#
|
|
||||||
# Outputs a bunch of information about the state and configuration of
|
|
||||||
# oh-my-zsh, zsh, and the user's system. This is intended to provide a
|
|
||||||
# bunch of context for diagnosing your own or a third party's problems, and to
|
|
||||||
# be suitable for posting to public bug reports.
|
|
||||||
#
|
|
||||||
# The output is human-readable and its format may change over time. It is not
|
|
||||||
# suitable for parsing. All the output is in one single file so it can be posted
|
|
||||||
# as a gist or bug comment on GitHub. GitHub doesn't support attaching tarballs
|
|
||||||
# or other files to bugs; otherwise, this would probably have an option to produce
|
|
||||||
# tarballs that contain copies of the config and customization files instead of
|
|
||||||
# catting them all in to one file.
|
|
||||||
#
|
|
||||||
# This is intended to be widely portable, and run anywhere that oh-my-zsh does.
|
|
||||||
# Feel free to report any portability issues as bugs.
|
|
||||||
#
|
|
||||||
# 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
|
|
||||||
# redefinitions.
|
|
||||||
#
|
|
||||||
# OPTIONS
|
|
||||||
#
|
|
||||||
# [file] Specifies the output file. If not given, a file in the current directory
|
|
||||||
# is selected automatically.
|
|
||||||
#
|
|
||||||
# -v Increase the verbosity of the dump output. May be specified multiple times.
|
|
||||||
# Verbosity levels:
|
|
||||||
# 0 - Basic info, shell state, omz configuration, git state
|
|
||||||
# 1 - (default) Adds key binding info and configuration file contents
|
|
||||||
# 2 - Adds zcompdump file contents
|
|
||||||
#
|
|
||||||
# -V Reduce the verbosity of the dump output. May be specified multiple times.
|
|
||||||
#
|
|
||||||
# TODO:
|
|
||||||
# * Multi-file capture
|
|
||||||
# * Add automatic gist uploading
|
|
||||||
# * Consider whether to move default output file location to TMPDIR. More robust
|
|
||||||
# but less user friendly.
|
|
||||||
#
|
|
||||||
|
|
||||||
autoload -Uz is-at-least
|
|
||||||
|
|
||||||
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
|
|
||||||
local timestamp=$(date +%Y%m%d-%H%M%S)
|
|
||||||
local outfile=omz_diagdump_$timestamp.txt
|
|
||||||
builtin zparseopts -A opts -D -- "v+=opt_verbose" "V+=opt_noverbose"
|
|
||||||
local verbose n_verbose=${#opt_verbose} n_noverbose=${#opt_noverbose}
|
|
||||||
(( verbose = 1 + n_verbose - n_noverbose ))
|
|
||||||
|
|
||||||
if [[ ${#*} > 0 ]]; then
|
|
||||||
opt_outfile=$1
|
|
||||||
fi
|
|
||||||
if [[ ${#*} > 1 ]]; then
|
|
||||||
builtin echo "$thisfcn: error: too many arguments" >&2
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
if [[ -n "$opt_outfile" ]]; then
|
|
||||||
outfile="$opt_outfile"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Always write directly to a file so terminal escape sequences are
|
|
||||||
# captured cleanly
|
|
||||||
_omz_diag_dump_one_big_text &> "$outfile"
|
|
||||||
if [[ $? != 0 ]]; then
|
|
||||||
builtin echo "$thisfcn: error while creating diagnostic dump; see $outfile for details"
|
|
||||||
fi
|
|
||||||
|
|
||||||
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 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,"
|
|
||||||
builtin echo "so don't share it publicly if there's sensitive information in them."
|
|
||||||
builtin echo
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function _omz_diag_dump_one_big_text() {
|
|
||||||
local program programs progfile md5
|
|
||||||
|
|
||||||
builtin echo oh-my-zsh diagnostic dump
|
|
||||||
builtin echo
|
|
||||||
builtin echo $outfile
|
|
||||||
builtin echo
|
|
||||||
|
|
||||||
# Basic system and zsh information
|
|
||||||
command date
|
|
||||||
command uname -a
|
|
||||||
builtin echo OSTYPE=$OSTYPE
|
|
||||||
builtin echo ZSH_VERSION=$ZSH_VERSION
|
|
||||||
builtin echo User: $USERNAME
|
|
||||||
builtin echo umask: $(umask)
|
|
||||||
builtin echo
|
|
||||||
_omz_diag_dump_os_specific_version
|
|
||||||
builtin echo
|
|
||||||
|
|
||||||
# Installed programs
|
|
||||||
programs=(sh zsh ksh bash sed cat grep ls find git posh)
|
|
||||||
local progfile="" extra_str="" sha_str=""
|
|
||||||
for program in $programs; do
|
|
||||||
extra_str="" sha_str=""
|
|
||||||
progfile=$(builtin which $program)
|
|
||||||
if [[ $? == 0 ]]; then
|
|
||||||
if [[ -e $progfile ]]; then
|
|
||||||
if builtin whence shasum &>/dev/null; then
|
|
||||||
sha_str=($(command shasum $progfile))
|
|
||||||
sha_str=$sha_str[1]
|
|
||||||
extra_str+=" SHA $sha_str"
|
|
||||||
fi
|
|
||||||
if [[ -h "$progfile" ]]; then
|
|
||||||
extra_str+=" ( -> ${progfile:A} )"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
builtin printf '%-9s %-20s %s\n' "$program is" "$progfile" "$extra_str"
|
|
||||||
else
|
|
||||||
builtin echo "$program: not found"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
builtin echo
|
|
||||||
builtin echo Command Versions:
|
|
||||||
builtin echo "zsh: $(zsh --version)"
|
|
||||||
builtin echo "this zsh session: $ZSH_VERSION"
|
|
||||||
builtin echo "bash: $(bash --version | command grep bash)"
|
|
||||||
builtin echo "git: $(git --version)"
|
|
||||||
builtin echo "grep: $(grep --version)"
|
|
||||||
builtin echo
|
|
||||||
|
|
||||||
# Core command definitions
|
|
||||||
_omz_diag_dump_check_core_commands || return 1
|
|
||||||
builtin echo
|
|
||||||
|
|
||||||
# ZSH Process state
|
|
||||||
builtin echo Process state:
|
|
||||||
builtin echo pwd: $PWD
|
|
||||||
if builtin whence pstree &>/dev/null; then
|
|
||||||
builtin echo Process tree for this shell:
|
|
||||||
pstree -p $$
|
|
||||||
else
|
|
||||||
ps -fT
|
|
||||||
fi
|
|
||||||
builtin set | command grep -a '^\(ZSH\|plugins\|TERM\|LC_\|LANG\|precmd\|chpwd\|preexec\|FPATH\|TTY\|DISPLAY\|PATH\)\|OMZ'
|
|
||||||
builtin echo
|
|
||||||
#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 Locale:
|
|
||||||
command locale
|
|
||||||
builtin echo
|
|
||||||
|
|
||||||
# Zsh installation and configuration
|
|
||||||
builtin echo Zsh configuration:
|
|
||||||
builtin echo setopt: $(builtin setopt)
|
|
||||||
builtin echo
|
|
||||||
builtin echo zstyle:
|
|
||||||
builtin zstyle
|
|
||||||
builtin echo
|
|
||||||
builtin echo 'compaudit output:'
|
|
||||||
compaudit
|
|
||||||
builtin echo
|
|
||||||
builtin echo '$fpath directories:'
|
|
||||||
command ls -lad $fpath
|
|
||||||
builtin echo
|
|
||||||
|
|
||||||
# Oh-my-zsh installation
|
|
||||||
builtin echo oh-my-zsh installation:
|
|
||||||
command ls -ld ~/.z*
|
|
||||||
command ls -ld ~/.oh*
|
|
||||||
builtin echo
|
|
||||||
builtin echo oh-my-zsh git state:
|
|
||||||
(builtin cd $ZSH && builtin echo "HEAD: $(git rev-parse HEAD)" && git remote -v && git status | command grep "[^[:space:]]")
|
|
||||||
if [[ $verbose -ge 1 ]]; then
|
|
||||||
(builtin cd $ZSH && git reflog --date=default | command grep pull)
|
|
||||||
fi
|
|
||||||
builtin echo
|
|
||||||
if [[ -e $ZSH_CUSTOM ]]; then
|
|
||||||
local custom_dir=$ZSH_CUSTOM
|
|
||||||
if [[ -h $custom_dir ]]; then
|
|
||||||
custom_dir=$(builtin cd $custom_dir && pwd -P)
|
|
||||||
fi
|
|
||||||
builtin echo "oh-my-zsh custom dir:"
|
|
||||||
builtin echo " $ZSH_CUSTOM ($custom_dir)"
|
|
||||||
(builtin cd ${custom_dir:h} && command find ${custom_dir:t} -name .git -prune -o -print)
|
|
||||||
builtin echo
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Key binding and terminal info
|
|
||||||
if [[ $verbose -ge 1 ]]; then
|
|
||||||
builtin echo "bindkey:"
|
|
||||||
builtin bindkey
|
|
||||||
builtin echo
|
|
||||||
builtin echo "infocmp:"
|
|
||||||
command infocmp -L
|
|
||||||
builtin echo
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Configuration file info
|
|
||||||
local zdotdir=${ZDOTDIR:-$HOME}
|
|
||||||
builtin echo "Zsh configuration files:"
|
|
||||||
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
|
|
||||||
$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 )
|
|
||||||
command ls -lad $cfgfiles 2>&1
|
|
||||||
builtin echo
|
|
||||||
if [[ $verbose -ge 1 ]]; then
|
|
||||||
for cfgfile in $cfgfiles; do
|
|
||||||
_omz_diag_dump_echo_file_w_header $cfgfile
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
builtin echo
|
|
||||||
builtin echo "Zsh compdump files:"
|
|
||||||
local dumpfile
|
|
||||||
local -U dumpfiles
|
|
||||||
dumpfiles=( $zdotdir/.zcompdump*(N) ${ZSH_COMPDUMP:h}/.zcompdump*(N) )
|
|
||||||
(( $#dumpfiles )) && command ls -lad $dumpfiles
|
|
||||||
if [[ $verbose -ge 2 ]]; then
|
|
||||||
for dumpfile in $dumpfiles; do
|
|
||||||
_omz_diag_dump_echo_file_w_header $dumpfile
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function _omz_diag_dump_check_core_commands() {
|
|
||||||
builtin echo "Core command check:"
|
|
||||||
local redefined name builtins externals reserved_words
|
|
||||||
redefined=()
|
|
||||||
# All the zsh non-module builtin commands
|
|
||||||
# These are taken from the zsh reference manual for 5.0.2
|
|
||||||
# Commands from modules should not be included.
|
|
||||||
# (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 '!' '[[' '{' '}'
|
|
||||||
)
|
|
||||||
builtins=( alias autoload bg bindkey break builtin bye cd chdir command
|
|
||||||
comparguments compcall compctl compdescribe compfiles compgroups compquote comptags
|
|
||||||
comptry compvalues continue dirs disable disown echo echotc echoti emulate
|
|
||||||
enable eval exec exit false fc fg functions getln getopts hash
|
|
||||||
jobs kill let limit log logout noglob popd print printf
|
|
||||||
pushd pushln pwd r read rehash return sched set setopt shift
|
|
||||||
source suspend test times trap true ttyctl type ulimit umask unalias
|
|
||||||
unfunction unhash unlimit unset unsetopt vared wait whence where which zcompile
|
|
||||||
zle zmodload zparseopts zregexparse zstyle )
|
|
||||||
if is-at-least 5.1; then
|
|
||||||
reserved_words+=( declare export integer float local readonly typeset )
|
|
||||||
else
|
|
||||||
builtins+=( declare export integer float local readonly typeset )
|
|
||||||
fi
|
|
||||||
builtins_fatal=( builtin command local )
|
|
||||||
externals=( zsh )
|
|
||||||
for name in $reserved_words; do
|
|
||||||
if [[ $(builtin whence -w $name) != "$name: reserved" ]]; then
|
|
||||||
builtin echo "reserved word '$name' has been redefined"
|
|
||||||
builtin which $name
|
|
||||||
redefined+=$name
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
for name in $builtins; do
|
|
||||||
if [[ $(builtin whence -w $name) != "$name: builtin" ]]; then
|
|
||||||
builtin echo "builtin '$name' has been redefined"
|
|
||||||
builtin which $name
|
|
||||||
redefined+=$name
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
for name in $externals; do
|
|
||||||
if [[ $(builtin whence -w $name) != "$name: command" ]]; then
|
|
||||||
builtin echo "command '$name' has been redefined"
|
|
||||||
builtin which $name
|
|
||||||
redefined+=$name
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [[ -n "$redefined" ]]; then
|
|
||||||
builtin echo "SOME CORE COMMANDS HAVE BEEN REDEFINED: $redefined"
|
|
||||||
else
|
|
||||||
builtin echo "All core commands are defined normally"
|
|
||||||
fi
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function _omz_diag_dump_echo_file_w_header() {
|
|
||||||
local file=$1
|
|
||||||
if [[ ( -f $file || -h $file ) ]]; then
|
|
||||||
builtin echo "========== $file =========="
|
|
||||||
if [[ -h $file ]]; then
|
|
||||||
builtin echo "========== ( => ${file:A} ) =========="
|
|
||||||
fi
|
|
||||||
command cat $file
|
|
||||||
builtin echo "========== end $file =========="
|
|
||||||
builtin echo
|
|
||||||
elif [[ -d $file ]]; then
|
|
||||||
builtin echo "File '$file' is a directory"
|
|
||||||
elif [[ ! -e $file ]]; then
|
|
||||||
builtin echo "File '$file' does not exist"
|
|
||||||
else
|
|
||||||
command ls -lad "$file"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function _omz_diag_dump_os_specific_version() {
|
|
||||||
local osname osver version_file version_files
|
|
||||||
case "$OSTYPE" in
|
|
||||||
darwin*)
|
|
||||||
osname=$(command sw_vers -productName)
|
|
||||||
osver=$(command sw_vers -productVersion)
|
|
||||||
builtin echo "OS Version: $osname $osver build $(sw_vers -buildVersion)"
|
|
||||||
;;
|
|
||||||
cygwin)
|
|
||||||
command systeminfo | command head -n 4 | command tail -n 2
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
if builtin which lsb_release >/dev/null; then
|
|
||||||
builtin echo "OS Release: $(command lsb_release -s -d)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
version_files=( /etc/*-release(N) /etc/*-version(N) /etc/*_version(N) )
|
|
||||||
for version_file in $version_files; do
|
|
||||||
builtin echo "$version_file:"
|
|
||||||
command cat "$version_file"
|
|
||||||
builtin echo
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
omz_diagnostic_dump "$@"
|
|
||||||
+953
-3
@@ -1,3 +1,953 @@
|
|||||||
# Keep this library path available for custom overrides.
|
#!/usr/bin/env zsh
|
||||||
# Force zsh-style autoloading so the first invocation runs once under kshautoload.
|
|
||||||
autoload -Uz omz
|
function omz {
|
||||||
|
setopt localoptions noksharrays
|
||||||
|
[[ $# -gt 0 ]] || {
|
||||||
|
_omz::help
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
local command="$1"
|
||||||
|
shift
|
||||||
|
|
||||||
|
# Subcommand functions start with _ so that they don't
|
||||||
|
# appear as completion entries when looking for `omz`
|
||||||
|
(( ${+functions[_omz::$command]} )) || {
|
||||||
|
_omz::help
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
_omz::$command "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
function _omz {
|
||||||
|
local -a cmds subcmds
|
||||||
|
cmds=(
|
||||||
|
'changelog:Print the changelog'
|
||||||
|
'help:Usage information'
|
||||||
|
'plugin:Manage plugins'
|
||||||
|
'pr:Manage Oh My Zsh Pull Requests'
|
||||||
|
'reload:Reload the current zsh session'
|
||||||
|
'shop:Open the Oh My Zsh shop'
|
||||||
|
'theme:Manage themes'
|
||||||
|
'update:Update Oh My Zsh'
|
||||||
|
'version:Show the version'
|
||||||
|
)
|
||||||
|
|
||||||
|
if (( CURRENT == 2 )); then
|
||||||
|
_describe 'command' cmds
|
||||||
|
elif (( CURRENT == 3 )); then
|
||||||
|
case "$words[2]" in
|
||||||
|
changelog) local -a refs
|
||||||
|
refs=("${(@f)$(builtin cd -q "$ZSH"; command git for-each-ref --format="%(refname:short):%(subject)" refs/heads refs/tags)}")
|
||||||
|
_describe 'command' refs ;;
|
||||||
|
plugin) subcmds=(
|
||||||
|
'disable:Disable plugin(s)'
|
||||||
|
'enable:Enable plugin(s)'
|
||||||
|
'info:Get plugin information'
|
||||||
|
'list:List plugins'
|
||||||
|
'load:Load plugin(s)'
|
||||||
|
)
|
||||||
|
_describe 'command' subcmds ;;
|
||||||
|
pr) subcmds=('clean:Delete all Pull Request branches' 'test:Test a Pull Request')
|
||||||
|
_describe 'command' subcmds ;;
|
||||||
|
theme) subcmds=('list:List themes' 'set:Set a theme in your .zshrc file' 'use:Load a theme')
|
||||||
|
_describe 'command' subcmds ;;
|
||||||
|
esac
|
||||||
|
elif (( CURRENT == 4 )); then
|
||||||
|
case "${words[2]}::${words[3]}" in
|
||||||
|
plugin::(disable|enable|load))
|
||||||
|
local -aU valid_plugins
|
||||||
|
|
||||||
|
if [[ "${words[3]}" = disable ]]; then
|
||||||
|
# if command is "disable", only offer already enabled plugins
|
||||||
|
valid_plugins=($plugins)
|
||||||
|
else
|
||||||
|
valid_plugins=("$ZSH"/plugins/*/{_*,*.plugin.zsh}(-.N:h:t) "$ZSH_CUSTOM"/plugins/*/{_*,*.plugin.zsh}(-.N:h:t))
|
||||||
|
# if command is "enable", remove already enabled plugins
|
||||||
|
[[ "${words[3]}" = enable ]] && valid_plugins=(${valid_plugins:|plugins})
|
||||||
|
fi
|
||||||
|
|
||||||
|
_describe 'plugin' valid_plugins ;;
|
||||||
|
plugin::info)
|
||||||
|
local -aU plugins
|
||||||
|
plugins=("$ZSH"/plugins/*/{_*,*.plugin.zsh}(-.N:h:t) "$ZSH_CUSTOM"/plugins/*/{_*,*.plugin.zsh}(-.N:h:t))
|
||||||
|
_describe 'plugin' plugins ;;
|
||||||
|
plugin::list)
|
||||||
|
local -a opts
|
||||||
|
opts=('--enabled:List enabled plugins only')
|
||||||
|
_describe -o 'options' opts ;;
|
||||||
|
theme::(set|use))
|
||||||
|
local -aU themes
|
||||||
|
themes=("$ZSH"/themes/*.zsh-theme(-.N:t:r) "$ZSH_CUSTOM"/**/*.zsh-theme(-.N:r:gs:"$ZSH_CUSTOM"/themes/:::gs:"$ZSH_CUSTOM"/:::))
|
||||||
|
_describe 'theme' themes ;;
|
||||||
|
esac
|
||||||
|
elif (( CURRENT > 4 )); then
|
||||||
|
case "${words[2]}::${words[3]}" in
|
||||||
|
plugin::(enable|disable|load))
|
||||||
|
local -aU valid_plugins
|
||||||
|
|
||||||
|
if [[ "${words[3]}" = disable ]]; then
|
||||||
|
# if command is "disable", only offer already enabled plugins
|
||||||
|
valid_plugins=($plugins)
|
||||||
|
else
|
||||||
|
valid_plugins=("$ZSH"/plugins/*/{_*,*.plugin.zsh}(-.N:h:t) "$ZSH_CUSTOM"/plugins/*/{_*,*.plugin.zsh}(-.N:h:t))
|
||||||
|
# if command is "enable", remove already enabled plugins
|
||||||
|
[[ "${words[3]}" = enable ]] && valid_plugins=(${valid_plugins:|plugins})
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove plugins already passed as arguments
|
||||||
|
# NOTE: $(( CURRENT - 1 )) is the last plugin argument completely passed, i.e. that which
|
||||||
|
# has a space after them. This is to avoid removing plugins partially passed, which makes
|
||||||
|
# the completion not add a space after the completed plugin.
|
||||||
|
local -a args
|
||||||
|
args=(${words[4,$(( CURRENT - 1))]})
|
||||||
|
valid_plugins=(${valid_plugins:|args})
|
||||||
|
|
||||||
|
_describe 'plugin' valid_plugins ;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# If run from a script, do not set the completion function
|
||||||
|
if (( ${+functions[compdef]} )); then
|
||||||
|
compdef _omz omz
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Utility functions
|
||||||
|
|
||||||
|
function _omz::confirm {
|
||||||
|
# If question supplied, ask it before reading the answer
|
||||||
|
# NOTE: uses the logname of the caller function
|
||||||
|
if [[ -n "$1" ]]; then
|
||||||
|
_omz::log prompt "$1" "${${functrace[1]#_}%:*}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Read one character
|
||||||
|
read -r -k 1
|
||||||
|
|
||||||
|
# If no newline entered, add a newline
|
||||||
|
if [[ "$REPLY" != $'\n' ]]; then
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function _omz::log {
|
||||||
|
# if promptsubst is set, a message with `` or $()
|
||||||
|
# will be run even if quoted due to `print -P`
|
||||||
|
setopt localoptions nopromptsubst
|
||||||
|
|
||||||
|
# $1 = info|warn|error|debug
|
||||||
|
# $2 = text
|
||||||
|
# $3 = (optional) name of the logger
|
||||||
|
|
||||||
|
local logtype=$1
|
||||||
|
local logname=${3:-${${functrace[1]#_}%:*}}
|
||||||
|
|
||||||
|
# Don't print anything if debug is not active
|
||||||
|
if [[ $logtype = debug && -z $_OMZ_DEBUG ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Choose coloring based on log type
|
||||||
|
case "$logtype" in
|
||||||
|
prompt) print -Pn "%S%F{blue}$logname%f%s: $2" ;;
|
||||||
|
debug) print -P "%F{white}$logname%f: $2" ;;
|
||||||
|
info) print -P "%F{green}$logname%f: $2" ;;
|
||||||
|
warn) print -P "%S%F{yellow}$logname%f%s: $2" ;;
|
||||||
|
error) print -P "%S%F{red}$logname%f%s: $2" ;;
|
||||||
|
esac >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
## User-facing commands
|
||||||
|
|
||||||
|
function _omz::help {
|
||||||
|
cat >&2 <<EOF
|
||||||
|
Usage: omz <command> [options]
|
||||||
|
|
||||||
|
Available commands:
|
||||||
|
|
||||||
|
help Print this help message
|
||||||
|
changelog Print the changelog
|
||||||
|
plugin <command> Manage plugins
|
||||||
|
pr <command> Manage Oh My Zsh Pull Requests
|
||||||
|
reload Reload the current zsh session
|
||||||
|
shop Open the Oh My Zsh shop
|
||||||
|
theme <command> Manage themes
|
||||||
|
update Update Oh My Zsh
|
||||||
|
version Show the version
|
||||||
|
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
function _omz::changelog {
|
||||||
|
local version=${1:-HEAD} format=${3:-"--text"}
|
||||||
|
|
||||||
|
if (
|
||||||
|
builtin cd -q "$ZSH"
|
||||||
|
! command git show-ref --verify refs/heads/$version && \
|
||||||
|
! command git show-ref --verify refs/tags/$version && \
|
||||||
|
! command git rev-parse --verify "${version}^{commit}"
|
||||||
|
) &>/dev/null; then
|
||||||
|
cat >&2 <<EOF
|
||||||
|
Usage: ${(j: :)${(s.::.)0#_}} [version]
|
||||||
|
|
||||||
|
NOTE: <version> must be a valid branch, tag or commit.
|
||||||
|
EOF
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
ZSH="$ZSH" command zsh -f "$ZSH/tools/changelog.sh" "$version" "${2:-}" "$format"
|
||||||
|
}
|
||||||
|
|
||||||
|
function _omz::plugin {
|
||||||
|
(( $# > 0 && $+functions[$0::$1] )) || {
|
||||||
|
cat >&2 <<EOF
|
||||||
|
Usage: ${(j: :)${(s.::.)0#_}} <command> [options]
|
||||||
|
|
||||||
|
Available commands:
|
||||||
|
|
||||||
|
disable <plugin> Disable plugin(s)
|
||||||
|
enable <plugin> Enable plugin(s)
|
||||||
|
info <plugin> Get information of a plugin
|
||||||
|
list [--enabled] List Oh My Zsh plugins
|
||||||
|
load <plugin> Load plugin(s)
|
||||||
|
|
||||||
|
EOF
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
local command="$1"
|
||||||
|
shift
|
||||||
|
|
||||||
|
$0::$command "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
function _omz::plugin::disable {
|
||||||
|
if [[ -z "$1" ]]; then
|
||||||
|
echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <plugin> [...]"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check that plugin is in $plugins
|
||||||
|
local -a dis_plugins
|
||||||
|
for plugin in "$@"; do
|
||||||
|
if [[ ${plugins[(Ie)$plugin]} -eq 0 ]]; then
|
||||||
|
_omz::log warn "plugin '$plugin' is not enabled."
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
dis_plugins+=("$plugin")
|
||||||
|
done
|
||||||
|
|
||||||
|
# Exit if there are no enabled plugins to disable
|
||||||
|
if [[ ${#dis_plugins} -eq 0 ]]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove plugins substitution awk script
|
||||||
|
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 }
|
||||||
|
"
|
||||||
|
|
||||||
|
local zdot="${ZDOTDIR:-$HOME}"
|
||||||
|
local zshrc="${${:-"${zdot}/.zshrc"}:A}"
|
||||||
|
awk "$awk_script" "$zshrc" > "$zdot/.zshrc.new" \
|
||||||
|
&& command cp -f "$zshrc" "$zdot/.zshrc.bck" \
|
||||||
|
&& command mv -f "$zdot/.zshrc.new" "$zshrc"
|
||||||
|
|
||||||
|
# Exit if the new .zshrc file wasn't created correctly
|
||||||
|
[[ $? -eq 0 ]] || {
|
||||||
|
local ret=$?
|
||||||
|
_omz::log error "error disabling plugins."
|
||||||
|
return $ret
|
||||||
|
}
|
||||||
|
|
||||||
|
# Exit if the new .zshrc file has syntax errors
|
||||||
|
if ! command zsh -n "$zdot/.zshrc"; then
|
||||||
|
_omz::log error "broken syntax in '"${zdot/#$HOME/\~}/.zshrc"'. Rolling back changes..."
|
||||||
|
command mv -f "$zdot/.zshrc.bck" "$zshrc"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Restart the zsh session if there were no errors
|
||||||
|
_omz::log info "plugins disabled: ${(j:, :)dis_plugins}."
|
||||||
|
|
||||||
|
# Only reload zsh if run in an interactive session
|
||||||
|
[[ ! -o interactive ]] || _omz::reload
|
||||||
|
}
|
||||||
|
|
||||||
|
function _omz::plugin::enable {
|
||||||
|
if [[ -z "$1" ]]; then
|
||||||
|
echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <plugin> [...]"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check that plugin is not in $plugins
|
||||||
|
local -a add_plugins
|
||||||
|
for plugin in "$@"; do
|
||||||
|
if [[ ${plugins[(Ie)$plugin]} -ne 0 ]]; then
|
||||||
|
_omz::log warn "plugin '$plugin' is already enabled."
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
add_plugins+=("$plugin")
|
||||||
|
done
|
||||||
|
|
||||||
|
# Exit if there are no plugins to enable
|
||||||
|
if [[ ${#add_plugins} -eq 0 ]]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Enable plugins awk script
|
||||||
|
local awk_script="
|
||||||
|
# if plugins=() is in oneline form, substitute ) with new plugins and go to the next line
|
||||||
|
/^[ \t]*plugins=\([^#]+\).*\$/ {
|
||||||
|
sub(/\)/, \" $add_plugins&\")
|
||||||
|
print \$0
|
||||||
|
next
|
||||||
|
}
|
||||||
|
|
||||||
|
# if plugins=() is in multiline form, enable multi flag and indent by default with 2 spaces
|
||||||
|
/^[ \t]*plugins=\(/ {
|
||||||
|
multi=1
|
||||||
|
indent=\" \"
|
||||||
|
print \$0
|
||||||
|
next
|
||||||
|
}
|
||||||
|
|
||||||
|
# if multi flag is enabled and we find a valid closing parenthesis,
|
||||||
|
# add new plugins with proper indent and disable multi flag
|
||||||
|
multi == 1 && /^[^#]*\)/ {
|
||||||
|
multi=0
|
||||||
|
split(\"$add_plugins\",p,\" \")
|
||||||
|
for (i in p) {
|
||||||
|
print indent p[i]
|
||||||
|
}
|
||||||
|
print \$0
|
||||||
|
next
|
||||||
|
}
|
||||||
|
|
||||||
|
# if multi flag is enabled and we didn't find a closing parenthesis,
|
||||||
|
# get the indentation level to match when adding plugins
|
||||||
|
multi == 1 && /^[^#]*/ {
|
||||||
|
indent=\"\"
|
||||||
|
for (i = 1; i <= length(\$0); i++) {
|
||||||
|
char=substr(\$0, i, 1)
|
||||||
|
if (char == \" \" || char == \"\t\") {
|
||||||
|
indent = indent char
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{ print \$0 }
|
||||||
|
"
|
||||||
|
|
||||||
|
local zdot="${ZDOTDIR:-$HOME}"
|
||||||
|
local zshrc="${${:-"${zdot}/.zshrc"}:A}"
|
||||||
|
awk "$awk_script" "$zshrc" > "$zdot/.zshrc.new" \
|
||||||
|
&& command cp -f "$zshrc" "$zdot/.zshrc.bck" \
|
||||||
|
&& command mv -f "$zdot/.zshrc.new" "$zshrc"
|
||||||
|
|
||||||
|
# Exit if the new .zshrc file wasn't created correctly
|
||||||
|
[[ $? -eq 0 ]] || {
|
||||||
|
local ret=$?
|
||||||
|
_omz::log error "error enabling plugins."
|
||||||
|
return $ret
|
||||||
|
}
|
||||||
|
|
||||||
|
# Exit if the new .zshrc file has syntax errors
|
||||||
|
if ! command zsh -n "$zdot/.zshrc"; then
|
||||||
|
_omz::log error "broken syntax in '"${zdot/#$HOME/\~}/.zshrc"'. Rolling back changes..."
|
||||||
|
command mv -f "$zdot/.zshrc.bck" "$zshrc"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Restart the zsh session if there were no errors
|
||||||
|
_omz::log info "plugins enabled: ${(j:, :)add_plugins}."
|
||||||
|
|
||||||
|
# Only reload zsh if run in an interactive session
|
||||||
|
[[ ! -o interactive ]] || _omz::reload
|
||||||
|
}
|
||||||
|
|
||||||
|
function _omz::plugin::info {
|
||||||
|
if [[ -z "$1" ]]; then
|
||||||
|
echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <plugin>"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local readme
|
||||||
|
for readme in "$ZSH_CUSTOM/plugins/$1/README.md" "$ZSH/plugins/$1/README.md"; do
|
||||||
|
if [[ -f "$readme" ]]; then
|
||||||
|
# If being piped, just cat the README
|
||||||
|
if [[ ! -t 1 ]]; then
|
||||||
|
cat "$readme"
|
||||||
|
return $?
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Enrich the README display depending on the tools we have
|
||||||
|
# - glow: https://github.com/charmbracelet/glow
|
||||||
|
# - bat: https://github.com/sharkdp/bat
|
||||||
|
# - less: typical pager command
|
||||||
|
case 1 in
|
||||||
|
${+commands[glow]}) glow -p "$readme" ;;
|
||||||
|
${+commands[bat]}) bat -l md --style plain "$readme" ;;
|
||||||
|
${+commands[less]}) less "$readme" ;;
|
||||||
|
*) cat "$readme" ;;
|
||||||
|
esac
|
||||||
|
return $?
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ -d "$ZSH_CUSTOM/plugins/$1" || -d "$ZSH/plugins/$1" ]]; then
|
||||||
|
_omz::log error "the '$1' plugin doesn't have a README file"
|
||||||
|
else
|
||||||
|
_omz::log error "'$1' plugin not found"
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function _omz::plugin::list {
|
||||||
|
local -a custom_plugins builtin_plugins
|
||||||
|
|
||||||
|
# If --enabled is provided, only list what's enabled
|
||||||
|
if [[ "$1" == "--enabled" ]]; then
|
||||||
|
local plugin
|
||||||
|
for plugin in "${plugins[@]}"; do
|
||||||
|
if [[ -d "${ZSH_CUSTOM}/plugins/${plugin}" ]]; then
|
||||||
|
custom_plugins+=("${plugin}")
|
||||||
|
elif [[ -d "${ZSH}/plugins/${plugin}" ]]; then
|
||||||
|
builtin_plugins+=("${plugin}")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
else
|
||||||
|
custom_plugins=("$ZSH_CUSTOM"/plugins/*(-/N:t))
|
||||||
|
builtin_plugins=("$ZSH"/plugins/*(-/N:t))
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If the command is being piped, print all found line by line
|
||||||
|
if [[ ! -t 1 ]]; then
|
||||||
|
print -l ${(q-)custom_plugins} ${(q-)builtin_plugins}
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if (( ${#custom_plugins} )); then
|
||||||
|
print -P "%U%BCustom plugins%b%u:"
|
||||||
|
print -lac ${(q-)custom_plugins}
|
||||||
|
fi
|
||||||
|
|
||||||
|
if (( ${#builtin_plugins} )); then
|
||||||
|
(( ${#custom_plugins} )) && echo # add a line of separation
|
||||||
|
|
||||||
|
print -P "%U%BBuilt-in plugins%b%u:"
|
||||||
|
print -lac ${(q-)builtin_plugins}
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function _omz::plugin::load {
|
||||||
|
if [[ -z "$1" ]]; then
|
||||||
|
echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <plugin> [...]"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local plugin base has_completion=0
|
||||||
|
for plugin in "$@"; do
|
||||||
|
if [[ -d "$ZSH_CUSTOM/plugins/$plugin" ]]; then
|
||||||
|
base="$ZSH_CUSTOM/plugins/$plugin"
|
||||||
|
elif [[ -d "$ZSH/plugins/$plugin" ]]; then
|
||||||
|
base="$ZSH/plugins/$plugin"
|
||||||
|
else
|
||||||
|
_omz::log warn "plugin '$plugin' not found"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if its a valid plugin
|
||||||
|
if [[ ! -f "$base/_$plugin" && ! -f "$base/$plugin.plugin.zsh" ]]; then
|
||||||
|
_omz::log warn "'$plugin' is not a valid plugin"
|
||||||
|
continue
|
||||||
|
# It is a valid plugin, add its directory to $fpath unless it is already there
|
||||||
|
elif (( ! ${fpath[(Ie)$base]} )); then
|
||||||
|
fpath=("$base" $fpath)
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if it has completion to reload compinit
|
||||||
|
local -a comp_files
|
||||||
|
comp_files=($base/_*(N))
|
||||||
|
(( has_completion )) || has_completion=$(( $#comp_files > 0 ))
|
||||||
|
|
||||||
|
# Load the plugin
|
||||||
|
if [[ -f "$base/$plugin.plugin.zsh" ]]; then
|
||||||
|
source "$base/$plugin.plugin.zsh"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# If we have completion, we need to reload the completion
|
||||||
|
# We pass -D to avoid generating a new dump file, which would overwrite our
|
||||||
|
# current one for the next session (and we don't want that because we're not
|
||||||
|
# actually enabling the plugins for the next session).
|
||||||
|
# Note that we still have to pass -d "$_comp_dumpfile", so that compinit
|
||||||
|
# doesn't use the default zcompdump location (${ZDOTDIR:-$HOME}/.zcompdump).
|
||||||
|
if (( has_completion )); then
|
||||||
|
compinit -D -d "$_comp_dumpfile"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function _omz::pr {
|
||||||
|
(( $# > 0 && $+functions[$0::$1] )) || {
|
||||||
|
cat >&2 <<EOF
|
||||||
|
Usage: ${(j: :)${(s.::.)0#_}} <command> [options]
|
||||||
|
|
||||||
|
Available commands:
|
||||||
|
|
||||||
|
clean Delete all PR branches (ohmyzsh/pull-*)
|
||||||
|
test <PR_number_or_URL> Fetch PR #NUMBER and rebase against master
|
||||||
|
|
||||||
|
EOF
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
local command="$1"
|
||||||
|
shift
|
||||||
|
|
||||||
|
$0::$command "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
function _omz::pr::clean {
|
||||||
|
(
|
||||||
|
set -e
|
||||||
|
builtin cd -q "$ZSH"
|
||||||
|
|
||||||
|
# Check if there are PR branches
|
||||||
|
local fmt branches
|
||||||
|
fmt="%(color:bold blue)%(align:18,right)%(refname:short)%(end)%(color:reset) %(color:dim bold red)%(objectname:short)%(color:reset) %(color:yellow)%(contents:subject)"
|
||||||
|
branches="$(command git for-each-ref --sort=-committerdate --color --format="$fmt" "refs/heads/ohmyzsh/pull-*")"
|
||||||
|
|
||||||
|
# Exit if there are no PR branches
|
||||||
|
if [[ -z "$branches" ]]; then
|
||||||
|
_omz::log info "there are no Pull Request branches to remove."
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Print found PR branches
|
||||||
|
echo "$branches\n"
|
||||||
|
# Confirm before removing the branches
|
||||||
|
_omz::confirm "do you want remove these Pull Request branches? [Y/n] "
|
||||||
|
# Only proceed if the answer is a valid yes option
|
||||||
|
[[ "$REPLY" != [yY$'\n'] ]] && return
|
||||||
|
|
||||||
|
_omz::log info "removing all Oh My Zsh Pull Request branches..."
|
||||||
|
command git branch --list 'ohmyzsh/pull-*' | while read branch; do
|
||||||
|
command git branch -D "$branch"
|
||||||
|
done
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function _omz::pr::test {
|
||||||
|
# Allow $1 to be a URL to the pull request
|
||||||
|
if [[ "$1" = https://* ]]; then
|
||||||
|
1="${1:t}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check the input
|
||||||
|
if ! [[ -n "$1" && "$1" =~ ^[[:digit:]]+$ ]]; then
|
||||||
|
echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <PR_NUMBER_or_URL>"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Save current git HEAD
|
||||||
|
local branch
|
||||||
|
branch=$(builtin cd -q "$ZSH"; git symbolic-ref --short HEAD) || {
|
||||||
|
_omz::log error "error when getting the current git branch. Aborting..."
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Fetch PR onto ohmyzsh/pull-<PR_NUMBER> branch and rebase against master
|
||||||
|
# If any of these operations fail, undo the changes made
|
||||||
|
(
|
||||||
|
set -e
|
||||||
|
builtin cd -q "$ZSH"
|
||||||
|
|
||||||
|
# Get the ohmyzsh git remote
|
||||||
|
command git remote -v | while read remote url _; do
|
||||||
|
case "$url" in
|
||||||
|
https://github.com/ohmyzsh/ohmyzsh(|.git)) found=1; break ;;
|
||||||
|
git@github.com:ohmyzsh/ohmyzsh(|.git)) found=1; break ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
(( $found )) || {
|
||||||
|
_omz::log error "could not find the ohmyzsh git remote. Aborting..."
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check if Pull Request has the "testers needed" label
|
||||||
|
_omz::log info "checking if PR #$1 has the 'testers needed' label..."
|
||||||
|
local pr_json label label_id="MDU6TGFiZWw4NzY1NTkwNA=="
|
||||||
|
pr_json=$(
|
||||||
|
curl -fsSL \
|
||||||
|
-H "Accept: application/vnd.github+json" \
|
||||||
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
||||||
|
"https://api.github.com/repos/ohmyzsh/ohmyzsh/pulls/$1"
|
||||||
|
)
|
||||||
|
|
||||||
|
if [[ $? -gt 0 || -z "$pr_json" ]]; then
|
||||||
|
_omz::log error "error when trying to fetch PR #$1 from GitHub."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if the label is present with jq or grep
|
||||||
|
if (( $+commands[jq] )); then
|
||||||
|
label="$(command jq ".labels.[] | select(.node_id == \"$label_id\")" <<< "$pr_json")"
|
||||||
|
else
|
||||||
|
label="$(command grep "\"$label_id\"" <<< "$pr_json" 2>/dev/null)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If a maintainer hasn't labeled the PR to test, explain the security risk
|
||||||
|
if [[ -z "$label" ]]; then
|
||||||
|
_omz::log warn "PR #$1 does not have the 'testers needed' label. This means that the PR"
|
||||||
|
_omz::log warn "has not been reviewed by a maintainer and may contain malicious code."
|
||||||
|
|
||||||
|
# Ask for explicit confirmation: user needs to type "yes" to continue
|
||||||
|
_omz::log prompt "Do you want to continue testing it? [yes/N] "
|
||||||
|
builtin read -r
|
||||||
|
if [[ "${REPLY:l}" != yes ]]; then
|
||||||
|
_omz::log error "PR test canceled. Please ask a maintainer to review and label the PR."
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
_omz::log warn "Continuing to check out and test PR #$1. Be careful!"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Fetch pull request head
|
||||||
|
_omz::log info "fetching PR #$1 to ohmyzsh/pull-$1..."
|
||||||
|
command git fetch -f "$remote" refs/pull/$1/head:ohmyzsh/pull-$1 || {
|
||||||
|
_omz::log error "error when trying to fetch PR #$1."
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Rebase pull request branch against the current master
|
||||||
|
_omz::log info "rebasing PR #$1..."
|
||||||
|
local ret gpgsign
|
||||||
|
{
|
||||||
|
# Back up commit.gpgsign setting: use --local to get the current repository
|
||||||
|
# setting, not the global one. If --local is not a known option, it will
|
||||||
|
# exit with a 129 status code.
|
||||||
|
gpgsign=$(command git config --local commit.gpgsign 2>/dev/null) || ret=$?
|
||||||
|
[[ $ret -ne 129 ]] || gpgsign=$(command git config commit.gpgsign 2>/dev/null)
|
||||||
|
command git config commit.gpgsign false
|
||||||
|
|
||||||
|
command git rebase master ohmyzsh/pull-$1 || {
|
||||||
|
command git rebase --abort &>/dev/null
|
||||||
|
_omz::log warn "could not rebase PR #$1 on top of master."
|
||||||
|
_omz::log warn "you might not see the latest stable changes."
|
||||||
|
_omz::log info "run \`zsh\` to test the changes."
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
} always {
|
||||||
|
case "$gpgsign" in
|
||||||
|
"") command git config --unset commit.gpgsign ;;
|
||||||
|
*) command git config commit.gpgsign "$gpgsign" ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
_omz::log info "fetch of PR #${1} successful."
|
||||||
|
)
|
||||||
|
|
||||||
|
# If there was an error, abort running zsh to test the PR
|
||||||
|
[[ $? -eq 0 ]] || return 1
|
||||||
|
|
||||||
|
# Run zsh to test the changes
|
||||||
|
_omz::log info "running \`zsh\` to test the changes. Run \`exit\` to go back."
|
||||||
|
command zsh -l
|
||||||
|
|
||||||
|
# After testing, go back to the previous HEAD if the user wants
|
||||||
|
_omz::confirm "do you want to go back to the previous branch? [Y/n] "
|
||||||
|
# Only proceed if the answer is a valid yes option
|
||||||
|
[[ "$REPLY" != [yY$'\n'] ]] && return
|
||||||
|
|
||||||
|
(
|
||||||
|
set -e
|
||||||
|
builtin cd -q "$ZSH"
|
||||||
|
|
||||||
|
command git checkout "$branch" -- || {
|
||||||
|
_omz::log error "could not go back to the previous branch ('$branch')."
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function _omz::shop {
|
||||||
|
local shop_url="https://commitgoods.com/collections/oh-my-zsh"
|
||||||
|
|
||||||
|
_omz::log info "Opening Oh My Zsh shop in your browser..."
|
||||||
|
_omz::log info "$shop_url"
|
||||||
|
|
||||||
|
open_command "$shop_url"
|
||||||
|
}
|
||||||
|
|
||||||
|
function _omz::reload {
|
||||||
|
# Delete current completion cache
|
||||||
|
command rm -f $_comp_dumpfile $ZSH_COMPDUMP
|
||||||
|
|
||||||
|
# Old zsh versions don't have ZSH_ARGZERO
|
||||||
|
local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"
|
||||||
|
# ZSH_ARGZERO is how zsh was invoked, not the path to it, so re-resolve
|
||||||
|
# anything that is not absolute via $PATH at exec time (see #13919)
|
||||||
|
[[ "${zsh#-}" != /* ]] && (( $+commands[zsh] )) && zsh="zsh"
|
||||||
|
# Check whether to run a login shell
|
||||||
|
[[ "$zsh" = -* || -o login ]] && exec -l "${zsh#-}" || exec "$zsh"
|
||||||
|
}
|
||||||
|
|
||||||
|
function _omz::theme {
|
||||||
|
(( $# > 0 && $+functions[$0::$1] )) || {
|
||||||
|
cat >&2 <<EOF
|
||||||
|
Usage: ${(j: :)${(s.::.)0#_}} <command> [options]
|
||||||
|
|
||||||
|
Available commands:
|
||||||
|
|
||||||
|
list List all available Oh My Zsh themes
|
||||||
|
set <theme> Set a theme in your .zshrc file
|
||||||
|
use <theme> Load a theme
|
||||||
|
|
||||||
|
EOF
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
local command="$1"
|
||||||
|
shift
|
||||||
|
|
||||||
|
$0::$command "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
function _omz::theme::list {
|
||||||
|
local -a custom_themes builtin_themes
|
||||||
|
custom_themes=("$ZSH_CUSTOM"/**/*.zsh-theme(-.N:r:gs:"$ZSH_CUSTOM"/themes/:::gs:"$ZSH_CUSTOM"/:::))
|
||||||
|
builtin_themes=("$ZSH"/themes/*.zsh-theme(-.N:t:r))
|
||||||
|
|
||||||
|
# If the command is being piped, print all found line by line
|
||||||
|
if [[ ! -t 1 ]]; then
|
||||||
|
print -l ${(q-)custom_themes} ${(q-)builtin_themes}
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Print theme in use
|
||||||
|
if [[ -n "$ZSH_THEME" ]]; then
|
||||||
|
print -Pn "%U%BCurrent theme%b%u: "
|
||||||
|
[[ $ZSH_THEME = random ]] && echo "$RANDOM_THEME (via random)" || echo "$ZSH_THEME"
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Print custom themes if there are any
|
||||||
|
if (( ${#custom_themes} )); then
|
||||||
|
print -P "%U%BCustom themes%b%u:"
|
||||||
|
print -lac ${(q-)custom_themes}
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Print built-in themes
|
||||||
|
print -P "%U%BBuilt-in themes%b%u:"
|
||||||
|
print -lac ${(q-)builtin_themes}
|
||||||
|
}
|
||||||
|
|
||||||
|
function _omz::theme::set {
|
||||||
|
if [[ -z "$1" ]]; then
|
||||||
|
echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <theme>"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check that theme exists
|
||||||
|
if [[ ! -f "$ZSH_CUSTOM/$1.zsh-theme" ]] \
|
||||||
|
&& [[ ! -f "$ZSH_CUSTOM/themes/$1.zsh-theme" ]] \
|
||||||
|
&& [[ ! -f "$ZSH/themes/$1.zsh-theme" ]]; then
|
||||||
|
_omz::log error "%B$1%b theme not found"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Enable theme in .zshrc
|
||||||
|
local awk_script='
|
||||||
|
!set && /^[ \t]*ZSH_THEME=[^#]+.*$/ {
|
||||||
|
set=1
|
||||||
|
sub(/^[ \t]*ZSH_THEME=[^#]+.*$/, "ZSH_THEME=\"'$1'\" # set by `omz`")
|
||||||
|
print $0
|
||||||
|
next
|
||||||
|
}
|
||||||
|
|
||||||
|
{ print $0 }
|
||||||
|
|
||||||
|
END {
|
||||||
|
# If no ZSH_THEME= line was found, return an error
|
||||||
|
if (!set) exit 1
|
||||||
|
}
|
||||||
|
'
|
||||||
|
|
||||||
|
local zdot="${ZDOTDIR:-$HOME}"
|
||||||
|
local zshrc="${${:-"${zdot}/.zshrc"}:A}"
|
||||||
|
awk "$awk_script" "$zshrc" > "$zdot/.zshrc.new" \
|
||||||
|
|| {
|
||||||
|
# Prepend ZSH_THEME= line to .zshrc if it doesn't exist
|
||||||
|
cat <<EOF
|
||||||
|
ZSH_THEME="$1" # set by \`omz\`
|
||||||
|
|
||||||
|
EOF
|
||||||
|
cat "$zdot/.zshrc"
|
||||||
|
} > "$zdot/.zshrc.new" \
|
||||||
|
&& command cp -f "$zshrc" "$zdot/.zshrc.bck" \
|
||||||
|
&& command mv -f "$zdot/.zshrc.new" "$zshrc"
|
||||||
|
|
||||||
|
# Exit if the new .zshrc file wasn't created correctly
|
||||||
|
[[ $? -eq 0 ]] || {
|
||||||
|
local ret=$?
|
||||||
|
_omz::log error "error setting theme."
|
||||||
|
return $ret
|
||||||
|
}
|
||||||
|
|
||||||
|
# Exit if the new .zshrc file has syntax errors
|
||||||
|
if ! command zsh -n "$zdot/.zshrc"; then
|
||||||
|
_omz::log error "broken syntax in '"${zdot/#$HOME/\~}/.zshrc"'. Rolling back changes..."
|
||||||
|
command mv -f "$zdot/.zshrc.bck" "$zshrc"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Restart the zsh session if there were no errors
|
||||||
|
_omz::log info "'$1' theme set correctly."
|
||||||
|
|
||||||
|
# Only reload zsh if run in an interactive session
|
||||||
|
[[ ! -o interactive ]] || _omz::reload
|
||||||
|
}
|
||||||
|
|
||||||
|
function _omz::theme::use {
|
||||||
|
if [[ -z "$1" ]]; then
|
||||||
|
echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <theme>"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Respect compatibility with old lookup order
|
||||||
|
if [[ -f "$ZSH_CUSTOM/$1.zsh-theme" ]]; then
|
||||||
|
source "$ZSH_CUSTOM/$1.zsh-theme"
|
||||||
|
elif [[ -f "$ZSH_CUSTOM/themes/$1.zsh-theme" ]]; then
|
||||||
|
source "$ZSH_CUSTOM/themes/$1.zsh-theme"
|
||||||
|
elif [[ -f "$ZSH/themes/$1.zsh-theme" ]]; then
|
||||||
|
source "$ZSH/themes/$1.zsh-theme"
|
||||||
|
else
|
||||||
|
_omz::log error "%B$1%b theme not found"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Update theme settings
|
||||||
|
ZSH_THEME="$1"
|
||||||
|
[[ $1 = random ]] || unset RANDOM_THEME
|
||||||
|
}
|
||||||
|
|
||||||
|
function _omz::update {
|
||||||
|
# Check if git command is available
|
||||||
|
(( $+commands[git] )) || {
|
||||||
|
_omz::log error "git is not installed. Aborting..."
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check if --unattended was passed
|
||||||
|
[[ "$1" != --unattended ]] || {
|
||||||
|
_omz::log error "the \`\e[2m--unattended\e[0m\` flag is no longer supported, use the \`\e[2mupgrade.sh\e[0m\` script instead."
|
||||||
|
_omz::log error "for more information see https://github.com/ohmyzsh/ohmyzsh/wiki/FAQ#how-do-i-update-oh-my-zsh"
|
||||||
|
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
|
||||||
|
local verbose_mode cooldown_days
|
||||||
|
zstyle -s ':omz:update' verbose verbose_mode || verbose_mode=default
|
||||||
|
zstyle -s ':omz:update' cooldown cooldown_days || cooldown_days=0
|
||||||
|
[[ $cooldown_days == <-> ]] || cooldown_days=0
|
||||||
|
ZSH="$ZSH" command zsh -f "$ZSH/tools/upgrade.sh" -i -v $verbose_mode -c $cooldown_days || return $?
|
||||||
|
|
||||||
|
# Update last updated file
|
||||||
|
zmodload zsh/datetime
|
||||||
|
echo "LAST_EPOCH=$(( EPOCHSECONDS / 60 / 60 / 24 ))" >! "${ZSH_CACHE_DIR}/.zsh-update"
|
||||||
|
# Remove update lock if it exists
|
||||||
|
command rm -rf "$ZSH/log/update.lock"
|
||||||
|
|
||||||
|
# Restart the zsh session if there were changes
|
||||||
|
if [[ "$(builtin cd -q "$ZSH"; git rev-parse HEAD)" != "$last_commit" ]]; then
|
||||||
|
# Old zsh versions don't have ZSH_ARGZERO
|
||||||
|
local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"
|
||||||
|
# ZSH_ARGZERO is how zsh was invoked, not the path to it, so re-resolve
|
||||||
|
# anything that is not absolute via $PATH at exec time (see #13919)
|
||||||
|
[[ "${zsh#-}" != /* ]] && (( $+commands[zsh] )) && zsh="zsh"
|
||||||
|
# Check whether to run a login shell
|
||||||
|
[[ "$zsh" = -* || -o login ]] && exec -l "${zsh#-}" || exec "$zsh"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function _omz::version {
|
||||||
|
(
|
||||||
|
builtin cd -q "$ZSH"
|
||||||
|
|
||||||
|
# Get the version name:
|
||||||
|
# 1) try tag-like version
|
||||||
|
# 2) try branch name
|
||||||
|
# 3) try name-rev (tag~<rev> or branch~<rev>)
|
||||||
|
local version
|
||||||
|
version=$(command git describe --tags HEAD 2>/dev/null) \
|
||||||
|
|| version=$(command git symbolic-ref --quiet --short HEAD 2>/dev/null) \
|
||||||
|
|| version=$(command git name-rev --no-undefined --name-only --exclude="remotes/*" HEAD 2>/dev/null) \
|
||||||
|
|| version="<detached>"
|
||||||
|
|
||||||
|
# Get short hash for the current HEAD
|
||||||
|
local commit=$(command git rev-parse --short HEAD 2>/dev/null)
|
||||||
|
|
||||||
|
# Show version and commit hash
|
||||||
|
printf "%s (%s)\n" "$version" "$commit"
|
||||||
|
)
|
||||||
|
}
|
||||||
+1
-31
@@ -16,10 +16,6 @@
|
|||||||
# - doitclient (for SSH) http://www.chiark.greenend.org.uk/~sgtatham/doit/
|
# - doitclient (for SSH) http://www.chiark.greenend.org.uk/~sgtatham/doit/
|
||||||
# - win32yank (Windows)
|
# - win32yank (Windows)
|
||||||
# - tmux (if $TMUX is set)
|
# - tmux (if $TMUX is set)
|
||||||
# - OSC 52 (when no clipboard tool is available, e.g. over SSH or in a container)
|
|
||||||
#
|
|
||||||
# Set ZSH_CLIPBOARD_OSC52 to "always" to copy through OSC 52 even if a
|
|
||||||
# clipboard tool is available, or to "never" to disable the fallback.
|
|
||||||
#
|
#
|
||||||
# Defines two functions, clipcopy and clippaste, based on the detected platform.
|
# Defines two functions, clipcopy and clippaste, based on the detected platform.
|
||||||
##
|
##
|
||||||
@@ -52,22 +48,6 @@
|
|||||||
# # Paste to a file
|
# # Paste to a file
|
||||||
# clippaste > file.txt
|
# clippaste > file.txt
|
||||||
#
|
#
|
||||||
function _has_osc52_clipboard() {
|
|
||||||
[[ -n "${TTY:-}" ]] && [[ -w "${TTY}" ]] && (( ${+commands[base64]} ))
|
|
||||||
}
|
|
||||||
|
|
||||||
function _clipcopy_osc52() {
|
|
||||||
emulate -L zsh
|
|
||||||
local content
|
|
||||||
content=$(cat "${1:-/dev/stdin}" | base64 | tr -d '\n') || return 1
|
|
||||||
print -rn -- $'\e]52;c;'"${content}"$'\e\\' > /dev/tty
|
|
||||||
}
|
|
||||||
|
|
||||||
function _clippaste_osc52() {
|
|
||||||
print 'clippaste: OSC 52 is write-only and no other clipboard tool was found' >&2
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
function detect-clipboard() {
|
function detect-clipboard() {
|
||||||
emulate -L zsh
|
emulate -L zsh
|
||||||
|
|
||||||
@@ -79,10 +59,7 @@ function detect-clipboard() {
|
|||||||
function clippaste() { cat /dev/clipboard; }
|
function clippaste() { cat /dev/clipboard; }
|
||||||
elif (( $+commands[clip.exe] )) && (( $+commands[powershell.exe] )); then
|
elif (( $+commands[clip.exe] )) && (( $+commands[powershell.exe] )); then
|
||||||
function clipcopy() { cat "${1:-/dev/stdin}" | clip.exe; }
|
function clipcopy() { cat "${1:-/dev/stdin}" | clip.exe; }
|
||||||
function clippaste() {
|
function clippaste() { powershell.exe -noprofile -command Get-Clipboard; }
|
||||||
setopt localoptions pipefail
|
|
||||||
powershell.exe -noprofile -command Get-Clipboard | tr -d '\r'
|
|
||||||
}
|
|
||||||
elif [ -n "${WAYLAND_DISPLAY:-}" ] && (( ${+commands[wl-copy]} )) && (( ${+commands[wl-paste]} )); then
|
elif [ -n "${WAYLAND_DISPLAY:-}" ] && (( ${+commands[wl-copy]} )) && (( ${+commands[wl-paste]} )); then
|
||||||
function clipcopy() { cat "${1:-/dev/stdin}" | wl-copy &>/dev/null &|; }
|
function clipcopy() { cat "${1:-/dev/stdin}" | wl-copy &>/dev/null &|; }
|
||||||
function clippaste() { wl-paste --no-newline; }
|
function clippaste() { wl-paste --no-newline; }
|
||||||
@@ -107,9 +84,6 @@ function detect-clipboard() {
|
|||||||
elif [ -n "${TMUX:-}" ] && (( ${+commands[tmux]} )); then
|
elif [ -n "${TMUX:-}" ] && (( ${+commands[tmux]} )); then
|
||||||
function clipcopy() { tmux load-buffer -w "${1:--}"; }
|
function clipcopy() { tmux load-buffer -w "${1:--}"; }
|
||||||
function clippaste() { tmux save-buffer -; }
|
function clippaste() { tmux save-buffer -; }
|
||||||
elif [[ "${ZSH_CLIPBOARD_OSC52:-}" != never ]] && _has_osc52_clipboard; then
|
|
||||||
function clipcopy() { _clipcopy_osc52 "$@"; }
|
|
||||||
function clippaste() { _clippaste_osc52; }
|
|
||||||
else
|
else
|
||||||
function _retry_clipboard_detection_or_fail() {
|
function _retry_clipboard_detection_or_fail() {
|
||||||
local clipcmd="${1}"; shift
|
local clipcmd="${1}"; shift
|
||||||
@@ -124,10 +98,6 @@ function detect-clipboard() {
|
|||||||
function clippaste() { _retry_clipboard_detection_or_fail clippaste "$@"; }
|
function clippaste() { _retry_clipboard_detection_or_fail clippaste "$@"; }
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${ZSH_CLIPBOARD_OSC52:-}" == always ]] && _has_osc52_clipboard; then
|
|
||||||
function clipcopy() { _clipcopy_osc52 "$@"; }
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function clipcopy clippaste {
|
function clipcopy clippaste {
|
||||||
|
|||||||
+353
-3
@@ -1,3 +1,353 @@
|
|||||||
# Keep this library path available for custom overrides.
|
# diagnostics.zsh
|
||||||
# Force zsh-style autoloading so the first invocation runs once under kshautoload.
|
#
|
||||||
autoload -Uz omz_diagnostic_dump
|
# Diagnostic and debugging support for oh-my-zsh
|
||||||
|
|
||||||
|
# omz_diagnostic_dump()
|
||||||
|
#
|
||||||
|
# Author: Andrew Janke <andrew@apjanke.net>
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
#
|
||||||
|
# omz_diagnostic_dump [-v] [-V] [file]
|
||||||
|
#
|
||||||
|
# NOTE: This is a work in progress. Its interface and behavior are going to change,
|
||||||
|
# and probably in non-back-compatible ways.
|
||||||
|
#
|
||||||
|
# Outputs a bunch of information about the state and configuration of
|
||||||
|
# oh-my-zsh, zsh, and the user's system. This is intended to provide a
|
||||||
|
# bunch of context for diagnosing your own or a third party's problems, and to
|
||||||
|
# be suitable for posting to public bug reports.
|
||||||
|
#
|
||||||
|
# The output is human-readable and its format may change over time. It is not
|
||||||
|
# suitable for parsing. All the output is in one single file so it can be posted
|
||||||
|
# as a gist or bug comment on GitHub. GitHub doesn't support attaching tarballs
|
||||||
|
# or other files to bugs; otherwise, this would probably have an option to produce
|
||||||
|
# tarballs that contain copies of the config and customization files instead of
|
||||||
|
# catting them all in to one file.
|
||||||
|
#
|
||||||
|
# This is intended to be widely portable, and run anywhere that oh-my-zsh does.
|
||||||
|
# Feel free to report any portability issues as bugs.
|
||||||
|
#
|
||||||
|
# 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
|
||||||
|
# redefinitions.
|
||||||
|
#
|
||||||
|
# OPTIONS
|
||||||
|
#
|
||||||
|
# [file] Specifies the output file. If not given, a file in the current directory
|
||||||
|
# is selected automatically.
|
||||||
|
#
|
||||||
|
# -v Increase the verbosity of the dump output. May be specified multiple times.
|
||||||
|
# Verbosity levels:
|
||||||
|
# 0 - Basic info, shell state, omz configuration, git state
|
||||||
|
# 1 - (default) Adds key binding info and configuration file contents
|
||||||
|
# 2 - Adds zcompdump file contents
|
||||||
|
#
|
||||||
|
# -V Reduce the verbosity of the dump output. May be specified multiple times.
|
||||||
|
#
|
||||||
|
# TODO:
|
||||||
|
# * Multi-file capture
|
||||||
|
# * Add automatic gist uploading
|
||||||
|
# * Consider whether to move default output file location to TMPDIR. More robust
|
||||||
|
# but less user friendly.
|
||||||
|
#
|
||||||
|
|
||||||
|
autoload -Uz is-at-least
|
||||||
|
|
||||||
|
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
|
||||||
|
local timestamp=$(date +%Y%m%d-%H%M%S)
|
||||||
|
local outfile=omz_diagdump_$timestamp.txt
|
||||||
|
builtin zparseopts -A opts -D -- "v+=opt_verbose" "V+=opt_noverbose"
|
||||||
|
local verbose n_verbose=${#opt_verbose} n_noverbose=${#opt_noverbose}
|
||||||
|
(( verbose = 1 + n_verbose - n_noverbose ))
|
||||||
|
|
||||||
|
if [[ ${#*} > 0 ]]; then
|
||||||
|
opt_outfile=$1
|
||||||
|
fi
|
||||||
|
if [[ ${#*} > 1 ]]; then
|
||||||
|
builtin echo "$thisfcn: error: too many arguments" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
if [[ -n "$opt_outfile" ]]; then
|
||||||
|
outfile="$opt_outfile"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Always write directly to a file so terminal escape sequences are
|
||||||
|
# captured cleanly
|
||||||
|
_omz_diag_dump_one_big_text &> "$outfile"
|
||||||
|
if [[ $? != 0 ]]; then
|
||||||
|
builtin echo "$thisfcn: error while creating diagnostic dump; see $outfile for details"
|
||||||
|
fi
|
||||||
|
|
||||||
|
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 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,"
|
||||||
|
builtin echo "so don't share it publicly if there's sensitive information in them."
|
||||||
|
builtin echo
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function _omz_diag_dump_one_big_text() {
|
||||||
|
local program programs progfile md5
|
||||||
|
|
||||||
|
builtin echo oh-my-zsh diagnostic dump
|
||||||
|
builtin echo
|
||||||
|
builtin echo $outfile
|
||||||
|
builtin echo
|
||||||
|
|
||||||
|
# Basic system and zsh information
|
||||||
|
command date
|
||||||
|
command uname -a
|
||||||
|
builtin echo OSTYPE=$OSTYPE
|
||||||
|
builtin echo ZSH_VERSION=$ZSH_VERSION
|
||||||
|
builtin echo User: $USERNAME
|
||||||
|
builtin echo umask: $(umask)
|
||||||
|
builtin echo
|
||||||
|
_omz_diag_dump_os_specific_version
|
||||||
|
builtin echo
|
||||||
|
|
||||||
|
# Installed programs
|
||||||
|
programs=(sh zsh ksh bash sed cat grep ls find git posh)
|
||||||
|
local progfile="" extra_str="" sha_str=""
|
||||||
|
for program in $programs; do
|
||||||
|
extra_str="" sha_str=""
|
||||||
|
progfile=$(builtin which $program)
|
||||||
|
if [[ $? == 0 ]]; then
|
||||||
|
if [[ -e $progfile ]]; then
|
||||||
|
if builtin whence shasum &>/dev/null; then
|
||||||
|
sha_str=($(command shasum $progfile))
|
||||||
|
sha_str=$sha_str[1]
|
||||||
|
extra_str+=" SHA $sha_str"
|
||||||
|
fi
|
||||||
|
if [[ -h "$progfile" ]]; then
|
||||||
|
extra_str+=" ( -> ${progfile:A} )"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
builtin printf '%-9s %-20s %s\n' "$program is" "$progfile" "$extra_str"
|
||||||
|
else
|
||||||
|
builtin echo "$program: not found"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
builtin echo
|
||||||
|
builtin echo Command Versions:
|
||||||
|
builtin echo "zsh: $(zsh --version)"
|
||||||
|
builtin echo "this zsh session: $ZSH_VERSION"
|
||||||
|
builtin echo "bash: $(bash --version | command grep bash)"
|
||||||
|
builtin echo "git: $(git --version)"
|
||||||
|
builtin echo "grep: $(grep --version)"
|
||||||
|
builtin echo
|
||||||
|
|
||||||
|
# Core command definitions
|
||||||
|
_omz_diag_dump_check_core_commands || return 1
|
||||||
|
builtin echo
|
||||||
|
|
||||||
|
# ZSH Process state
|
||||||
|
builtin echo Process state:
|
||||||
|
builtin echo pwd: $PWD
|
||||||
|
if builtin whence pstree &>/dev/null; then
|
||||||
|
builtin echo Process tree for this shell:
|
||||||
|
pstree -p $$
|
||||||
|
else
|
||||||
|
ps -fT
|
||||||
|
fi
|
||||||
|
builtin set | command grep -a '^\(ZSH\|plugins\|TERM\|LC_\|LANG\|precmd\|chpwd\|preexec\|FPATH\|TTY\|DISPLAY\|PATH\)\|OMZ'
|
||||||
|
builtin echo
|
||||||
|
#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 Locale:
|
||||||
|
command locale
|
||||||
|
builtin echo
|
||||||
|
|
||||||
|
# Zsh installation and configuration
|
||||||
|
builtin echo Zsh configuration:
|
||||||
|
builtin echo setopt: $(builtin setopt)
|
||||||
|
builtin echo
|
||||||
|
builtin echo zstyle:
|
||||||
|
builtin zstyle
|
||||||
|
builtin echo
|
||||||
|
builtin echo 'compaudit output:'
|
||||||
|
compaudit
|
||||||
|
builtin echo
|
||||||
|
builtin echo '$fpath directories:'
|
||||||
|
command ls -lad $fpath
|
||||||
|
builtin echo
|
||||||
|
|
||||||
|
# Oh-my-zsh installation
|
||||||
|
builtin echo oh-my-zsh installation:
|
||||||
|
command ls -ld ~/.z*
|
||||||
|
command ls -ld ~/.oh*
|
||||||
|
builtin echo
|
||||||
|
builtin echo oh-my-zsh git state:
|
||||||
|
(builtin cd $ZSH && builtin echo "HEAD: $(git rev-parse HEAD)" && git remote -v && git status | command grep "[^[:space:]]")
|
||||||
|
if [[ $verbose -ge 1 ]]; then
|
||||||
|
(builtin cd $ZSH && git reflog --date=default | command grep pull)
|
||||||
|
fi
|
||||||
|
builtin echo
|
||||||
|
if [[ -e $ZSH_CUSTOM ]]; then
|
||||||
|
local custom_dir=$ZSH_CUSTOM
|
||||||
|
if [[ -h $custom_dir ]]; then
|
||||||
|
custom_dir=$(builtin cd $custom_dir && pwd -P)
|
||||||
|
fi
|
||||||
|
builtin echo "oh-my-zsh custom dir:"
|
||||||
|
builtin echo " $ZSH_CUSTOM ($custom_dir)"
|
||||||
|
(builtin cd ${custom_dir:h} && command find ${custom_dir:t} -name .git -prune -o -print)
|
||||||
|
builtin echo
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Key binding and terminal info
|
||||||
|
if [[ $verbose -ge 1 ]]; then
|
||||||
|
builtin echo "bindkey:"
|
||||||
|
builtin bindkey
|
||||||
|
builtin echo
|
||||||
|
builtin echo "infocmp:"
|
||||||
|
command infocmp -L
|
||||||
|
builtin echo
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Configuration file info
|
||||||
|
local zdotdir=${ZDOTDIR:-$HOME}
|
||||||
|
builtin echo "Zsh configuration files:"
|
||||||
|
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
|
||||||
|
$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 )
|
||||||
|
command ls -lad $cfgfiles 2>&1
|
||||||
|
builtin echo
|
||||||
|
if [[ $verbose -ge 1 ]]; then
|
||||||
|
for cfgfile in $cfgfiles; do
|
||||||
|
_omz_diag_dump_echo_file_w_header $cfgfile
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
builtin echo
|
||||||
|
builtin echo "Zsh compdump files:"
|
||||||
|
local dumpfile dumpfiles
|
||||||
|
command ls -lad $zdotdir/.zcompdump*
|
||||||
|
dumpfiles=( $zdotdir/.zcompdump*(N) )
|
||||||
|
if [[ $verbose -ge 2 ]]; then
|
||||||
|
for dumpfile in $dumpfiles; do
|
||||||
|
_omz_diag_dump_echo_file_w_header $dumpfile
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function _omz_diag_dump_check_core_commands() {
|
||||||
|
builtin echo "Core command check:"
|
||||||
|
local redefined name builtins externals reserved_words
|
||||||
|
redefined=()
|
||||||
|
# All the zsh non-module builtin commands
|
||||||
|
# These are taken from the zsh reference manual for 5.0.2
|
||||||
|
# Commands from modules should not be included.
|
||||||
|
# (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 '!' '[[' '{' '}'
|
||||||
|
)
|
||||||
|
builtins=( alias autoload bg bindkey break builtin bye cd chdir command
|
||||||
|
comparguments compcall compctl compdescribe compfiles compgroups compquote comptags
|
||||||
|
comptry compvalues continue dirs disable disown echo echotc echoti emulate
|
||||||
|
enable eval exec exit false fc fg functions getln getopts hash
|
||||||
|
jobs kill let limit log logout noglob popd print printf
|
||||||
|
pushd pushln pwd r read rehash return sched set setopt shift
|
||||||
|
source suspend test times trap true ttyctl type ulimit umask unalias
|
||||||
|
unfunction unhash unlimit unset unsetopt vared wait whence where which zcompile
|
||||||
|
zle zmodload zparseopts zregexparse zstyle )
|
||||||
|
if is-at-least 5.1; then
|
||||||
|
reserved_words+=( declare export integer float local readonly typeset )
|
||||||
|
else
|
||||||
|
builtins+=( declare export integer float local readonly typeset )
|
||||||
|
fi
|
||||||
|
builtins_fatal=( builtin command local )
|
||||||
|
externals=( zsh )
|
||||||
|
for name in $reserved_words; do
|
||||||
|
if [[ $(builtin whence -w $name) != "$name: reserved" ]]; then
|
||||||
|
builtin echo "reserved word '$name' has been redefined"
|
||||||
|
builtin which $name
|
||||||
|
redefined+=$name
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
for name in $builtins; do
|
||||||
|
if [[ $(builtin whence -w $name) != "$name: builtin" ]]; then
|
||||||
|
builtin echo "builtin '$name' has been redefined"
|
||||||
|
builtin which $name
|
||||||
|
redefined+=$name
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
for name in $externals; do
|
||||||
|
if [[ $(builtin whence -w $name) != "$name: command" ]]; then
|
||||||
|
builtin echo "command '$name' has been redefined"
|
||||||
|
builtin which $name
|
||||||
|
redefined+=$name
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ -n "$redefined" ]]; then
|
||||||
|
builtin echo "SOME CORE COMMANDS HAVE BEEN REDEFINED: $redefined"
|
||||||
|
else
|
||||||
|
builtin echo "All core commands are defined normally"
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function _omz_diag_dump_echo_file_w_header() {
|
||||||
|
local file=$1
|
||||||
|
if [[ ( -f $file || -h $file ) ]]; then
|
||||||
|
builtin echo "========== $file =========="
|
||||||
|
if [[ -h $file ]]; then
|
||||||
|
builtin echo "========== ( => ${file:A} ) =========="
|
||||||
|
fi
|
||||||
|
command cat $file
|
||||||
|
builtin echo "========== end $file =========="
|
||||||
|
builtin echo
|
||||||
|
elif [[ -d $file ]]; then
|
||||||
|
builtin echo "File '$file' is a directory"
|
||||||
|
elif [[ ! -e $file ]]; then
|
||||||
|
builtin echo "File '$file' does not exist"
|
||||||
|
else
|
||||||
|
command ls -lad "$file"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function _omz_diag_dump_os_specific_version() {
|
||||||
|
local osname osver version_file version_files
|
||||||
|
case "$OSTYPE" in
|
||||||
|
darwin*)
|
||||||
|
osname=$(command sw_vers -productName)
|
||||||
|
osver=$(command sw_vers -productVersion)
|
||||||
|
builtin echo "OS Version: $osname $osver build $(sw_vers -buildVersion)"
|
||||||
|
;;
|
||||||
|
cygwin)
|
||||||
|
command systeminfo | command head -n 4 | command tail -n 2
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if builtin which lsb_release >/dev/null; then
|
||||||
|
builtin echo "OS Release: $(command lsb_release -s -d)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
version_files=( /etc/*-release(N) /etc/*-version(N) /etc/*_version(N) )
|
||||||
|
for version_file in $version_files; do
|
||||||
|
builtin echo "$version_file:"
|
||||||
|
command cat "$version_file"
|
||||||
|
builtin echo
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
+1
-1
@@ -231,7 +231,7 @@ function omz_urlencode() {
|
|||||||
url_str+="$byte"
|
url_str+="$byte"
|
||||||
else
|
else
|
||||||
ord=$(( [##16] #byte ))
|
ord=$(( [##16] #byte ))
|
||||||
url_str+="%${(l:2::0:)ord}"
|
url_str+="%$ord"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -110,6 +110,23 @@ bindkey -M emacs '^[[1;5D' backward-word
|
|||||||
bindkey -M viins '^[[1;5D' backward-word
|
bindkey -M viins '^[[1;5D' backward-word
|
||||||
bindkey -M vicmd '^[[1;5D' backward-word
|
bindkey -M vicmd '^[[1;5D' backward-word
|
||||||
|
|
||||||
|
# [Keypad] - application mode (enabled above) makes the keypad send escape
|
||||||
|
# sequences instead of characters, so map them back to the plain keys
|
||||||
|
() {
|
||||||
|
local seq key
|
||||||
|
local -A keypad=(
|
||||||
|
'^[Op' '0' '^[Oq' '1' '^[Or' '2' '^[Os' '3' '^[Ot' '4'
|
||||||
|
'^[Ou' '5' '^[Ov' '6' '^[Ow' '7' '^[Ox' '8' '^[Oy' '9'
|
||||||
|
'^[On' '.' '^[Ol' ',' '^[Ok' '+' '^[Om' '-' '^[Oj' '*'
|
||||||
|
'^[Oo' '/' '^[OX' '=' '^[OM' '^M'
|
||||||
|
)
|
||||||
|
for seq key in "${(@kv)keypad}"; do
|
||||||
|
bindkey -M emacs -s "$seq" "$key"
|
||||||
|
bindkey -M viins -s "$seq" "$key"
|
||||||
|
bindkey -M vicmd -s "$seq" "$key"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bindkey '\ew' kill-region # [Esc-w] - Kill from the cursor to the mark
|
bindkey '\ew' kill-region # [Esc-w] - Kill from the cursor to the mark
|
||||||
bindkey -s '\el' '^q ls\n' # [Esc-l] - run command: ls
|
bindkey -s '\el' '^q ls\n' # [Esc-l] - run command: ls
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
# P.C. Shyamshankar <sykora@lucentbeing.com>
|
# P.C. Shyamshankar <sykora@lucentbeing.com>
|
||||||
# Copied from https://github.com/sykora/etc/blob/master/zsh/functions/spectrum/
|
# Copied from https://github.com/sykora/etc/blob/master/zsh/functions/spectrum/
|
||||||
|
|
||||||
autoload -Uz is-at-least
|
|
||||||
|
|
||||||
typeset -AHg FX FG BG
|
typeset -AHg FX FG BG
|
||||||
|
|
||||||
FX=(
|
FX=(
|
||||||
@@ -20,16 +18,7 @@ FX=(
|
|||||||
() {
|
() {
|
||||||
setopt localoptions noksharrays
|
setopt localoptions noksharrays
|
||||||
local -a codes fg bg
|
local -a codes fg bg
|
||||||
local code
|
|
||||||
codes=({000..255})
|
codes=({000..255})
|
||||||
# ${a:^b} array zipping needs zsh 5.0.6
|
|
||||||
if ! is-at-least 5.0.6; then
|
|
||||||
for code in $codes; do
|
|
||||||
FG[$code]="%{"$'\e'"[38;5;${code}m%}"
|
|
||||||
BG[$code]="%{"$'\e'"[48;5;${code}m%}"
|
|
||||||
done
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
fg=( "%{"$'\e'"[38;5;"${^codes}"m%}" )
|
fg=( "%{"$'\e'"[38;5;"${^codes}"m%}" )
|
||||||
bg=( "%{"$'\e'"[48;5;"${^codes}"m%}" )
|
bg=( "%{"$'\e'"[48;5;"${^codes}"m%}" )
|
||||||
FG=( ${codes:^fg} )
|
FG=( ${codes:^fg} )
|
||||||
|
|||||||
+9
-18
@@ -5,6 +5,7 @@
|
|||||||
# See: http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#ss3.1
|
# See: http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#ss3.1
|
||||||
# Fully supports screen, iterm, and probably most modern xterm and rxvt
|
# Fully supports screen, iterm, and probably most modern xterm and rxvt
|
||||||
# (In screen, only short_tab_title is used)
|
# (In screen, only short_tab_title is used)
|
||||||
|
# Limited support for Apple Terminal (Terminal can't set window and tab separately)
|
||||||
function title {
|
function title {
|
||||||
setopt localoptions nopromptsubst
|
setopt localoptions nopromptsubst
|
||||||
|
|
||||||
@@ -16,7 +17,7 @@ function title {
|
|||||||
: ${2=$1}
|
: ${2=$1}
|
||||||
|
|
||||||
case "$TERM" in
|
case "$TERM" in
|
||||||
cygwin|xterm*|putty*|rxvt*|konsole*|ansi|mlterm*|alacritty*|st*|foot*|contour*|wezterm*|nsterm*)
|
cygwin|xterm*|putty*|rxvt*|konsole*|ansi|mlterm*|alacritty*|st*|foot*|contour*|wezterm*)
|
||||||
print -Pn "\e]2;${2:q}\a" # set window name
|
print -Pn "\e]2;${2:q}\a" # set window name
|
||||||
print -Pn "\e]1;${1:q}\a" # set tab name
|
print -Pn "\e]1;${1:q}\a" # set tab name
|
||||||
;;
|
;;
|
||||||
@@ -25,12 +26,10 @@ function title {
|
|||||||
print -Pn "\ek${1:q}\e\\" # set screen hardstatus/tmux window name if `allow-rename` is on
|
print -Pn "\ek${1:q}\e\\" # set screen hardstatus/tmux window name if `allow-rename` is on
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
case "$TERM_PROGRAM" in
|
if [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
|
||||||
"iTerm.app"|"Apple_Terminal")
|
|
||||||
print -Pn "\e]2;${2:q}\a" # set window name
|
print -Pn "\e]2;${2:q}\a" # set window name
|
||||||
print -Pn "\e]1;${1:q}\a" # set tab name
|
print -Pn "\e]1;${1:q}\a" # set tab name
|
||||||
;;
|
else
|
||||||
*)
|
|
||||||
# Try to use terminfo to set the title if the feature is available
|
# Try to use terminfo to set the title if the feature is available
|
||||||
if (( ${+terminfo[fsl]} && ${+terminfo[tsl]} )); then
|
if (( ${+terminfo[fsl]} && ${+terminfo[tsl]} )); then
|
||||||
# Emit the capabilities with echoti so terminfo does its own parameter
|
# Emit the capabilities with echoti so terminfo does its own parameter
|
||||||
@@ -40,8 +39,7 @@ function title {
|
|||||||
print -Pn "$1"
|
print -Pn "$1"
|
||||||
echoti fsl
|
echoti fsl
|
||||||
fi
|
fi
|
||||||
;;
|
fi
|
||||||
esac
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
@@ -154,23 +152,16 @@ esac
|
|||||||
# the host name to disambiguate local vs. remote paths.
|
# the host name to disambiguate local vs. remote paths.
|
||||||
function omz_termsupport_cwd {
|
function omz_termsupport_cwd {
|
||||||
setopt localoptions unset
|
setopt localoptions unset
|
||||||
# Percent-encode the host and path names. Encoding forks a subshell each,
|
# Percent-encode the host and path names.
|
||||||
# so keep the result and only redo it when its inputs change.
|
|
||||||
local cache_key="$HOST:$PWD:${langinfo[CODESET]}:${KONSOLE_PROFILE_NAME:+1}:${KONSOLE_DBUS_SESSION:+1}"
|
|
||||||
if [[ "$_omz_termsupport_cwd_key" != "$cache_key" ]]; then
|
|
||||||
local URL_HOST URL_PATH
|
local URL_HOST URL_PATH
|
||||||
URL_HOST="$(omz_urlencode -P "$HOST")" || return 1
|
URL_HOST="$(omz_urlencode -P $HOST)" || return 1
|
||||||
URL_PATH="$(omz_urlencode -P "$PWD")" || return 1
|
URL_PATH="$(omz_urlencode -P $PWD)" || return 1
|
||||||
|
|
||||||
# Konsole errors if the HOST is provided
|
# Konsole errors if the HOST is provided
|
||||||
[[ -z "$KONSOLE_PROFILE_NAME" && -z "$KONSOLE_DBUS_SESSION" ]] || URL_HOST=""
|
[[ -z "$KONSOLE_PROFILE_NAME" && -z "$KONSOLE_DBUS_SESSION" ]] || URL_HOST=""
|
||||||
|
|
||||||
typeset -g _omz_termsupport_cwd_key="$cache_key"
|
|
||||||
typeset -g _omz_termsupport_cwd_url="file://${URL_HOST}${URL_PATH}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# common control sequence (OSC 7) to set current host and path
|
# common control sequence (OSC 7) to set current host and path
|
||||||
printf "\e]7;%s\e\\" "$_omz_termsupport_cwd_url"
|
printf "\e]7;file://%s%s\e\\" "${URL_HOST}" "${URL_PATH}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Use a precmd hook instead of a chpwd hook to avoid contaminating output
|
# Use a precmd hook instead of a chpwd hook to avoid contaminating output
|
||||||
|
|||||||
@@ -7,9 +7,6 @@ run_awk() {
|
|||||||
(( ! DEBUG )) || set -xv
|
(( ! DEBUG )) || set -xv
|
||||||
|
|
||||||
local awk_subst_plugins="\
|
local awk_subst_plugins="\
|
||||||
do {
|
|
||||||
prev = \$0
|
|
||||||
|
|
||||||
gsub(/[ \t]+(${(j:|:)dis_plugins})[ \t]+/, \" \") # with spaces before or after
|
gsub(/[ \t]+(${(j:|:)dis_plugins})[ \t]+/, \" \") # with spaces before or after
|
||||||
gsub(/[ \t]+(${(j:|:)dis_plugins})$/, \"\") # with spaces before and EOL
|
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 BOL and spaces after
|
||||||
@@ -20,7 +17,6 @@ run_awk() {
|
|||||||
|
|
||||||
gsub(/^(${(j:|:)dis_plugins})\)/, \")\") # with BOL and closing parenthesis
|
gsub(/^(${(j:|:)dis_plugins})\)/, \")\") # with BOL and closing parenthesis
|
||||||
gsub(/\((${(j:|:)dis_plugins})$/, \"(\") # with opening parenthesis and EOL
|
gsub(/\((${(j:|:)dis_plugins})$/, \"(\") # with opening parenthesis and EOL
|
||||||
} while (\$0 != prev)
|
|
||||||
"
|
"
|
||||||
# Disable plugins awk script
|
# Disable plugins awk script
|
||||||
local awk_script="
|
local awk_script="
|
||||||
@@ -171,34 +167,3 @@ z)" \
|
|||||||
"plugins=(
|
"plugins=(
|
||||||
git
|
git
|
||||||
)"
|
)"
|
||||||
|
|
||||||
run_awk_and_test \
|
|
||||||
"it should delete two adjacent plugins among others in oneline format" \
|
|
||||||
"docker kubectl" \
|
|
||||||
"plugins=(git docker kubectl npm)" \
|
|
||||||
"plugins=(git npm)"
|
|
||||||
|
|
||||||
run_awk_and_test \
|
|
||||||
"it should delete three adjacent plugins among others in oneline format" \
|
|
||||||
"docker kubectl aws" \
|
|
||||||
"plugins=(git docker kubectl aws npm)" \
|
|
||||||
"plugins=(git npm)"
|
|
||||||
|
|
||||||
run_awk_and_test \
|
|
||||||
"it should delete every plugin of a long oneline list" \
|
|
||||||
"git docker kubectl aws npm z" \
|
|
||||||
"plugins=(git docker kubectl aws npm z)" \
|
|
||||||
"plugins=()"
|
|
||||||
|
|
||||||
run_awk_and_test \
|
|
||||||
"it should delete adjacent plugins sharing a line in multiline format" \
|
|
||||||
"docker kubectl aws" \
|
|
||||||
"plugins=(
|
|
||||||
git
|
|
||||||
docker kubectl aws
|
|
||||||
npm
|
|
||||||
)" \
|
|
||||||
"plugins=(
|
|
||||||
git
|
|
||||||
npm
|
|
||||||
)"
|
|
||||||
+11
-42
@@ -38,47 +38,16 @@
|
|||||||
# due to malicious input as a consequence of CVE-2021-45444, which affects
|
# due to malicious input as a consequence of CVE-2021-45444, which affects
|
||||||
# zsh versions from 5.0.3 to 5.8.
|
# zsh versions from 5.0.3 to 5.8.
|
||||||
#
|
#
|
||||||
# The patch is applied when VCS_INFO_formats is first called, since loading
|
autoload -Uz +X regexp-replace VCS_INFO_formats 2>/dev/null || return 0
|
||||||
# and patching it on every startup costs time in shells that never use
|
|
||||||
# vcs_info. `autoload` doesn't replace an already defined function, so this
|
|
||||||
# wrapper survives a later `autoload -Uz vcs_info` in a theme or .zshrc, and
|
|
||||||
# vcs_info's own `autoload -Uz VCS_INFO_formats`.
|
|
||||||
function _omz_patch_vcs_info_formats {
|
|
||||||
local formatter
|
|
||||||
if (( $# )); then
|
|
||||||
formatter="$1"
|
|
||||||
else
|
|
||||||
# Load in a subshell so the wrapper stays installed if loading fails.
|
|
||||||
formatter="$(
|
|
||||||
unfunction VCS_INFO_formats 2>/dev/null
|
|
||||||
autoload -Uz +X VCS_INFO_formats 2>/dev/null || return 1
|
|
||||||
print -r -- "$functions[VCS_INFO_formats]"
|
|
||||||
)" || return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# We use $tmp here because it's already a local variable in VCS_INFO_formats.
|
# We use $tmp here because it's already a local variable in VCS_INFO_formats
|
||||||
local patch='for tmp (base base-name branch misc revision subdir) hook_com[$tmp]="${hook_com[$tmp]//\%/%%}"'
|
typeset PATCH='for tmp (base base-name branch misc revision subdir) hook_com[$tmp]="${hook_com[$tmp]//\%/%%}"'
|
||||||
local patch_id=vcs_info-patch-9b9840f2-91e5-4471-af84-9e9a0dc68c1b
|
# Unique string to avoid reapplying the patch if this code gets called twice
|
||||||
local post_backend="VCS_INFO_hook 'post-backend'"
|
typeset PATCH_ID=vcs_info-patch-9b9840f2-91e5-4471-af84-9e9a0dc68c1b
|
||||||
if [[ $formatter != *"$patch_id"* ]]; then
|
# Only patch the VCS_INFO_formats function if not already patched
|
||||||
[[ $formatter == *"$post_backend"* ]] || return 1
|
if [[ "$functions[VCS_INFO_formats]" != *$PATCH_ID* ]]; then
|
||||||
local replacement=": $patch_id; $patch; $post_backend"
|
regexp-replace 'functions[VCS_INFO_formats]' \
|
||||||
formatter="${formatter//"$post_backend"/$replacement}"
|
"VCS_INFO_hook 'post-backend'" \
|
||||||
fi
|
': ${PATCH_ID}; ${PATCH}; ${MATCH}'
|
||||||
|
|
||||||
[[ $formatter != "$functions[VCS_INFO_formats]" ]] || return 0
|
|
||||||
# Assigning to functions reparses the body. Preserve autoload -U behavior.
|
|
||||||
setopt localoptions noaliases
|
|
||||||
functions[VCS_INFO_formats]="$formatter"
|
|
||||||
}
|
|
||||||
|
|
||||||
# An autoload stub counts as not loaded yet, so it gets the wrapper too.
|
|
||||||
if (( $+functions[VCS_INFO_formats] )) && [[ $functions[VCS_INFO_formats] != 'builtin autoload -X'* ]]; then
|
|
||||||
# A custom formatter may lack the stock hook call.
|
|
||||||
_omz_patch_vcs_info_formats "$functions[VCS_INFO_formats]" || true
|
|
||||||
else
|
|
||||||
function VCS_INFO_formats {
|
|
||||||
_omz_patch_vcs_info_formats || return 1
|
|
||||||
VCS_INFO_formats "$@"
|
|
||||||
}
|
|
||||||
fi
|
fi
|
||||||
|
unset PATCH PATCH_ID
|
||||||
+1
-1
@@ -128,7 +128,7 @@ fi
|
|||||||
|
|
||||||
# Save the location of the current completion dump file.
|
# Save the location of the current completion dump file.
|
||||||
if [[ -z "$ZSH_COMPDUMP" ]]; then
|
if [[ -z "$ZSH_COMPDUMP" ]]; then
|
||||||
ZSH_COMPDUMP="${ZSH_CACHE_DIR}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
|
ZSH_COMPDUMP="${ZDOTDIR:-$HOME}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Resolve the commit $ZSH is checked out at into $REPLY by reading the git
|
# Resolve the commit $ZSH is checked out at into $REPLY by reading the git
|
||||||
|
|||||||
@@ -58,8 +58,6 @@ Running the shortest `gs` shell alias that it found:
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
It also looks through aliases you type, suggesting only ones that cover more of the command. With the kubectl plugin, `k get pods` suggests `kgp`, while `kgp` on its own suggests nothing.
|
|
||||||
|
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
alias-finder() {
|
alias-finder() {
|
||||||
local c="" cmd=" " exact="" longer="" cheaper="" wordEnd="'?$" finder="" filter="" cmdLen=""
|
local cmd=" " exact="" longer="" cheaper="" wordEnd="'?$" finder="" filter=""
|
||||||
|
|
||||||
# build command and options
|
# build command and options
|
||||||
for c in "$@"; do
|
for c in "$@"; do
|
||||||
@@ -19,15 +19,11 @@ alias-finder() {
|
|||||||
zstyle -t ':omz:plugins:alias-finder' cheaper && cheaper=true
|
zstyle -t ':omz:plugins:alias-finder' cheaper && cheaper=true
|
||||||
|
|
||||||
# format cmd for grep
|
# format cmd for grep
|
||||||
## - replace newlines and multiple spaces with one space
|
## - replace newlines with spaces
|
||||||
## - trim both ends
|
## - trim both ends
|
||||||
|
## - replace multiple spaces with one space
|
||||||
## - add escaping character to special characters
|
## - add escaping character to special characters
|
||||||
setopt localoptions extendedglob
|
cmd=$(echo -n "$cmd" | tr '\n' ' ' | xargs | tr -s '[:space:]' | sed 's/[].\|$(){}?+*^[]/\\&/g')
|
||||||
cmd=${cmd//[[:space:]]##/ }
|
|
||||||
cmd=${cmd# }
|
|
||||||
cmd=${cmd% }
|
|
||||||
local esc_pattern='(#m)[][.\\|$(){}?+*^]' MATCH MBEGIN MEND
|
|
||||||
cmd=${cmd//${~esc_pattern}/\\$MATCH}
|
|
||||||
|
|
||||||
if [[ $longer == true ]]; then
|
if [[ $longer == true ]]; then
|
||||||
wordEnd="" # remove wordEnd to find longer aliases
|
wordEnd="" # remove wordEnd to find longer aliases
|
||||||
@@ -39,7 +35,7 @@ alias-finder() {
|
|||||||
|
|
||||||
# make filter to find only shorter results than current cmd
|
# make filter to find only shorter results than current cmd
|
||||||
if [[ $cheaper == true ]]; then
|
if [[ $cheaper == true ]]; then
|
||||||
cmdLen=${#cmd}
|
cmdLen=$(echo -n "$cmd" | wc -c)
|
||||||
if [[ $cmdLen -le 1 ]]; then
|
if [[ $cmdLen -le 1 ]]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
@@ -65,20 +61,9 @@ alias-finder() {
|
|||||||
|
|
||||||
preexec_alias-finder() {
|
preexec_alias-finder() {
|
||||||
# TODO: Remove backward compatibility (other than zstyle form)
|
# TODO: Remove backward compatibility (other than zstyle form)
|
||||||
zstyle -t ':omz:plugins:alias-finder' autoload || [[ $ZSH_ALIAS_FINDER_AUTOMATIC = true ]] || return
|
zstyle -t ':omz:plugins:alias-finder' autoload && alias-finder $1 || if [[ $ZSH_ALIAS_FINDER_AUTOMATIC = true ]]; then
|
||||||
|
alias-finder $1
|
||||||
# $3 has aliases expanded, so `k get pods` can suggest `kgp`
|
|
||||||
local -a words=(${(z)1}) found=(${(f)"$(alias-finder $3)"}) keep
|
|
||||||
local used=${aliases[$words[1]]} line
|
|
||||||
|
|
||||||
# If an alias was typed, only suggest aliases that cover more of the command
|
|
||||||
if [[ -n "$used" ]]; then
|
|
||||||
for line in $found; do
|
|
||||||
(( ${#${(Q)line#*=}} > ${#used} )) && keep+=("$line")
|
|
||||||
done
|
|
||||||
found=($keep)
|
|
||||||
fi
|
fi
|
||||||
(( $#found )) && print -rl -- $found
|
|
||||||
}
|
}
|
||||||
|
|
||||||
autoload -U add-zsh-hook
|
autoload -U add-zsh-hook
|
||||||
|
|||||||
@@ -103,34 +103,10 @@ upgrades were available. Use `pacman -Que` instead.
|
|||||||
| parep | `pacaur -Si` | Display information about a package in the repositories |
|
| parep | `pacaur -Si` | Display information about a package in the repositories |
|
||||||
| pareps | `pacaur -Ss` | Search for packages in the repositories |
|
| pareps | `pacaur -Ss` | Search for packages in the repositories |
|
||||||
| paupd | `pacaur -Sy` | Update and refresh local package, ABS and AUR databases |
|
| paupd | `pacaur -Sy` | Update and refresh local package, ABS and AUR databases |
|
||||||
| paupg | `pacaur -Syu` | Sync with repositories before upgrading all packages (from AUR too) |
|
| paupg | `pacaur -Syua` | Sync with repositories before upgrading all packages (from AUR too) |
|
||||||
| pasu | `pacaur -Syu --noconfirm` | Same as `paupg`, but without confirmation |
|
| pasu | `pacaur -Syua --no-confirm` | Same as `paupg`, but without confirmation |
|
||||||
| upgrade[¹](#f1) | `pacaur -Syu` | Sync with repositories before upgrading packages |
|
| upgrade[¹](#f1) | `pacaur -Syu` | Sync with repositories before upgrading packages |
|
||||||
|
|
||||||
#### Paru
|
|
||||||
|
|
||||||
| Alias | Command | Description |
|
|
||||||
|---------|--------------------------------|-------------------------------------------------------------------|
|
|
||||||
| puclean | `paru -Sc` | Clean out old and unused caches and packages |
|
|
||||||
| puclr | `paru -Scc` | Remove all files from the cache |
|
|
||||||
| pufiles | `paru -F` | Search the files database for packages that contain a file |
|
|
||||||
| puin | `paru -S` | Install packages from the repositories |
|
|
||||||
| puins | `paru -U` | Install a package from a local file |
|
|
||||||
| puinsd | `paru -S --asdeps` | Install packages as dependencies of another package |
|
|
||||||
| puloc | `paru -Qi` | Display information about a package in the local database |
|
|
||||||
| pulocs | `paru -Qs` | Search for packages in the local database |
|
|
||||||
| pulst | `paru -Qe` | List installed packages including from AUR (tagged as "local") |
|
|
||||||
| pumir | `paru -Syy` | Force refresh of all package lists after updating mirrorlist |
|
|
||||||
| puorph | `paru -Qtd` | List orphaned packages |
|
|
||||||
| pure | `paru -R` | Remove packages, keeping its settings and dependencies |
|
|
||||||
| purem | `paru -Rns` | Remove packages, including its settings and unneeded dependencies |
|
|
||||||
| purep | `paru -Si` | Display information about a package in the repositories |
|
|
||||||
| pureps | `paru -Ss` | Search for packages in the repositories |
|
|
||||||
| puupd | `paru -Sy` | Update and refresh local package, ABS and AUR databases |
|
|
||||||
| puupg | `paru -Syu` | Sync with repositories before upgrading packages |
|
|
||||||
| pusu | `paru -Syu --noconfirm` | Same as `puupg`, but without confirmation |
|
|
||||||
| upgrade[¹](#f1) | `paru -Syu` | Sync with repositories before upgrading packages |
|
|
||||||
|
|
||||||
#### Trizen
|
#### Trizen
|
||||||
|
|
||||||
| Alias | Command | Description |
|
| Alias | Command | Description |
|
||||||
@@ -152,7 +128,7 @@ upgrades were available. Use `pacman -Que` instead.
|
|||||||
| trreps | `trizen -Ss` | Search for packages in the repositories |
|
| trreps | `trizen -Ss` | Search for packages in the repositories |
|
||||||
| trupd | `trizen -Sy` | Update and refresh local package, ABS and AUR databases |
|
| trupd | `trizen -Sy` | Update and refresh local package, ABS and AUR databases |
|
||||||
| trupg | `trizen -Syua` | Sync with repositories before upgrading all packages (from AUR too) |
|
| trupg | `trizen -Syua` | Sync with repositories before upgrading all packages (from AUR too) |
|
||||||
| trsu | `trizen -Syua --noconfirm` | Same as `trupg`, but without confirmation |
|
| trsu | `trizen -Syua --no-confirm` | Same as `trupg`, but without confirmation |
|
||||||
| upgrade[¹](#f1) | `trizen -Syu` | Sync with repositories before upgrading packages |
|
| upgrade[¹](#f1) | `trizen -Syu` | Sync with repositories before upgrading packages |
|
||||||
|
|
||||||
#### Yay
|
#### Yay
|
||||||
@@ -176,7 +152,7 @@ upgrades were available. Use `pacman -Que` instead.
|
|||||||
| yareps | `yay -Ss` | Search for packages in the repositories |
|
| yareps | `yay -Ss` | Search for packages in the repositories |
|
||||||
| yaupd | `yay -Sy` | Update and refresh local package, ABS and AUR databases |
|
| yaupd | `yay -Sy` | Update and refresh local package, ABS and AUR databases |
|
||||||
| yaupg | `yay -Syu` | Sync with repositories before upgrading packages |
|
| yaupg | `yay -Syu` | Sync with repositories before upgrading packages |
|
||||||
| yasu | `yay -Syu --noconfirm` | Same as `yaupg`, but without confirmation |
|
| yasu | `yay -Syu --no-confirm` | Same as `yaupg`, but without confirmation |
|
||||||
| upgrade[¹](#f1) | `yay -Syu` | Sync with repositories before upgrading packages |
|
| upgrade[¹](#f1) | `yay -Syu` | Sync with repositories before upgrading packages |
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -187,10 +163,9 @@ whether the package manager is installed, checked in the following order:
|
|||||||
|
|
||||||
1. `yay`
|
1. `yay`
|
||||||
2. `trizen`
|
2. `trizen`
|
||||||
3. `paru`
|
3. `pacaur`
|
||||||
4. `pacaur`
|
4. `aura`
|
||||||
5. `aura`
|
5. `pacman`
|
||||||
6. `pacman`
|
|
||||||
|
|
||||||
## Contributors
|
## Contributors
|
||||||
|
|
||||||
@@ -207,4 +182,3 @@ whether the package manager is installed, checked in the following order:
|
|||||||
- Jeff M. Hubbard - jeffmhubbard@gmail.com
|
- Jeff M. Hubbard - jeffmhubbard@gmail.com
|
||||||
- K. Harishankar(harishnkr) - hari2menon1234@gmail.com
|
- K. Harishankar(harishnkr) - hari2menon1234@gmail.com
|
||||||
- WH-2099 - wh2099@outlook.com
|
- WH-2099 - wh2099@outlook.com
|
||||||
- Boris Frenkel - fobos2k@gmail.com
|
|
||||||
@@ -134,27 +134,6 @@ if (( $+commands[pacaur] )); then
|
|||||||
alias paupd="pacaur -Sy"
|
alias paupd="pacaur -Sy"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if (( $+commands[paru] )); then
|
|
||||||
alias puclean='paru -Sc'
|
|
||||||
alias puclr='paru -Scc'
|
|
||||||
alias pufiles='paru -F'
|
|
||||||
alias puin='paru -S'
|
|
||||||
alias puins='paru -U'
|
|
||||||
alias puinsd='paru -S --asdeps'
|
|
||||||
alias puloc='paru -Qi'
|
|
||||||
alias pulocs='paru -Qs'
|
|
||||||
alias pulst='paru -Qe'
|
|
||||||
alias pumir='paru -Syy'
|
|
||||||
alias puorph='paru -Qtd'
|
|
||||||
alias pure='paru -R'
|
|
||||||
alias purem='paru -Rns'
|
|
||||||
alias purep='paru -Si'
|
|
||||||
alias pureps='paru -Ss'
|
|
||||||
alias puupd='paru -Sy'
|
|
||||||
alias puupg='paru -Syu'
|
|
||||||
alias pusu='paru -Syu --noconfirm'
|
|
||||||
fi
|
|
||||||
|
|
||||||
if (( $+commands[trizen] )); then
|
if (( $+commands[trizen] )); then
|
||||||
alias trconf='trizen -C'
|
alias trconf='trizen -C'
|
||||||
alias trupg='trizen -Syua'
|
alias trupg='trizen -Syua'
|
||||||
@@ -215,8 +194,6 @@ function upgrade() {
|
|||||||
yay -Su
|
yay -Su
|
||||||
elif (( $+commands[trizen] )); then
|
elif (( $+commands[trizen] )); then
|
||||||
trizen -Su
|
trizen -Su
|
||||||
elif (( $+commands[paru] )); then
|
|
||||||
paru -Su
|
|
||||||
elif (( $+commands[pacaur] )); then
|
elif (( $+commands[pacaur] )); then
|
||||||
pacaur -Su
|
pacaur -Su
|
||||||
elif (( $+commands[aura] )); then
|
elif (( $+commands[aura] )); then
|
||||||
|
|||||||
@@ -35,8 +35,7 @@ plugins=(... aws)
|
|||||||
|
|
||||||
* `aws_change_access_key`: changes the AWS access key of a profile.
|
* `aws_change_access_key`: changes the AWS access key of a profile.
|
||||||
|
|
||||||
* `aws_profiles`: lists the available profiles in the `$AWS_CONFIG_FILE` (default: `~/.aws/config`) and
|
* `aws_profiles`: lists the available profiles in the `$AWS_CONFIG_FILE` (default: `~/.aws/config`).
|
||||||
`$AWS_SHARED_CREDENTIALS_FILE` (default: `~/.aws/credentials`).
|
|
||||||
Used to provide completion for the `asp` function.
|
Used to provide completion for the `asp` function.
|
||||||
|
|
||||||
* `aws_regions`: lists the available regions.
|
* `aws_regions`: lists the available regions.
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ function asp() {
|
|||||||
export AWS_PROFILE=$1
|
export AWS_PROFILE=$1
|
||||||
export AWS_EB_PROFILE=$1
|
export AWS_EB_PROFILE=$1
|
||||||
|
|
||||||
export AWS_PROFILE_REGION=$(_aws_profile_region "$1")
|
export AWS_PROFILE_REGION=$(aws configure get region)
|
||||||
|
|
||||||
_aws_update_state
|
_aws_update_state
|
||||||
|
|
||||||
@@ -239,47 +239,9 @@ function aws_regions() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function aws_profiles() {
|
function aws_profiles() {
|
||||||
emulate -L zsh
|
aws --no-cli-pager configure list-profiles 2> /dev/null && return
|
||||||
local config="${AWS_CONFIG_FILE:-$HOME/.aws/config}"
|
[[ -r "${AWS_CONFIG_FILE:-$HOME/.aws/config}" ]] || return 1
|
||||||
local creds="${AWS_SHARED_CREDENTIALS_FILE:-$HOME/.aws/credentials}"
|
command grep -Eo '^[[:space:]]*\[[[:space:]]*(profile[[:space:]]+)?[^][:space:]]+[[:space:]]*\]' "${AWS_CONFIG_FILE:-$HOME/.aws/config}" | command sed -E 's/^[[:space:]]*\[[[:space:]]*(profile[[:space:]]+)?([^][:space:]]+)[[:space:]]*\]$/\2/'
|
||||||
# Read the files directly; the AWS CLI is slow to start
|
|
||||||
if [[ ! -r "$config" && ! -r "$creds" ]]; then
|
|
||||||
aws --no-cli-pager configure list-profiles 2> /dev/null
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
local line words
|
|
||||||
# Only read the section headers, so the credentials never enter the shell
|
|
||||||
for line in "${(@f)$(command grep -h '^[[:space:]]*\[' -- "$config" "$creds" 2> /dev/null)}"; do
|
|
||||||
line=${line#*\[} # drop up to the first [
|
|
||||||
line=${line%\]*} # drop from the last ] (comments, CR)
|
|
||||||
words=(${=line})
|
|
||||||
if (( $#words == 1 )); then
|
|
||||||
print -r -- $words[1] # [default], or [foo] in the credentials file
|
|
||||||
elif (( $#words == 2 )) && [[ $words[1] == profile ]]; then
|
|
||||||
print -r -- $words[2]
|
|
||||||
fi
|
|
||||||
done | command sort -u
|
|
||||||
}
|
|
||||||
|
|
||||||
# Read a profile's region from the config file, falling back to the AWS CLI
|
|
||||||
function _aws_profile_region() {
|
|
||||||
emulate -L zsh
|
|
||||||
local config="${AWS_CONFIG_FILE:-$HOME/.aws/config}" line words in_profile
|
|
||||||
if [[ -r "$config" ]]; then
|
|
||||||
# Only read headers and region lines, so any credentials never enter the shell
|
|
||||||
for line in "${(@f)$(command grep -e '\[' -e region -- "$config" 2> /dev/null)}"; do
|
|
||||||
line=${line%$'\r'}
|
|
||||||
words=(${=line//[\[\]=]/ }) # "[profile foo]" -> (profile foo), "region = x" -> (region x)
|
|
||||||
if [[ ${${=line}[1]} == \[* ]]; then # header, possibly indented
|
|
||||||
in_profile=
|
|
||||||
[[ "$words" == "profile $1" || ( $1 == default && "$words" == default ) ]] && in_profile=1
|
|
||||||
elif [[ -n $in_profile && $words[1] == region ]]; then
|
|
||||||
print -r -- $words[2]
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
aws configure get region
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _aws_regions() {
|
function _aws_regions() {
|
||||||
@@ -323,7 +285,7 @@ if [[ "$AWS_PROFILE_STATE_ENABLED" == true ]]; then
|
|||||||
export AWS_PROFILE="$AWS_DEFAULT_PROFILE"
|
export AWS_PROFILE="$AWS_DEFAULT_PROFILE"
|
||||||
export AWS_EB_PROFILE="$AWS_DEFAULT_PROFILE"
|
export AWS_EB_PROFILE="$AWS_DEFAULT_PROFILE"
|
||||||
|
|
||||||
test -z "${aws_state[2]}" && AWS_REGION=$(_aws_profile_region "$AWS_PROFILE")
|
test -z "${aws_state[2]}" && AWS_REGION=$(aws configure get region)
|
||||||
|
|
||||||
export AWS_REGION=${AWS_REGION:-$aws_state[2]}
|
export AWS_REGION=${AWS_REGION:-$aws_state[2]}
|
||||||
export AWS_DEFAULT_REGION="$AWS_REGION"
|
export AWS_DEFAULT_REGION="$AWS_REGION"
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
# Bitwarden plugin
|
|
||||||
|
|
||||||
This plugin adds Zsh completions for whichever Bitwarden CLIs are installed:
|
|
||||||
|
|
||||||
- [Bitwarden CLI (`bw`)](https://bitwarden.com/help/cli/)
|
|
||||||
- [Bitwarden Secrets Manager CLI (`bws`)](https://bitwarden.com/help/secrets-manager-cli/)
|
|
||||||
|
|
||||||
To enable it, add `bitwarden` to the plugins array in your `.zshrc`:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
plugins=(... bitwarden)
|
|
||||||
```
|
|
||||||
|
|
||||||
Each installed CLI generates and refreshes its own completion cache in the
|
|
||||||
background when the plugin loads. The cache files are
|
|
||||||
`$ZSH_CACHE_DIR/completions/_bw` and `$ZSH_CACHE_DIR/completions/_bws`.
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
# Autocompletion for the Bitwarden CLI (bw) and Secrets Manager CLI (bws).
|
|
||||||
() {
|
|
||||||
local cli completion cache_file
|
|
||||||
local -a generator_args
|
|
||||||
for cli in bw bws; do
|
|
||||||
completion="_$cli"
|
|
||||||
cache_file="$ZSH_CACHE_DIR/completions/$completion"
|
|
||||||
|
|
||||||
if (( ! $+commands[$cli] )); then
|
|
||||||
# compinit can register a cached completion after the CLI is removed.
|
|
||||||
if [[ -f "$cache_file" && ${_comps[$cli]-} == "$completion" ]]; then
|
|
||||||
unset "_comps[$cli]"
|
|
||||||
fi
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
case "$cli" in
|
|
||||||
bw)
|
|
||||||
generator_args=(completion --shell zsh)
|
|
||||||
# bw emits function definitions. Use ksh-style autoload to run _bw
|
|
||||||
# on the first Tab press as well as loading its helper functions.
|
|
||||||
autoload -Uk "$completion"
|
|
||||||
;;
|
|
||||||
bws)
|
|
||||||
generator_args=(completions zsh)
|
|
||||||
autoload -Uz "$completion"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
# Register the completion if compinit hasn't picked it up yet.
|
|
||||||
if [[ -z ${_comps[$cli]-} ]]; then
|
|
||||||
_comps[$cli]=$completion
|
|
||||||
fi
|
|
||||||
|
|
||||||
() {
|
|
||||||
zmodload -F zsh/files b:zf_mv || return
|
|
||||||
local temp_file
|
|
||||||
temp_file=$(mktemp "${cache_file:h}/.$completion.XXXXXXXX") || return
|
|
||||||
if command "$cli" "$@" >| "$temp_file" && [[ -s "$temp_file" ]] &&
|
|
||||||
zf_mv -f -- "$temp_file" "$cache_file"; then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
rm -f -- "$temp_file"
|
|
||||||
} "${generator_args[@]}" &|
|
|
||||||
done
|
|
||||||
}
|
|
||||||
@@ -59,7 +59,7 @@ ensures the `bdr` alias runs without warnings.
|
|||||||
| `bsra` | `bsr --all` | Run all stopped services. |
|
| `bsra` | `bsr --all` | Run all stopped services. |
|
||||||
| `bu` | `brew update` | Update brew and all installed formulae. |
|
| `bu` | `brew update` | Update brew and all installed formulae. |
|
||||||
| `bubo` | `brew update && brew outdated` | Update Homebrew data, then list outdated formulae and casks. |
|
| `bubo` | `brew update && brew outdated` | Update Homebrew data, then list outdated formulae and casks. |
|
||||||
| `bubu` | `bu && bup` | Update Homebrew data, then upgrade outdated, unpinned brews. |
|
| `bubu` | `bubo && bup` | Do the last two operations above. |
|
||||||
| `bugbc` | `brew upgrade --greedy && brew cleanup` | Upgrade outdated formulae and casks (greedy), then run cleanup. |
|
| `bugbc` | `brew upgrade --greedy && brew cleanup` | Upgrade outdated formulae and casks (greedy), then run cleanup. |
|
||||||
| `bup` | `brew upgrade` | Upgrade outdated, unpinned brews. |
|
| `bup` | `brew upgrade` | Upgrade outdated, unpinned brews. |
|
||||||
| `buz` | `brew uninstall --zap` | Remove all files associated with a cask. |
|
| `buz` | `brew uninstall --zap` | Remove all files associated with a cask. |
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ alias bsr='brew services run'
|
|||||||
alias bsra='bsr --all'
|
alias bsra='bsr --all'
|
||||||
alias bu='brew update'
|
alias bu='brew update'
|
||||||
alias bubo='brew update && brew outdated'
|
alias bubo='brew update && brew outdated'
|
||||||
alias bubu='bu && bup'
|
alias bubu='bubo && bup'
|
||||||
alias bubug='bubo && bugbc'
|
alias bubug='bubo && bugbc'
|
||||||
alias bugbc='brew upgrade --greedy && brew cleanup'
|
alias bugbc='brew upgrade --greedy && brew cleanup'
|
||||||
alias bup='brew upgrade'
|
alias bup='brew upgrade'
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Bridgetown plugin
|
# Bridgetown plugin
|
||||||
|
|
||||||
This plugin adds aliases for common [Bridgetown](https://www.bridgetownrb.com/) commands.
|
This plugin adds some aliases and autocompletion for common [Bridgetown](https://bridgetownrb.com/) commands.
|
||||||
|
|
||||||
To use it, add `bridgetown` to the plugins array in your zshrc file:
|
To use it, add `bridgetown` to the plugins array in your zshrc file:
|
||||||
|
|
||||||
@@ -10,27 +10,17 @@ plugins=(... bridgetown)
|
|||||||
|
|
||||||
## Aliases
|
## Aliases
|
||||||
|
|
||||||
Most aliases use the project's `bin/bridgetown` executable so the command runs with the Bridgetown version
|
| Alias | Command |
|
||||||
locked in its `Gemfile`. The `br` and `brn` aliases use the globally installed executable and can be run
|
|-------|----------------------------|
|
||||||
outside a Bridgetown project.
|
| br | `bridgetown` |
|
||||||
|
| bra | `bin/bridgetown apply` |
|
||||||
| Alias | Command | Description |
|
| brb | `bin/bridgetown build` |
|
||||||
| --------- | ---------------------------- | ---------------------------------------- |
|
| brc | `bin/bridgetown console` |
|
||||||
| `br` | `bridgetown` | Run the globally installed CLI |
|
| brclean | `bin/bridgetown clean` |
|
||||||
| `bra` | `bin/bridgetown apply` | Apply an automation |
|
| brd | `bin/bridgetown deploy` |
|
||||||
| `brb` | `bin/bridgetown build` | Build the site |
|
| brdoc | `bin/bridgetown doctor` |
|
||||||
| `brc` | `bin/bridgetown console` | Open the Bridgetown console |
|
| brh | `bin/bridgetown help` |
|
||||||
| `brclean` | `bin/bridgetown clean` | Remove generated files and caches |
|
| brn | `bridgetown new` |
|
||||||
| `brco` | `bin/bridgetown configure` | Apply a bundled configuration |
|
| brp | `bridgetown plugins` |
|
||||||
| `brd` | `bin/bridgetown deploy` | Run the project's deployment task |
|
| brpl | `bridgetown plugins list` |
|
||||||
| `brdev` | `bin/bridgetown dev` | Start the development server |
|
| brs | `bin/bridgetown start` |
|
||||||
| `bre` | `bin/bridgetown esbuild` | Manage the esbuild configuration |
|
|
||||||
| `brh` | `bin/bridgetown help` | Show command help |
|
|
||||||
| `brn` | `bridgetown new` | Create a new Bridgetown site |
|
|
||||||
| `brp` | `bin/bridgetown plugins` | Access plugin commands |
|
|
||||||
| `brpl` | `bin/bridgetown plugins list` | List installed plugins |
|
|
||||||
| `brs` | `bin/bridgetown start` | Start the development server |
|
|
||||||
| `brt` | `bin/bridgetown test` | Run the project's test build task |
|
|
||||||
|
|
||||||
`deploy` and `test` are standard tasks from the `Rakefile` generated for a new Bridgetown site. If the project
|
|
||||||
customizes or removes those tasks, the corresponding aliases follow that project behavior.
|
|
||||||
@@ -3,13 +3,10 @@ alias bra='bin/bridgetown apply'
|
|||||||
alias brb='bin/bridgetown build'
|
alias brb='bin/bridgetown build'
|
||||||
alias brc='bin/bridgetown console'
|
alias brc='bin/bridgetown console'
|
||||||
alias brclean='bin/bridgetown clean'
|
alias brclean='bin/bridgetown clean'
|
||||||
alias brco='bin/bridgetown configure'
|
|
||||||
alias brd='bin/bridgetown deploy'
|
alias brd='bin/bridgetown deploy'
|
||||||
alias brdev='bin/bridgetown dev'
|
alias brdoc='bin/bridgetown doctor'
|
||||||
alias bre='bin/bridgetown esbuild'
|
|
||||||
alias brh='bin/bridgetown help'
|
alias brh='bin/bridgetown help'
|
||||||
alias brn='bridgetown new'
|
alias brn='bridgetown new'
|
||||||
alias brp='bin/bridgetown plugins'
|
alias brp='bridgetown plugins'
|
||||||
alias brpl='bin/bridgetown plugins list'
|
alias brpl='bridgetown plugins list'
|
||||||
alias brs='bin/bridgetown start'
|
alias brs='bin/bridgetown start'
|
||||||
alias brt='bin/bridgetown test'
|
|
||||||
@@ -90,7 +90,6 @@ colorize_less() {
|
|||||||
# (e.g. when not scrolled to the bottom) while already the next file will be displayed.
|
# (e.g. when not scrolled to the bottom) while already the next file will be displayed.
|
||||||
local LESSOPEN="| zsh -c 'source \"$ZSH_COLORIZE_PLUGIN_PATH\"; \
|
local LESSOPEN="| zsh -c 'source \"$ZSH_COLORIZE_PLUGIN_PATH\"; \
|
||||||
ZSH_COLORIZE_TOOL=$ZSH_COLORIZE_TOOL ZSH_COLORIZE_STYLE=$ZSH_COLORIZE_STYLE \
|
ZSH_COLORIZE_TOOL=$ZSH_COLORIZE_TOOL ZSH_COLORIZE_STYLE=$ZSH_COLORIZE_STYLE \
|
||||||
ZSH_COLORIZE_CHROMA_FORMATTER=$ZSH_COLORIZE_CHROMA_FORMATTER \
|
|
||||||
colorize_cat %s 2> /dev/null'"
|
colorize_cat %s 2> /dev/null'"
|
||||||
|
|
||||||
# LESSCLOSE will be set to prevent any errors by executing a user script
|
# LESSCLOSE will be set to prevent any errors by executing a user script
|
||||||
|
|||||||
+3
-11
@@ -1,6 +1,6 @@
|
|||||||
# conda plugin
|
# conda plugin
|
||||||
|
|
||||||
The conda plugin provides [aliases](#aliases) and [completion](#completion) for `conda`, usually installed via [anaconda](https://www.anaconda.com/) or [miniconda](https://docs.conda.io/en/latest/miniconda.html).
|
The conda plugin provides [aliases](#aliases) for `conda`, usually installed via [anaconda](https://www.anaconda.com/) or [miniconda](https://docs.conda.io/en/latest/miniconda.html).
|
||||||
|
|
||||||
To use it, add `conda` to the plugins array in your zshrc file:
|
To use it, add `conda` to the plugins array in your zshrc file:
|
||||||
|
|
||||||
@@ -28,18 +28,10 @@ plugins=(... conda)
|
|||||||
| `cnle` | `conda list --export` | Export the list of installed packages in the current environment |
|
| `cnle` | `conda list --export` | Export the list of installed packages in the current environment |
|
||||||
| `cnles` | `conda list --explicit > spec-file.txt` | Export the list of installed packages in the current environment to a spec file |
|
| `cnles` | `conda list --explicit > spec-file.txt` | Export the list of installed packages in the current environment to a spec file |
|
||||||
| `cnr` | `conda remove` | Remove given package |
|
| `cnr` | `conda remove` | Remove given package |
|
||||||
| `cnrn` | `conda remove -y --all -n` | Remove all packages in the specified environment |
|
| `cnrn` | `conda remove -y -all -n` | Remove all packages in the specified environment |
|
||||||
| `cnrp` | `conda remove -y --all -p` | Remove all packages in the specified prefix |
|
| `cnrp` | `conda remove -y -all -p` | Remove all packages in the specified prefix |
|
||||||
| `cnry` | `conda remove -y` | Remove given package without confirmation |
|
| `cnry` | `conda remove -y` | Remove given package without confirmation |
|
||||||
| `cnsr` | `conda search` | Search conda repositories for package |
|
| `cnsr` | `conda search` | Search conda repositories for package |
|
||||||
| `cnu` | `conda update` | Update conda package manager |
|
| `cnu` | `conda update` | Update conda package manager |
|
||||||
| `cnua` | `conda update --all` | Update all installed packages |
|
| `cnua` | `conda update --all` | Update all installed packages |
|
||||||
| `cnuc` | `conda update conda` | Update conda package manager |
|
| `cnuc` | `conda update conda` | Update conda package manager |
|
||||||
|
|
||||||
## Completion
|
|
||||||
|
|
||||||
Tab completion is available for the following commands, using the environment list conda keeps in
|
|
||||||
`~/.conda/environments.txt`:
|
|
||||||
|
|
||||||
- `cna`: completes environment names for `conda activate`
|
|
||||||
- `cnrn`: completes environment names for `conda remove -y --all -n`
|
|
||||||
@@ -1,7 +1,4 @@
|
|||||||
unalias cna cnrn 2>/dev/null
|
alias cna='conda activate'
|
||||||
cna() { conda activate "$@"; }
|
|
||||||
cnrn() { conda remove -y --all -n "$@"; }
|
|
||||||
|
|
||||||
alias cnab='conda activate base'
|
alias cnab='conda activate base'
|
||||||
alias cncf='conda env create -f'
|
alias cncf='conda env create -f'
|
||||||
alias cncn='conda create -y -n'
|
alias cncn='conda create -y -n'
|
||||||
@@ -17,26 +14,10 @@ alias cnl='conda list'
|
|||||||
alias cnle='conda list --export'
|
alias cnle='conda list --export'
|
||||||
alias cnles='conda list --explicit > spec-file.txt'
|
alias cnles='conda list --explicit > spec-file.txt'
|
||||||
alias cnr='conda remove'
|
alias cnr='conda remove'
|
||||||
|
alias cnrn='conda remove -y --all -n'
|
||||||
alias cnrp='conda remove -y --all -p'
|
alias cnrp='conda remove -y --all -p'
|
||||||
alias cnry='conda remove -y'
|
alias cnry='conda remove -y'
|
||||||
alias cnsr='conda search'
|
alias cnsr='conda search'
|
||||||
alias cnu='conda update'
|
alias cnu='conda update'
|
||||||
alias cnua='conda update --all'
|
alias cnua='conda update --all'
|
||||||
alias cnuc='conda update conda'
|
alias cnuc='conda update conda'
|
||||||
|
|
||||||
_omz_conda_envs() {
|
|
||||||
emulate -L zsh -o extended_glob
|
|
||||||
local envs_file="$HOME/.conda/environments.txt"
|
|
||||||
[[ -r "$envs_file" ]] || return 1
|
|
||||||
|
|
||||||
# Each line is an env prefix; named envs live under <dir>/envs/<name>.
|
|
||||||
# The root prefix (base) and envs created with -p have no name and are skipped.
|
|
||||||
local -aU envs
|
|
||||||
envs=(${(f)"$(<$envs_file)"})
|
|
||||||
envs=(${${(M)envs:#*/envs/[^/]##}:t})
|
|
||||||
(( ${#envs} )) && compadd -Q -a envs
|
|
||||||
}
|
|
||||||
|
|
||||||
if (( $+functions[compdef] )); then
|
|
||||||
compdef _omz_conda_envs cna cnrn
|
|
||||||
fi
|
|
||||||
@@ -14,6 +14,6 @@ function copyfile {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
clipcopy $1 || return 1
|
clipcopy $1
|
||||||
echo ${(%):-"%B$1%b copied to clipboard."}
|
echo ${(%):-"%B$1%b copied to clipboard."}
|
||||||
}
|
}
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
#!/usr/bin/env zsh
|
|
||||||
|
|
||||||
emulate -LR zsh
|
|
||||||
|
|
||||||
source "${1:-${0:A:h:h}/copyfile.plugin.zsh}"
|
|
||||||
|
|
||||||
test_dir=$(mktemp -d) || exit 1
|
|
||||||
trap 'command rm -rf -- "$test_dir"' EXIT
|
|
||||||
|
|
||||||
typeset -i clipboard_status=0 failures=0 tests=0
|
|
||||||
typeset output expected_output
|
|
||||||
|
|
||||||
clipcopy() {
|
|
||||||
print -r -- "$#" "$1" >| "$test_dir/call"
|
|
||||||
if (( clipboard_status )); then
|
|
||||||
print -u2 -r -- "clipboard backend failed"
|
|
||||||
return $clipboard_status
|
|
||||||
fi
|
|
||||||
command cat -- "$1" >| "$test_dir/clipboard"
|
|
||||||
}
|
|
||||||
|
|
||||||
check_copyfile() {
|
|
||||||
local description="$1" expected_status="$2" expected_stdout="$3" expected_stderr="$4"
|
|
||||||
shift 4
|
|
||||||
|
|
||||||
output=$(copyfile "$@" 2> "$test_dir/stderr")
|
|
||||||
local actual_status=$?
|
|
||||||
(( tests++ ))
|
|
||||||
|
|
||||||
if [[ $actual_status == $expected_status && $output == "$expected_stdout" && $(<"$test_dir/stderr") == "$expected_stderr" ]]; then
|
|
||||||
print -r -- "PASS: $description"
|
|
||||||
else
|
|
||||||
print -u2 -r -- "FAIL: $description"
|
|
||||||
print -u2 -r -- " status: $actual_status (expected $expected_status)"
|
|
||||||
print -u2 -r -- " stdout: ${(qqq)output} (expected ${(qqq)expected_stdout})"
|
|
||||||
print -u2 -r -- " stderr: $(<"$test_dir/stderr") (expected $expected_stderr)"
|
|
||||||
(( failures++ ))
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
for filename in plain.txt 'file with spaces.txt' 'unicode-ą.txt' empty.txt; do
|
|
||||||
if [[ $filename == empty.txt ]]; then
|
|
||||||
: >| "$test_dir/$filename"
|
|
||||||
else
|
|
||||||
print -r -- "contents of $filename" >| "$test_dir/$filename"
|
|
||||||
fi
|
|
||||||
|
|
||||||
expected_output=${(%):-"%B$test_dir/$filename%b copied to clipboard."}
|
|
||||||
clipboard_status=0
|
|
||||||
check_copyfile "successful copy of $filename" 0 "$expected_output" '' "$test_dir/$filename"
|
|
||||||
|
|
||||||
if [[ $(<"$test_dir/call") != "1 $test_dir/$filename" ]] || ! command cmp -s -- "$test_dir/$filename" "$test_dir/clipboard"; then
|
|
||||||
print -u2 -r -- "FAIL: clipboard received a different argument or contents for $filename"
|
|
||||||
(( failures++ ))
|
|
||||||
fi
|
|
||||||
|
|
||||||
for clipboard_status in 1 42 127; do
|
|
||||||
check_copyfile "clipboard exit $clipboard_status for $filename" 1 '' 'clipboard backend failed' "$test_dir/$filename"
|
|
||||||
done
|
|
||||||
done
|
|
||||||
|
|
||||||
command rm -f -- "$test_dir/call"
|
|
||||||
check_copyfile 'missing argument' 1 'Usage: copyfile <file>' ''
|
|
||||||
check_copyfile 'empty argument' 1 'Usage: copyfile <file>' '' ''
|
|
||||||
check_copyfile 'nonexistent file' 1 "Error: '$test_dir/missing.txt' is not a valid file." '' "$test_dir/missing.txt"
|
|
||||||
check_copyfile 'directory argument' 1 "Error: '$test_dir' is not a valid file." '' "$test_dir"
|
|
||||||
|
|
||||||
if [[ -e "$test_dir/call" ]]; then
|
|
||||||
print -u2 -r -- 'FAIL: invalid input invoked the clipboard backend'
|
|
||||||
(( failures++ ))
|
|
||||||
fi
|
|
||||||
|
|
||||||
print -r -- "$tests tests, $failures failures"
|
|
||||||
(( failures == 0 ))
|
|
||||||
@@ -52,7 +52,7 @@ function push_future() {
|
|||||||
if [[ $#dirhistory_future -ge $DIRHISTORY_SIZE ]]; then
|
if [[ $#dirhistory_future -ge $DIRHISTORY_SIZE ]]; then
|
||||||
shift dirhistory_future
|
shift dirhistory_future
|
||||||
fi
|
fi
|
||||||
if [[ $#dirhistory_future -eq 0 || $dirhistory_future[$#dirhistory_future] != "$1" ]]; then
|
if [[ $#dirhistory_future -eq 0 || $dirhistory_futuret[$#dirhistory_future] != "$1" ]]; then
|
||||||
dirhistory_future+=($1)
|
dirhistory_future+=($1)
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ plugins=(... docker-compose)
|
|||||||
## Aliases
|
## Aliases
|
||||||
|
|
||||||
| Alias | Command | Description |
|
| Alias | Command | Description |
|
||||||
|-----------|-------------------------------------|----------------------------------------------------------------------------------------------|
|
|-----------|----------------------------------|----------------------------------------------------------------------------------|
|
||||||
| dco | `docker-compose` | Docker-compose main command |
|
| dco | `docker-compose` | Docker-compose main command |
|
||||||
| dcb | `docker-compose build` | Build containers |
|
| dcb | `docker-compose build` | Build containers |
|
||||||
| dcc | `docker-compose config` | Parse, resolve and render compose file in canonical format |
|
| dcc | `docker-compose config` | Parse, resolve and render compose file in canonical format |
|
||||||
@@ -28,8 +28,6 @@ plugins=(... docker-compose)
|
|||||||
| dcupb | `docker-compose up --build` | Same as `dcup`, but build images before starting containers |
|
| 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 |
|
| 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 |
|
| dcupdb | `docker-compose up -d --build` | Same as `dcup`, but build images before starting containers and starts as daemon |
|
||||||
| dcupw | `docker-compose up --watch` | Watch changes in service and rebuild/restart accordingly (see [Use Compose Watch] for usage) |
|
|
||||||
| dcupwb | `docker-compose up --watch --build` | Same as `dcupw`, but build images before starting containers |
|
|
||||||
| dcdn | `docker-compose down` | Stop and remove containers |
|
| dcdn | `docker-compose down` | Stop and remove containers |
|
||||||
| dcl | `docker-compose logs` | Show logs of container |
|
| dcl | `docker-compose logs` | Show logs of container |
|
||||||
| dclf | `docker-compose logs -f` | Show logs and follow output |
|
| dclf | `docker-compose logs -f` | Show logs and follow output |
|
||||||
@@ -40,5 +38,3 @@ plugins=(... docker-compose)
|
|||||||
| dcv | `docker-compose version` | Show version information |
|
| dcv | `docker-compose version` | Show version information |
|
||||||
| dcsts | `docker-compose stats` | Show stats of containers |
|
| dcsts | `docker-compose stats` | Show stats of containers |
|
||||||
| dci | `docker-compose images` | List images |
|
| dci | `docker-compose images` | List images |
|
||||||
|
|
||||||
[Use Compose Watch]: https://docs.docker.com/compose/how-tos/file-watch/
|
|
||||||
@@ -17,8 +17,6 @@ alias dcup="$dccmd up"
|
|||||||
alias dcupb="$dccmd up --build"
|
alias dcupb="$dccmd up --build"
|
||||||
alias dcupd="$dccmd up -d"
|
alias dcupd="$dccmd up -d"
|
||||||
alias dcupdb="$dccmd up -d --build"
|
alias dcupdb="$dccmd up -d --build"
|
||||||
alias dcupw="$dccmd up --watch"
|
|
||||||
alias dcupwb="$dccmd up --watch --build"
|
|
||||||
alias dcdn="$dccmd down"
|
alias dcdn="$dccmd down"
|
||||||
alias dcl="$dccmd logs"
|
alias dcl="$dccmd logs"
|
||||||
alias dclf="$dccmd logs -f"
|
alias dclf="$dccmd logs -f"
|
||||||
|
|||||||
@@ -84,7 +84,6 @@ If you use Podman's Docker wrapper, you need to enable legacy completion. See ab
|
|||||||
| dtop | `docker top` | Display the running processes of a container |
|
| dtop | `docker top` | Display the running processes of a container |
|
||||||
| dvi | `docker volume inspect` | Display detailed information about one or more volumes |
|
| dvi | `docker volume inspect` | Display detailed information about one or more volumes |
|
||||||
| dvls | `docker volume ls` | List all the volumes known to docker |
|
| dvls | `docker volume ls` | List all the volumes known to docker |
|
||||||
| dvrm | `docker volume rm` | Remove one or more volumes |
|
|
||||||
| dvprune | `docker volume prune` | Cleanup dangling volumes |
|
| dvprune | `docker volume prune` | Cleanup dangling volumes |
|
||||||
| dxc | `docker container exec` | Run a new command in a running container |
|
| dxc | `docker container exec` | Run a new command in a running container |
|
||||||
| dxcit | `docker container exec -it` | Run a new command in a running container in an interactive shell |
|
| dxcit | `docker container exec -it` | Run a new command in a running container in an interactive shell |
|
||||||
@@ -35,7 +35,6 @@ alias dsts='docker stats'
|
|||||||
alias dtop='docker top'
|
alias dtop='docker top'
|
||||||
alias dvi='docker volume inspect'
|
alias dvi='docker volume inspect'
|
||||||
alias dvls='docker volume ls'
|
alias dvls='docker volume ls'
|
||||||
alias dvrm='docker volume rm'
|
|
||||||
alias dvprune='docker volume prune'
|
alias dvprune='docker volume prune'
|
||||||
alias dxc='docker container exec'
|
alias dxc='docker container exec'
|
||||||
alias dxcit='docker container exec -it'
|
alias dxcit='docker container exec -it'
|
||||||
@@ -49,11 +48,6 @@ fi
|
|||||||
0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
|
0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
|
||||||
0="${${(M)0:#/*}:-$PWD/$0}"
|
0="${${(M)0:#/*}:-$PWD/$0}"
|
||||||
|
|
||||||
# Make sure the cache directory exists; when the plugin is loaded by a
|
|
||||||
# standalone plugin manager (e.g. antigen) the core is not sourced, so
|
|
||||||
# $ZSH_CACHE_DIR/completions may not have been created yet (#13679).
|
|
||||||
[[ -d "$ZSH_CACHE_DIR/completions" ]] || mkdir -p "$ZSH_CACHE_DIR/completions"
|
|
||||||
|
|
||||||
# If the completion file doesn't exist yet, we need to autoload it and
|
# 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.
|
# bind it to `docker`. Otherwise, compinit will have already done that.
|
||||||
if [[ ! -f "$ZSH_CACHE_DIR/completions/_docker" ]]; then
|
if [[ ! -f "$ZSH_CACHE_DIR/completions/_docker" ]]; then
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ takes preference, _i.e._ the .env file will never be sourced.
|
|||||||
## Named Pipe (FIFO) Support
|
## Named Pipe (FIFO) Support
|
||||||
|
|
||||||
The plugin supports `.env` files provided as UNIX named pipes (FIFOs) in addition to regular files.
|
The plugin supports `.env` files provided as UNIX named pipes (FIFOs) in addition to regular files.
|
||||||
This is useful when secrets managers like [1Password Environments](https://developer.1password.com/docs/environments/)
|
This is useful when secrets managers like [1Password Environments](https://developer.1password.com/docs/environment/)
|
||||||
mount `.env` files as named pipes to inject secrets on-the-fly without writing them to disk.
|
mount `.env` files as named pipes to inject secrets on-the-fly without writing them to disk.
|
||||||
|
|
||||||
No additional configuration is required — the plugin automatically detects and sources named pipes.
|
No additional configuration is required — the plugin automatically detects and sources named pipes.
|
||||||
|
|||||||
@@ -263,9 +263,9 @@ _dotenv_check_syntax() {
|
|||||||
local filename="$1"
|
local filename="$1"
|
||||||
|
|
||||||
if (( $# == 2 )); then
|
if (( $# == 2 )); then
|
||||||
printf '%s' "$2" | command zsh -fn /dev/stdin
|
printf '%s' "$2" | zsh -fn /dev/stdin
|
||||||
else
|
else
|
||||||
command zsh -fn -- "$filename"
|
zsh -fn -- "$filename"
|
||||||
fi || {
|
fi || {
|
||||||
echo "dotenv: error when sourcing '$filename' file" >&2
|
echo "dotenv: error when sourcing '$filename' file" >&2
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ plugins=(... drush)
|
|||||||
| `drcr` | `drush core-cron` | Run all cron hooks in all active modules for specified site |
|
| `drcr` | `drush core-cron` | Run all cron hooks in all active modules for specified site |
|
||||||
| `drct` | `drush cc theme-registry` | Clear theme-registry cache |
|
| `drct` | `drush cc theme-registry` | Clear theme-registry cache |
|
||||||
| `drcv` | `drush cc views` | Clear views cache _(make sure that the views module is enabled)_ |
|
| `drcv` | `drush cc views` | Clear views cache _(make sure that the views module is enabled)_ |
|
||||||
| `drdmp` | `drush sql-dump --ordered-dump --result-file=dump.sql` | Backup database in a new dump.sql file |
|
| `drdmp` | `drush drush sql-dump --ordered-dump --result-file=dumpsql` | Backup database in a new dump.sql file |
|
||||||
| `drf` | `drush features` | Display features status |
|
| `drf` | `drush features` | Display features status |
|
||||||
| `drfr` | `drush features-revert -y` | Revert a feature module on your site |
|
| `drfr` | `drush features-revert -y` | Revert a feature module on your site |
|
||||||
| `drfra` | `drush features-revert-all` | Revert all enabled feature module on your site |
|
| `drfra` | `drush features-revert-all` | Revert all enabled feature module on your site |
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ case $state in
|
|||||||
'new' \
|
'new' \
|
||||||
'serve' \
|
'serve' \
|
||||||
'test' \
|
'test' \
|
||||||
'version' && ret=0
|
'vesion' && ret=0
|
||||||
;;
|
;;
|
||||||
addon)
|
addon)
|
||||||
_arguments \
|
_arguments \
|
||||||
|
|||||||
@@ -46,10 +46,10 @@ Encode a file's contents to base64 and save output to text file.
|
|||||||
- From parameter
|
- From parameter
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ encodefile64 oh-my-zsh
|
$ encodefile64 ohmyzsh.icn
|
||||||
oh-my-zsh's content encoded in base64 and saved as oh-my-zsh.txt
|
ohmyzsh.icn's content encoded in base64 and saved as ohmyzsh.icn.txt
|
||||||
$ ef64 "oh-my-zsh"
|
$ ef64 "oh-my-zsh"
|
||||||
oh-my-zsh's content encoded in base64 and saved as oh-my-zsh.txt
|
ohmyzsh.icn's content encoded in base64 and saved as ohmyzsh.icn.txt
|
||||||
```
|
```
|
||||||
|
|
||||||
### Decoding
|
### Decoding
|
||||||
|
|||||||
@@ -2,37 +2,24 @@ encode64() {
|
|||||||
if [[ $# -eq 0 ]]; then
|
if [[ $# -eq 0 ]]; then
|
||||||
cat | base64
|
cat | base64
|
||||||
else
|
else
|
||||||
printf '%s' "$1" | base64
|
printf '%s' $1 | base64
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
encodefile64() {
|
encodefile64() {
|
||||||
if [[ $# -ne 1 || ! -f "$1" || ! -r "$1" ]]; then
|
if [[ $# -eq 0 ]]; then
|
||||||
print -u2 -- 'Usage: encodefile64 <file>'
|
echo "You must provide a filename"
|
||||||
return 1
|
else
|
||||||
|
base64 $1 > $1.txt
|
||||||
|
echo "${1}'s content encoded in base64 and saved as ${1}.txt"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local file="$1" output="${1}.txt" tmp_file
|
|
||||||
[[ $output == /* ]] || output="./$output"
|
|
||||||
|
|
||||||
tmp_file=$(mktemp "${output}.XXXXXX") || return 1
|
|
||||||
if ! base64 < "$file" > "$tmp_file"; then
|
|
||||||
command rm -f "$tmp_file"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
if ! command mv "$tmp_file" "$output"; then
|
|
||||||
command rm -f "$tmp_file"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
print -- "$file's content encoded in base64 and saved as ${file}.txt"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
decode64() {
|
decode64() {
|
||||||
if [[ $# -eq 0 ]]; then
|
if [[ $# -eq 0 ]]; then
|
||||||
cat | base64 -d
|
cat | base64 --decode
|
||||||
else
|
else
|
||||||
printf '%s' "$1" | base64 -d
|
printf '%s' $1 | base64 --decode
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
alias e64=encode64
|
alias e64=encode64
|
||||||
|
|||||||
@@ -1,77 +0,0 @@
|
|||||||
#!/usr/bin/env zsh
|
|
||||||
|
|
||||||
emulate -LR zsh
|
|
||||||
|
|
||||||
source "${1:-${0:A:h:h}/encode64.plugin.zsh}"
|
|
||||||
|
|
||||||
test_dir=$(mktemp -d) || exit 1
|
|
||||||
trap 'command rm -rf -- "$test_dir"' EXIT
|
|
||||||
cd "$test_dir" || exit 1
|
|
||||||
|
|
||||||
typeset -i failures=0 tests=0
|
|
||||||
typeset output expected_output
|
|
||||||
|
|
||||||
check_result() {
|
|
||||||
local description="$1" expected_status="$2" expected_stdout="$3" expected_stderr="$4"
|
|
||||||
shift 4
|
|
||||||
|
|
||||||
output=$("$@" 2> "$test_dir/stderr")
|
|
||||||
local actual_status=$?
|
|
||||||
(( tests++ ))
|
|
||||||
|
|
||||||
if [[ $actual_status == $expected_status && $output == "$expected_stdout" && $(<"$test_dir/stderr") == "$expected_stderr" ]]; then
|
|
||||||
print -r -- "PASS: $description"
|
|
||||||
else
|
|
||||||
print -u2 -r -- "FAIL: $description"
|
|
||||||
print -u2 -r -- " status: $actual_status (expected $expected_status)"
|
|
||||||
print -u2 -r -- " stdout: ${(qqq)output} (expected ${(qqq)expected_stdout})"
|
|
||||||
print -u2 -r -- " stderr: $(<"$test_dir/stderr") (expected $expected_stderr)"
|
|
||||||
(( failures++ ))
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
check_encode_arg() { encode64 'oh-my-zsh'; }
|
|
||||||
check_encode_empty() { encode64 ''; }
|
|
||||||
check_decode_arg() { decode64 'b2gtbXktenNo'; }
|
|
||||||
|
|
||||||
expected_output=$(printf '%s' 'oh-my-zsh' | base64)
|
|
||||||
check_result 'encode argument' 0 "$expected_output" '' check_encode_arg
|
|
||||||
check_result 'encode empty argument' 0 '' '' check_encode_empty
|
|
||||||
check_result 'decode argument' 0 'oh-my-zsh' '' check_decode_arg
|
|
||||||
|
|
||||||
file="$test_dir/file with spaces.txt"
|
|
||||||
print -r -- 'file contents' >| "$file"
|
|
||||||
encodefile64 "$file" > "$test_dir/stdout" 2> "$test_dir/stderr"
|
|
||||||
file_status=$?
|
|
||||||
expected_output=$(base64 < "$file")
|
|
||||||
(( tests++ ))
|
|
||||||
if [[ $file_status == 0 && $(<"${file}.txt") == "$expected_output" && $(<"$test_dir/stdout") == "$file's content encoded in base64 and saved as ${file}.txt" && ! -s "$test_dir/stderr" ]]; then
|
|
||||||
print -r -- 'PASS: encode file with spaces'
|
|
||||||
else
|
|
||||||
print -u2 -r -- 'FAIL: encode file with spaces'
|
|
||||||
(( failures++ ))
|
|
||||||
fi
|
|
||||||
|
|
||||||
check_invalid_file() { encodefile64 ''; }
|
|
||||||
check_result 'empty filename' 1 '' 'Usage: encodefile64 <file>' check_invalid_file
|
|
||||||
if [[ -e .txt ]]; then
|
|
||||||
print -u2 -r -- 'FAIL: empty filename created .txt'
|
|
||||||
(( failures++ ))
|
|
||||||
command rm -f .txt
|
|
||||||
fi
|
|
||||||
|
|
||||||
print -r -- 'preserve existing output' >| "${file}.txt"
|
|
||||||
base64() { return 42; }
|
|
||||||
encodefile64 "$file" > "$test_dir/stdout" 2> "$test_dir/stderr"
|
|
||||||
file_status=$?
|
|
||||||
unset -f base64
|
|
||||||
(( tests++ ))
|
|
||||||
if [[ $file_status != 0 && $(<"${file}.txt") == 'preserve existing output' && ! -s "$test_dir/stdout" ]]; then
|
|
||||||
print -r -- 'PASS: failed encoding preserves existing output'
|
|
||||||
else
|
|
||||||
print -u2 -r -- 'FAIL: failed encoding preserves existing output'
|
|
||||||
(( failures++ ))
|
|
||||||
fi
|
|
||||||
|
|
||||||
print -r -- "$tests tests, $failures failures"
|
|
||||||
(( failures == 0 ))
|
|
||||||
@@ -45,12 +45,9 @@ plugins=(... extract)
|
|||||||
| `tar.lrz` | Tarball with lrzip compression |
|
| `tar.lrz` | Tarball with lrzip compression |
|
||||||
| `tar.lz` | Tarball with lzip compression |
|
| `tar.lz` | Tarball with lzip compression |
|
||||||
| `tar.lz4` | Tarball with lz4 compression |
|
| `tar.lz4` | Tarball with lz4 compression |
|
||||||
| `tar.lzma` | Tarball with lzma compression |
|
|
||||||
| `tar.xz` | Tarball with lzma2 compression |
|
| `tar.xz` | Tarball with lzma2 compression |
|
||||||
| `tar.zma` | Tarball with lzma compression |
|
| `tar.zma` | Tarball with lzma compression |
|
||||||
| `tar.zst` | Tarball with zstd compression |
|
| `tar.zst` | Tarball with zstd compression |
|
||||||
| `tar.Z` | Tarball with compress (LZW) compression |
|
|
||||||
| `taz` | Tarball with compress (LZW) compression |
|
|
||||||
| `tbz` | Tarball with bzip compression |
|
| `tbz` | Tarball with bzip compression |
|
||||||
| `tbz2` | Tarball with bzip2 compression |
|
| `tbz2` | Tarball with bzip2 compression |
|
||||||
| `tgz` | Tarball with gzip compression |
|
| `tgz` | Tarball with gzip compression |
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ local -a exts=(
|
|||||||
tar.lrz
|
tar.lrz
|
||||||
tar.lz
|
tar.lz
|
||||||
tar.lz4
|
tar.lz4
|
||||||
tar.lzma
|
|
||||||
tar.xz
|
tar.xz
|
||||||
tar.zma
|
tar.zma
|
||||||
tar.zst
|
tar.zst
|
||||||
|
|||||||
Regular → Executable
+7
-45
@@ -88,7 +88,7 @@ EOF
|
|||||||
tar --xz --help &> /dev/null \
|
tar --xz --help &> /dev/null \
|
||||||
&& tar --xz -xvf "$full_path" \
|
&& tar --xz -xvf "$full_path" \
|
||||||
|| xzcat "$full_path" | tar xvf - } ;;
|
|| xzcat "$full_path" | tar xvf - } ;;
|
||||||
(*.tar.lzma|*.tar.zma|*.tlz)
|
(*.tar.zma|*.tlz)
|
||||||
tar --lzma --help &> /dev/null \
|
tar --lzma --help &> /dev/null \
|
||||||
&& tar --lzma -xvf "$full_path" \
|
&& tar --lzma -xvf "$full_path" \
|
||||||
|| lzcat "$full_path" | tar xvf - ;;
|
|| lzcat "$full_path" | tar xvf - ;;
|
||||||
@@ -97,23 +97,16 @@ EOF
|
|||||||
&& tar --zstd -xvf "$full_path" \
|
&& tar --zstd -xvf "$full_path" \
|
||||||
|| zstdcat "$full_path" | tar xvf - ;;
|
|| zstdcat "$full_path" | tar xvf - ;;
|
||||||
(*.tar) tar xvf "$full_path" ;;
|
(*.tar) tar xvf "$full_path" ;;
|
||||||
# `tar cf - dir | compress > dir.tar.Z`: the plain `.Z` arm below only decompresses the
|
|
||||||
# stream back to `dir.tar`, so the combined form has to untar it in one step. `.taz` is the
|
|
||||||
# historic name for the same file, next to `.tgz`/`.tbz`/`.tlz`/`.txz`/`.tzst`. Matching is
|
|
||||||
# on the lowercased name, so `.tar.Z` lands here too.
|
|
||||||
(*.tar.z|*.taz) uncompress -c "$full_path" | tar xvf - ;;
|
|
||||||
(*.tar.lz) (( $+commands[lzip] )) && tar xvf "$full_path" ;;
|
(*.tar.lz) (( $+commands[lzip] )) && tar xvf "$full_path" ;;
|
||||||
(*.tar.lz4) lz4 -c -d "$full_path" | tar xvf - ;;
|
(*.tar.lz4) lz4 -c -d "$full_path" | tar xvf - ;;
|
||||||
(*.tar.lrz) (( $+commands[lrzuntar] )) && lrzuntar "$full_path" ;;
|
(*.tar.lrz) (( $+commands[lrzuntar] )) && lrzuntar "$full_path" ;;
|
||||||
(*.gz) (( $+commands[pigz] )) && pigz -cdk "$full_path" > "${file:t:r}" || gunzip -ck "$full_path" > "${file:t:r}" ;;
|
(*.gz) (( $+commands[pigz] )) && pigz -cdk "$full_path" > "${file:t:r}" || gunzip -ck "$full_path" > "${file:t:r}" ;;
|
||||||
(*.bz2)
|
(*.bz2) (( $+commands[pbzip2] )) && pbzip2 -d "$full_path" || bunzip2 "$full_path" ;;
|
||||||
(( $+commands[pbzip2] )) && pbzip2 -cd "$full_path" > "${file:t:r}" \
|
|
||||||
|| bunzip2 -c "$full_path" > "${file:t:r}" ;;
|
|
||||||
(*.xz) xzcat "$full_path" > "${file:t:r}" ;;
|
(*.xz) xzcat "$full_path" > "${file:t:r}" ;;
|
||||||
(*.lrz) (( $+commands[lrunzip] )) && lrunzip "$full_path" ;;
|
(*.lrz) (( $+commands[lrunzip] )) && lrunzip "$full_path" ;;
|
||||||
(*.lz4) lz4 -d "$full_path" ;;
|
(*.lz4) lz4 -d "$full_path" ;;
|
||||||
(*.lzma) unlzma -c "$full_path" > "${file:t:r}" ;;
|
(*.lzma) unlzma "$full_path" ;;
|
||||||
(*.z) uncompress -c "$full_path" > "${file:t:r}" ;;
|
(*.z) uncompress "$full_path" ;;
|
||||||
(*.zip|*.war|*.jar|*.ear|*.sublime-package|*.ipa|*.ipsw|*.xpi|*.apk|*.aar|*.whl|*.vsix|*.crx|*.pk3|*.pk4) unzip "$full_path" ;;
|
(*.zip|*.war|*.jar|*.ear|*.sublime-package|*.ipa|*.ipsw|*.xpi|*.apk|*.aar|*.whl|*.vsix|*.crx|*.pk3|*.pk4) unzip "$full_path" ;;
|
||||||
(*.rar)
|
(*.rar)
|
||||||
if (( $+commands[unrar] )); then
|
if (( $+commands[unrar] )); then
|
||||||
@@ -140,40 +133,9 @@ EOF
|
|||||||
(*.deb)
|
(*.deb)
|
||||||
command mkdir -p "control" "data"
|
command mkdir -p "control" "data"
|
||||||
ar vx "$full_path" > /dev/null
|
ar vx "$full_path" > /dev/null
|
||||||
local member= dest= failed=0
|
builtin cd -q control; extract ../control.tar.*
|
||||||
for member in control.tar.* data.tar.*; do
|
builtin cd -q ../data; extract ../data.tar.*
|
||||||
dest="${member%%.*}"
|
builtin cd -q ..; command rm *.tar.* debian-binary ;;
|
||||||
case "${member:l}" in
|
|
||||||
(*.tar.gz)
|
|
||||||
(( $+commands[pigz] )) && { tar -I pigz -xvf "$member" -C "$dest" } \
|
|
||||||
|| tar zxvf "$member" -C "$dest" ;;
|
|
||||||
(*.tar.bz2)
|
|
||||||
(( $+commands[pbzip2] )) && { tar -I pbzip2 -xvf "$member" -C "$dest" } \
|
|
||||||
|| tar xvjf "$member" -C "$dest" ;;
|
|
||||||
(*.tar.xz)
|
|
||||||
# .deb members are small, so skip extract()'s pixz fast path and
|
|
||||||
# let tar use its built-in xz support (or a plain pipe).
|
|
||||||
tar --xz --help &> /dev/null \
|
|
||||||
&& tar --xz -xvf "$member" -C "$dest" \
|
|
||||||
|| xzcat "$member" | tar xvf - -C "$dest" ;;
|
|
||||||
(*.tar.zst)
|
|
||||||
tar --zstd --help &> /dev/null \
|
|
||||||
&& tar --zstd -xvf "$member" -C "$dest" \
|
|
||||||
|| zstdcat "$member" | tar xvf - -C "$dest" ;;
|
|
||||||
(*.tar)
|
|
||||||
tar xvf "$member" -C "$dest" ;;
|
|
||||||
(*)
|
|
||||||
echo "extract: cannot extract unexpected .deb member '$member'" >&2
|
|
||||||
failed=1
|
|
||||||
success=1 ;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
if (( failed )); then
|
|
||||||
# Keep the archive members so the unexpected one can be inspected.
|
|
||||||
echo "extract: leaving .deb members in place" >&2
|
|
||||||
else
|
|
||||||
command rm *.tar.* debian-binary
|
|
||||||
fi ;;
|
|
||||||
(*.zst) unzstd --stdout "$full_path" > "${file:t:r}" ;;
|
(*.zst) unzstd --stdout "$full_path" > "${file:t:r}" ;;
|
||||||
(*.cab|*.exe) cabextract "$full_path" ;;
|
(*.cab|*.exe) cabextract "$full_path" ;;
|
||||||
(*.cpio|*.obscpio) cpio -idmvF "$full_path" ;;
|
(*.cpio|*.obscpio) cpio -idmvF "$full_path" ;;
|
||||||
|
|||||||
@@ -1,188 +0,0 @@
|
|||||||
#!/usr/bin/env zsh
|
|
||||||
|
|
||||||
# Run with: zsh -df plugins/extract/tests/extract.test.zsh
|
|
||||||
emulate -L zsh
|
|
||||||
setopt err_return
|
|
||||||
|
|
||||||
for tool in ar lzma unlzma uncompress; do
|
|
||||||
(( $+commands[$tool] )) || {
|
|
||||||
print -u2 -r -- "These tests require $tool."
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
done
|
|
||||||
|
|
||||||
source "${0:A:h:h}/extract.plugin.zsh"
|
|
||||||
local test_dir=$(mktemp -d) original_dir=$PWD
|
|
||||||
|
|
||||||
check_extract() {
|
|
||||||
local extension=$1 mode=$2
|
|
||||||
local case_dir="$test_dir/$extension-$mode"
|
|
||||||
mkdir -p "$case_dir/source files" "$case_dir/work/target dir"
|
|
||||||
local archive="$case_dir/source files/sample.txt.$extension"
|
|
||||||
cp "$test_dir/fixture.$extension" "$archive"
|
|
||||||
builtin cd "$case_dir/work"
|
|
||||||
|
|
||||||
local output="$PWD/sample.txt"
|
|
||||||
local -a args
|
|
||||||
case "$mode" in
|
|
||||||
target)
|
|
||||||
args=(-t 'target dir')
|
|
||||||
output="$PWD/target dir/sample.txt"
|
|
||||||
;;
|
|
||||||
remove) args=(-r) ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# Run the plugin without the test's ERR_RETURN option.
|
|
||||||
() {
|
|
||||||
emulate -L zsh
|
|
||||||
extract "${args[@]}" "$archive"
|
|
||||||
} || return 1
|
|
||||||
cmp "$test_dir/plain" "$output"
|
|
||||||
if [[ $mode == remove ]]; then
|
|
||||||
[[ ! -e $archive ]]
|
|
||||||
else
|
|
||||||
[[ -f $archive ]]
|
|
||||||
fi
|
|
||||||
print -r -- "PASS: $extension ($mode)"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Extracting a .deb must place the control members directly in <name>/control
|
|
||||||
# and the data members directly in <name>/data, whatever their member count.
|
|
||||||
check_deb_extract() {
|
|
||||||
local mode=$1
|
|
||||||
local case_dir="$test_dir/deb-$mode"
|
|
||||||
mkdir -p "$case_dir/source files" "$case_dir/work/target dir" \
|
|
||||||
"$case_dir/src/ctl" "$case_dir/src/data/usr/bin"
|
|
||||||
print -r -- "postinst script" > "$case_dir/src/ctl/postinst"
|
|
||||||
print -r -- "conf:1" > "$case_dir/src/ctl/conffiles"
|
|
||||||
print -r -- "app main" > "$case_dir/src/data/usr/bin/app"
|
|
||||||
tar czf "$case_dir/src/control.tar.gz" -C "$case_dir/src/ctl" conffiles postinst
|
|
||||||
tar czf "$case_dir/src/data.tar.gz" -C "$case_dir/src/data" usr
|
|
||||||
print -r -- "2.0" > "$case_dir/src/debian-binary"
|
|
||||||
(
|
|
||||||
builtin cd "$case_dir/src"
|
|
||||||
rm -f "$case_dir/source files/pkg.deb"
|
|
||||||
ar rS "$case_dir/source files/pkg.deb" debian-binary control.tar.gz data.tar.gz
|
|
||||||
)
|
|
||||||
local archive="$case_dir/source files/pkg.deb"
|
|
||||||
|
|
||||||
builtin cd "$case_dir/work"
|
|
||||||
local base="$PWD/pkg"
|
|
||||||
local -a args
|
|
||||||
case "$mode" in
|
|
||||||
target)
|
|
||||||
args=(-t 'target dir')
|
|
||||||
base="$PWD/target dir/pkg"
|
|
||||||
;;
|
|
||||||
remove) args=(-r) ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
() {
|
|
||||||
emulate -L zsh
|
|
||||||
extract "${args[@]}" "$archive"
|
|
||||||
} || return 1
|
|
||||||
|
|
||||||
[[ -f "$base/control/conffiles" && -f "$base/control/postinst" ]] ||
|
|
||||||
{ print -u2 -r -- "$mode: control members not extracted into $base/control"; return 1 }
|
|
||||||
[[ -f "$base/data/usr/bin/app" ]] ||
|
|
||||||
{ print -u2 -r -- "$mode: data members not extracted into $base/data"; return 1 }
|
|
||||||
[[ ! -d "$base/control/control" && ! -d "$base/data/data" ]] ||
|
|
||||||
{ print -u2 -r -- "$mode: deb extraction double-nested the member directories"; return 1 }
|
|
||||||
[[ ! -e "$base/control.tar.gz" && ! -e "$base/data.tar.gz" && ! -e "$base/debian-binary" ]] ||
|
|
||||||
{ print -u2 -r -- "$mode: deb member debris left behind"; return 1 }
|
|
||||||
if [[ $mode == remove ]]; then
|
|
||||||
[[ ! -e $archive ]]
|
|
||||||
else
|
|
||||||
[[ -f $archive ]]
|
|
||||||
fi
|
|
||||||
print -r -- "PASS: deb ($mode)"
|
|
||||||
}
|
|
||||||
|
|
||||||
# An unexpected member must be reported and left on disk for inspection, and
|
|
||||||
# the cleanup must not delete the other members around it either.
|
|
||||||
check_deb_unexpected_member() {
|
|
||||||
local case_dir="$test_dir/deb-unexpected"
|
|
||||||
mkdir -p "$case_dir/src/ctl" "$case_dir/src/data/usr/bin"
|
|
||||||
print -r -- "postinst script" > "$case_dir/src/ctl/postinst"
|
|
||||||
print -r -- "app main" > "$case_dir/src/data/usr/bin/app"
|
|
||||||
tar czf "$case_dir/src/control.tar.gz" -C "$case_dir/src/ctl" postinst
|
|
||||||
print -r -- "unknown compression" > "$case_dir/src/control.tar.weird"
|
|
||||||
tar czf "$case_dir/src/data.tar.gz" -C "$case_dir/src/data" usr
|
|
||||||
print -r -- "2.0" > "$case_dir/src/debian-binary"
|
|
||||||
(
|
|
||||||
builtin cd "$case_dir/src"
|
|
||||||
ar rS "$case_dir/pkg.deb" debian-binary control.tar.weird data.tar.gz
|
|
||||||
)
|
|
||||||
|
|
||||||
builtin cd "$case_dir"
|
|
||||||
() {
|
|
||||||
emulate -L zsh
|
|
||||||
extract "$case_dir/pkg.deb"
|
|
||||||
} || return 1
|
|
||||||
|
|
||||||
[[ -f "$case_dir/pkg/data/usr/bin/app" ]] ||
|
|
||||||
{ print -u2 -r -- "deb-unexpected: known members were not extracted"; return 1 }
|
|
||||||
[[ -f "$case_dir/pkg/control.tar.weird" && -f "$case_dir/pkg/data.tar.gz" &&
|
|
||||||
-f "$case_dir/pkg/debian-binary" ]] ||
|
|
||||||
{ print -u2 -r -- "deb-unexpected: archive members were deleted"; return 1 }
|
|
||||||
print -r -- "PASS: deb (unexpected member)"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Passing more than one .deb in a single call must not leak the loop variables
|
|
||||||
# between archives; the stale `member`/`dest` locals used to be printed by the
|
|
||||||
# second archive.
|
|
||||||
check_deb_multiple() {
|
|
||||||
local case_dir="$test_dir/deb-multiple"
|
|
||||||
mkdir -p "$case_dir/src/ctl" "$case_dir/src/data/usr/bin"
|
|
||||||
print -r -- "postinst script" > "$case_dir/src/ctl/postinst"
|
|
||||||
print -r -- "app main" > "$case_dir/src/data/usr/bin/app"
|
|
||||||
tar czf "$case_dir/src/control.tar.gz" -C "$case_dir/src/ctl" postinst
|
|
||||||
tar czf "$case_dir/src/data.tar.gz" -C "$case_dir/src/data" usr
|
|
||||||
print -r -- "2.0" > "$case_dir/src/debian-binary"
|
|
||||||
(
|
|
||||||
builtin cd "$case_dir/src"
|
|
||||||
ar rS "$case_dir/one.deb" debian-binary control.tar.gz data.tar.gz
|
|
||||||
ar rS "$case_dir/two.deb" debian-binary control.tar.gz data.tar.gz
|
|
||||||
)
|
|
||||||
|
|
||||||
builtin cd "$case_dir"
|
|
||||||
local output
|
|
||||||
output=$( () {
|
|
||||||
emulate -L zsh
|
|
||||||
extract one.deb two.deb
|
|
||||||
} 2>&1 ) || return 1
|
|
||||||
|
|
||||||
[[ $output != *member=* && $output != *dest=* ]] ||
|
|
||||||
{ print -u2 -r -- "deb-multiple: stale loop variables were printed"; return 1 }
|
|
||||||
[[ -f one/control/postinst && -f one/data/usr/bin/app &&
|
|
||||||
-f two/control/postinst && -f two/data/usr/bin/app ]] ||
|
|
||||||
{ print -u2 -r -- "deb-multiple: both archives were not extracted"; return 1 }
|
|
||||||
print -r -- "PASS: deb (multiple archives)"
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
print -r -- hello > "$test_dir/plain"
|
|
||||||
lzma -c "$test_dir/plain" > "$test_dir/fixture.lzma"
|
|
||||||
# "hello\n" as a .Z stream, since many systems only ship uncompress.
|
|
||||||
printf '\037\235\220\150\312\260\141\363\106\001' \
|
|
||||||
> "$test_dir/fixture.Z"
|
|
||||||
|
|
||||||
cp "$test_dir/plain" "$test_dir/sample.txt"
|
|
||||||
tar -cf "$test_dir/fixture.tar" -C "$test_dir" sample.txt
|
|
||||||
lzma -c "$test_dir/fixture.tar" > "$test_dir/fixture.tar.lzma"
|
|
||||||
|
|
||||||
for extension in lzma Z tar.lzma; do
|
|
||||||
for mode in default target remove; do
|
|
||||||
check_extract "$extension" "$mode"
|
|
||||||
done
|
|
||||||
done
|
|
||||||
check_deb_extract default
|
|
||||||
check_deb_extract target
|
|
||||||
check_deb_extract remove
|
|
||||||
check_deb_unexpected_member
|
|
||||||
check_deb_multiple
|
|
||||||
print 'All extract compressed-file tests passed.'
|
|
||||||
} always {
|
|
||||||
builtin cd "$original_dir"
|
|
||||||
rm -rf -- "$test_dir"
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
# Fizzy CLI plugin
|
|
||||||
|
|
||||||
This plugin adds completion for the [Fizzy CLI (fizzy)](https://github.com/basecamp/fizzy-cli).
|
|
||||||
|
|
||||||
To use it, add `fizzy` to the plugins array in your zshrc file:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
plugins=(... fizzy)
|
|
||||||
```
|
|
||||||
|
|
||||||
This plugin does not add any aliases.
|
|
||||||
|
|
||||||
## Cache
|
|
||||||
|
|
||||||
This plugin caches the completion script and automatically updates it when the
|
|
||||||
plugin is loaded, which is usually when you start a new terminal emulator.
|
|
||||||
|
|
||||||
The cache is stored at `$ZSH_CACHE_DIR/completions/_fizzy`.
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
# Autocompletion for the Fizzy CLI (fizzy).
|
|
||||||
if (( ! $+commands[fizzy] )); then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If the completion isn't registered yet, autoload it and bind it to `fizzy`.
|
|
||||||
# Otherwise, compinit will have already done that from the cache.
|
|
||||||
if [[ -z ${_comps[fizzy]-} ]]; then
|
|
||||||
typeset -g -A _comps
|
|
||||||
autoload -Uz _fizzy
|
|
||||||
_comps[fizzy]=_fizzy
|
|
||||||
fi
|
|
||||||
|
|
||||||
zmodload -F zsh/files b:zf_mv || return
|
|
||||||
() {
|
|
||||||
local cache_file="$ZSH_CACHE_DIR/completions/_fizzy"
|
|
||||||
local temp_file
|
|
||||||
temp_file=$(mktemp "$ZSH_CACHE_DIR/completions/._fizzy.XXXXXXXX") || return
|
|
||||||
if command fizzy completion zsh >| "$temp_file" && [[ -s "$temp_file" ]] &&
|
|
||||||
zf_mv -f -- "$temp_file" "$cache_file"; then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
rm -f -- "$temp_file"
|
|
||||||
} &|
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
# fnox
|
|
||||||
|
|
||||||
Adds shell integration and completions for [fnox](https://github.com/jdx/fnox), a tool for provider-agnostic secret injection.
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
[Install fnox](https://fnox.jdx.dev/guide/quick-start.html), then add it to your plugins in `~/.zshrc`:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
plugins=(fnox)
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
See the [fnox documentation](https://fnox.jdx.dev/guide/shell-integration.html) for shell integration and usage.
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
if (( ! $+commands[fnox] )); then
|
|
||||||
# if we don't have fnox at all just bail out
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
eval "$(fnox activate zsh)"
|
|
||||||
|
|
||||||
# If the completion file doesn't exist yet, we need to autoload it and
|
|
||||||
# bind it to `fnox`. Otherwise, compinit will have already done that.
|
|
||||||
if [[ ! -f "$ZSH_CACHE_DIR/completions/_fnox" ]]; then
|
|
||||||
typeset -g -A _comps
|
|
||||||
autoload -Uz _fnox
|
|
||||||
_comps[fnox]=_fnox
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Regenerate completions when the executable changes.
|
|
||||||
if [[ ! -s "$ZSH_CACHE_DIR/completions/_fnox" || "$commands[fnox]" -nt "$ZSH_CACHE_DIR/completions/_fnox" ]]; then
|
|
||||||
zmodload -F zsh/files b:zf_mv
|
|
||||||
() {
|
|
||||||
local TMPPREFIX="$ZSH_CACHE_DIR/completions/._fnox"
|
|
||||||
zf_mv -f -- =( fnox completion zsh ) "$ZSH_CACHE_DIR/completions/_fnox"
|
|
||||||
} &|
|
|
||||||
fi
|
|
||||||
@@ -1,30 +1,7 @@
|
|||||||
## Fossil Plugin
|
## Fossil Plugin
|
||||||
|
|
||||||
This plugin adds completion support and prompt for fossil repositories.
|
This plugin adds completion support and prompt for fossil repositories.
|
||||||
|
The prompt will display the current branch and status been dirty or clean.
|
||||||
To use it, add `fossil` to the plugins array in your .zshrc file:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
plugins=(... fossil)
|
|
||||||
``
|
|
||||||
|
|
||||||
This plugin provides a prompt function named `fossil_prompt_info` that
|
|
||||||
will display the current branch and if there are changes (dirty) or not (clean).
|
|
||||||
|
|
||||||
### Prompt segments
|
|
||||||
|
|
||||||
These variables control how the prompt function looks:
|
|
||||||
|
|
||||||
```
|
|
||||||
ZSH_THEME_FOSSIL_PROMPT_PREFIX="%{$fg_bold[blue]%}fossil:(%{$fg_bold[red]%}"
|
|
||||||
ZSH_THEME_FOSSIL_PROMPT_SUFFIX="%{$fg_bold[blue]%})"
|
|
||||||
ZSH_THEME_FOSSIL_PROMPT_DIRTY="%{$fg_bold[red]%}✖"
|
|
||||||
ZSH_THEME_FOSSIL_PROMPT_CLEAN="%{$fg_bold[green]%}✔"
|
|
||||||
```
|
|
||||||
|
|
||||||
You can override their values in your .zshrc file, anywhere after the
|
|
||||||
`source $ZSH/oh-my-zsh.sh` line.
|
|
||||||
|
|
||||||
### CONTRIBUTOR
|
### CONTRIBUTOR
|
||||||
|
- Jefferson González ([jgmdev](https://github.com/jgmdev))
|
||||||
- Jefferson González ([jgmdev](https://github.com/jgmdev))
|
|
||||||
@@ -7,10 +7,10 @@ ZSH_THEME_FOSSIL_PROMPT_PREFIX="%{$fg_bold[blue]%}fossil:(%{$fg_bold[red]%}"
|
|||||||
ZSH_THEME_FOSSIL_PROMPT_SUFFIX="%{$fg_bold[blue]%})"
|
ZSH_THEME_FOSSIL_PROMPT_SUFFIX="%{$fg_bold[blue]%})"
|
||||||
|
|
||||||
# Text to display if the branch is dirty
|
# Text to display if the branch is dirty
|
||||||
ZSH_THEME_FOSSIL_PROMPT_DIRTY="%{$fg_bold[red]%}✖"
|
ZSH_THEME_FOSSIL_PROMPT_DIRTY=" %{$fg_bold[red]%}✖"
|
||||||
|
|
||||||
# Text to display if the branch is clean
|
# Text to display if the branch is clean
|
||||||
ZSH_THEME_FOSSIL_PROMPT_CLEAN="%{$fg_bold[green]%}✔"
|
ZSH_THEME_FOSSIL_PROMPT_CLEAN=" %{$fg_bold[green]%}✔"
|
||||||
|
|
||||||
function fossil_prompt_info() {
|
function fossil_prompt_info() {
|
||||||
local branch=$(fossil branch current 2>&1)
|
local branch=$(fossil branch current 2>&1)
|
||||||
@@ -25,35 +25,27 @@ function fossil_prompt_info() {
|
|||||||
dirty="$ZSH_THEME_FOSSIL_PROMPT_DIRTY"
|
dirty="$ZSH_THEME_FOSSIL_PROMPT_DIRTY"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf ' %s%s%s%s%s' \
|
printf '%s %s %s %s %s' \
|
||||||
"$ZSH_THEME_FOSSIL_PROMPT_PREFIX" \
|
"$ZSH_THEME_FOSSIL_PROMPT_PREFIX" \
|
||||||
"${branch:gs/%/%%}" \
|
"${branch:gs/%/%%}" \
|
||||||
"$dirty" \
|
|
||||||
"$ZSH_THEME_FOSSIL_PROMPT_SUFFIX" \
|
"$ZSH_THEME_FOSSIL_PROMPT_SUFFIX" \
|
||||||
|
"$dirty" \
|
||||||
"%{$reset_color%}"
|
"%{$reset_color%}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function _fossil_prompt () {
|
function _fossil_prompt () {
|
||||||
# Re-check each time, in case the theme rebuilds its prompt in precmd
|
local current=`echo $PROMPT $RPROMPT | grep fossil`
|
||||||
if [ -z "$_FOSSIL_PROMPT" ] || [[ "$PROMPT$RPROMPT" != *fossil_prompt_info* ]]; then
|
|
||||||
# Use substitutions to work out what other plugins and themes have
|
if [ "$_FOSSIL_PROMPT" = "" -o "$current" = "" ]; then
|
||||||
# done ahead of us so we don't duplicate their work.
|
local _prompt=${PROMPT}
|
||||||
#
|
local _rprompt=${RPROMPT}
|
||||||
# If $fossil_prompt_info isn't in the prompt strings already but we
|
|
||||||
# can find $git_prompt_info, put it immediately afterward so that
|
local is_prompt=`echo $PROMPT | grep git`
|
||||||
# one or the other appears in the prompt. We're gambling that you
|
|
||||||
# aren't in a directory that's a checkout for both a Git repo and a
|
if [ "$is_prompt" = "" ]; then
|
||||||
# Fossil repo.
|
RPROMPT="$_rprompt"'$(fossil_prompt_info)'
|
||||||
#
|
else
|
||||||
# Otherwise, add it to the right prompt, as before.
|
PROMPT="$_prompt"'$(fossil_prompt_info) '
|
||||||
if [ "${PROMPT/fossil_prompt_info//}" = "$PROMPT" ]; then
|
|
||||||
PROMPT="${PROMPT/git_prompt_info/git_prompt_info)\$(fossil_prompt_info}"
|
|
||||||
fi
|
|
||||||
if [ "${RPROMPT/fossil_prompt_info//}" = "$RPROMPT" ]; then
|
|
||||||
RPROMPT="${RPROMPT/git_prompt_info/git_prompt_info)\$(fossil_prompt_info}"
|
|
||||||
fi
|
|
||||||
if [[ "$PROMPT$RPROMPT" != *fossil_prompt_info* ]]; then
|
|
||||||
RPROMPT+='$(fossil_prompt_info)'
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_FOSSIL_PROMPT="1"
|
_FOSSIL_PROMPT="1"
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ if [[ -z "${CLOUDSDK_HOME}" ]]; then
|
|||||||
search_locations=(
|
search_locations=(
|
||||||
"$HOME/google-cloud-sdk"
|
"$HOME/google-cloud-sdk"
|
||||||
"/usr/local/share/google-cloud-sdk"
|
"/usr/local/share/google-cloud-sdk"
|
||||||
"/usr/local/google-cloud-sdk"
|
|
||||||
"/usr/local/Caskroom/google-cloud-sdk/latest/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/Caskroom/google-cloud-sdk/latest/google-cloud-sdk"
|
||||||
"/opt/homebrew/share/google-cloud-sdk"
|
"/opt/homebrew/share/google-cloud-sdk"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# git-commit plugin
|
# git-commit plugin
|
||||||
|
|
||||||
The git-commit plugin adds several git subcommands for
|
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.
|
[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:
|
To use it, add `git-commit` to the plugins array in your zshrc file:
|
||||||
@@ -12,7 +13,7 @@ plugins=(... git-commit)
|
|||||||
## Syntax
|
## Syntax
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
git <type> [(-s, --scope) "<scope>"] [(-a, --attention)] [(-b, --body) "<body>"] "<message>"
|
git <type> [(-s, --scope) "<scope>"] [(-a, --attention)] "<message>"
|
||||||
```
|
```
|
||||||
|
|
||||||
Where `type` is one of the following:
|
Where `type` is one of the following:
|
||||||
@@ -30,19 +31,17 @@ Where `type` is one of the following:
|
|||||||
- `test`
|
- `test`
|
||||||
- `wip`
|
- `wip`
|
||||||
|
|
||||||
The optional `-b` / `--body` becomes the commit body (a blank line after the subject), as defined by
|
> NOTE: the alias for `revert` type is `rev`, as otherwise it conflicts with the git command of the same name.
|
||||||
[Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/#summary).
|
> It will still generate a commit message in the format `revert: <message>`
|
||||||
|
|
||||||
> NOTE: the subcommand for `revert` type is `rev`, as otherwise it conflicts with the
|
> ⚠️ Enabling this plugin will (potentially) overwrite all `alias.<type>` that you manually set. Use with
|
||||||
> git command of the same name. It will still generate a commit message in the format
|
> care!
|
||||||
> `revert: <message>`
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
| Git subcommand | Command |
|
| Git alias | Command |
|
||||||
| --------------------------------------------- | ---------------------------------------------------- |
|
| --------------------------------------------- | ---------------------------------------------------- |
|
||||||
| `git style "remove trailing whitespace"` | `git commit -m "style: remove trailing whitespace"` |
|
| `git style "remove trailing whitespace"` | `git commit -m "style: remove trailing whitespace"` |
|
||||||
| `git wip "work in progress"` | `git commit -m "wip: work in progress"` |
|
| `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 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"` |
|
| `git rev -s "api" "rollback v2"` | `git commit -m "revert(api): rollback v2"` |
|
||||||
| `git feat -s "auth" -b "Keep session across redirects." "add login redirect"` | `git commit -m "feat(auth): add login redirect" -m "Keep session across redirects."` |
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
./omz_git_commit
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
./omz_git_commit
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
./omz_git_commit
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
./omz_git_commit
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
./omz_git_commit
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
./omz_git_commit
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
./omz_git_commit
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
./omz_git_commit
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
./omz_git_commit
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
./omz_git_commit
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
./omz_git_commit
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
./omz_git_commit
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
#!/usr/bin/env zsh
|
|
||||||
|
|
||||||
_omz_git_commit() {
|
|
||||||
0=${(%):-%x}
|
|
||||||
if [[ "$0" != */git-* ]]; then
|
|
||||||
echo >&2 "Expecting command named git-foo. Got '$0'."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
local _type="${0##*/git-}"
|
|
||||||
# The subcommand is shortened to avoid Git's built-in revert command.
|
|
||||||
if [[ "$_type" == rev ]]; then
|
|
||||||
_type=revert
|
|
||||||
fi
|
|
||||||
local _scope _attention _message _body
|
|
||||||
while [ $# -ne 0 ]; do
|
|
||||||
case $1 in
|
|
||||||
-s | --scope )
|
|
||||||
if [ -z "$2" ]; then
|
|
||||||
echo >&2 "Missing scope!"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
_scope="$2"
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
-a | --attention )
|
|
||||||
_attention="!"
|
|
||||||
shift 1
|
|
||||||
;;
|
|
||||||
-b | --body )
|
|
||||||
if [ -z "$2" ]; then
|
|
||||||
echo >&2 "Missing body!"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
_body="$2"
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
* )
|
|
||||||
_message="${_message} $1"
|
|
||||||
shift 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
git commit -m "${_type}${_scope:+(${_scope})}${_attention}:${_message}" ${_body:+-m} ${_body:+"$_body"}
|
|
||||||
}
|
|
||||||
_omz_git_commit "$@"
|
|
||||||
@@ -1,45 +1,58 @@
|
|||||||
# Add git-commit commands directory to path
|
local _rev="$(git -C $ZSH rev-parse HEAD 2> /dev/null)"
|
||||||
0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
|
if [[ $_rev == $(git config --global --get oh-my-zsh.git-commit-alias 2> /dev/null) ]]; then
|
||||||
0="${${(M)0:#/*}:-$PWD/$0}"
|
return
|
||||||
path=("${0:a:h}/git-commands" $path)
|
fi
|
||||||
|
git config --global oh-my-zsh.git-commit-alias "$_rev"
|
||||||
|
|
||||||
# Append completions for custom git commands
|
local -a _git_commit_aliases
|
||||||
() {
|
_git_commit_aliases=(
|
||||||
local -a git_user_commands
|
'build'
|
||||||
zstyle -a ':completion:*:*:git:*' user-commands 'git_user_commands' \
|
'chore'
|
||||||
|| git_user_commands=()
|
'ci'
|
||||||
git_user_commands+=(
|
'docs'
|
||||||
build:'Commit with a message indicating a build' \
|
'feat'
|
||||||
chore:'Commit with a message indicating a chore' \
|
'fix'
|
||||||
ci:'Commit with a message indicating a CI change' \
|
'perf'
|
||||||
docs:'Commit with a message indicating an update to the documentation' \
|
'refactor'
|
||||||
feat:'Commit with a message indicating a feature' \
|
'revert'
|
||||||
fix:'Commit with a message indicating a fix' \
|
'style'
|
||||||
perf:'Commit with a message indicating a performance enhancement' \
|
'test'
|
||||||
refactor:'Commit with a message indicating a refactor' \
|
'wip'
|
||||||
rev:'Commit with a message indicating a revert' \
|
)
|
||||||
style:'Commit with a message indicating a style change' \
|
|
||||||
test:'Commit with a message indicating updates to tests' \
|
|
||||||
wip:'Commit with a message indicating a work in progress'
|
|
||||||
)
|
|
||||||
zstyle ':completion:*:*:git:*' user-commands "${git_user_commands[@]}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Clean up aliases from the prior implementation of git-commit. Keep this migration
|
local _alias _type
|
||||||
# for users upgrading from versions that still wrote aliases to .gitconfig.
|
for _type in "${_git_commit_aliases[@]}"; do
|
||||||
() {
|
# an alias can't be named "revert" because the git command takes precedence
|
||||||
git config --global --get oh-my-zsh.git-commit-alias &> /dev/null || return 0
|
# https://stackoverflow.com/a/3538791
|
||||||
local -a old_git_aliases=(
|
case "$_type" in
|
||||||
'build' 'chore' 'ci'
|
revert) _alias=rev ;;
|
||||||
'docs' 'feat' 'fix'
|
*) _alias=$_type ;;
|
||||||
'perf' 'refactor' 'rev'
|
esac
|
||||||
'style' 'test' 'wip'
|
|
||||||
)
|
local _func='!a() {
|
||||||
local git_alias
|
local _scope _attention _message
|
||||||
for git_alias in $old_git_aliases; do
|
while [ $# -ne 0 ]; do
|
||||||
if [[ "$(git config --global --get alias.$git_alias | tr '\n' ' ')" == "!a() { local _scope _attention _message"* ]]; then
|
case $1 in
|
||||||
git config --global --unset alias.$git_alias
|
-s | --scope )
|
||||||
|
if [ -z $2 ]; then
|
||||||
|
echo "Missing scope!"
|
||||||
|
return 1
|
||||||
fi
|
fi
|
||||||
done
|
_scope="$2"
|
||||||
git config --global --unset oh-my-zsh.git-commit-alias
|
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
|
||||||
@@ -18,12 +18,10 @@ plugins=(... git)
|
|||||||
| `g` | `git` |
|
| `g` | `git` |
|
||||||
| `ga` | `git add` |
|
| `ga` | `git add` |
|
||||||
| `gaa` | `git add --all` |
|
| `gaa` | `git add --all` |
|
||||||
| `gan` | `git add --intent-to-add` |
|
|
||||||
| `ganpa` | `git add --intent-to-add . && git add --patch` |
|
|
||||||
| `gapa` | `git add --patch` |
|
| `gapa` | `git add --patch` |
|
||||||
| `gau` | `git add --update` |
|
| `gau` | `git add --update` |
|
||||||
| `gav` | `git add --verbose` |
|
| `gav` | `git add --verbose` |
|
||||||
| `gwip` | `git add -A; git commit --no-verify --no-gpg-sign --message "--wip-- [skip ci]"` |
|
| `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` |
|
| `gam` | `git am` |
|
||||||
| `gama` | `git am --abort` |
|
| `gama` | `git am --abort` |
|
||||||
| `gamc` | `git am --continue` |
|
| `gamc` | `git am --continue` |
|
||||||
@@ -193,7 +191,6 @@ plugins=(... git)
|
|||||||
| `grmc` | `git rm --cached` |
|
| `grmc` | `git rm --cached` |
|
||||||
| `gcount` | `git shortlog --summary -n` |
|
| `gcount` | `git shortlog --summary -n` |
|
||||||
| `gsh` | `git show` |
|
| `gsh` | `git show` |
|
||||||
| `gshs` | `git show --stat` |
|
|
||||||
| `gsps` | `git show --pretty=short --show-signature` |
|
| `gsps` | `git show --pretty=short --show-signature` |
|
||||||
| `gstall` | `git stash --all` |
|
| `gstall` | `git stash --all` |
|
||||||
| `gstu` | `git stash --include-untracked` |
|
| `gstu` | `git stash --include-untracked` |
|
||||||
@@ -210,7 +207,6 @@ plugins=(... git)
|
|||||||
| `gsb` | `git status --short -b` |
|
| `gsb` | `git status --short -b` |
|
||||||
| `gsnut` | `git status --untracked-files=no` |
|
| `gsnut` | `git status --untracked-files=no` |
|
||||||
| `gsi` | `git submodule init` |
|
| `gsi` | `git submodule init` |
|
||||||
| `gsms` | `git submodule status` |
|
|
||||||
| `gsu` | `git submodule update` |
|
| `gsu` | `git submodule update` |
|
||||||
| `gsuri` | `git submodule update --recursive --init` |
|
| `gsuri` | `git submodule update --recursive --init` |
|
||||||
| `gsd` | `git svn dcommit` |
|
| `gsd` | `git svn dcommit` |
|
||||||
|
|||||||
@@ -1,34 +1,6 @@
|
|||||||
# Git version checking
|
# Git version checking
|
||||||
autoload -Uz is-at-least
|
autoload -Uz is-at-least
|
||||||
# Running `git version` forks on every startup, so cache the result for a day
|
git_version="${${(As: :)$(git version 2>/dev/null)}[3]}"
|
||||||
# in $ZSH_CACHE_DIR, keyed on the resolved git binary's path and mtime.
|
|
||||||
# Run the fallback outside this function so its locals cannot shadow wrapper variables.
|
|
||||||
() {
|
|
||||||
# Shell overrides and relative PATH entries can make the command hash
|
|
||||||
# differ from the Git that Zsh actually runs.
|
|
||||||
(( $+functions[git] || $+aliases[git] || $+galiases[git] || ${path[(I)(|[^/]*)]} )) && return 1
|
|
||||||
|
|
||||||
local cache="$ZSH_CACHE_DIR/git-version" git_path="${commands[git]:+${commands[git]:A}}" key magic
|
|
||||||
local -a stat lines
|
|
||||||
# Shims and the macOS developer-tool dispatcher can select a different Git.
|
|
||||||
[[ "${git_path:t:r}" = 'git' ]] || return 1
|
|
||||||
[[ "$OSTYPE" == darwin* && "$git_path" = /usr/bin/git ]] && return 1
|
|
||||||
read -r -k 2 -u 0 magic 2>/dev/null < "$git_path" || return 1
|
|
||||||
[[ "$magic" = '#!' ]] && return 1
|
|
||||||
zmodload -F zsh/stat b:zstat && zstat -A stat +mtime -- "$git_path" 2>/dev/null || return 1
|
|
||||||
key="$git_path $stat[1]"
|
|
||||||
|
|
||||||
lines=("$cache"(Nm-1))
|
|
||||||
(( $#lines )) && lines=("${(@f)$(<"$cache")}")
|
|
||||||
if [[ "$lines[1]" = "$key" && "$lines[2]" == <->.<->* ]]; then
|
|
||||||
git_version="$lines[2]"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
git_version="${${(As: :)$(git version 2>/dev/null)}[3]}"
|
|
||||||
[[ ! -w "$ZSH_CACHE_DIR" ]] || print -rl -- "$key" "$git_version" >| "$cache"
|
|
||||||
return 0
|
|
||||||
} || git_version="${${(As: :)$(git version 2>/dev/null)}[3]}"
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Functions Current
|
# Functions Current
|
||||||
@@ -144,12 +116,10 @@ alias ggpur='ggu'
|
|||||||
alias g='git'
|
alias g='git'
|
||||||
alias ga='git add'
|
alias ga='git add'
|
||||||
alias gaa='git add --all'
|
alias gaa='git add --all'
|
||||||
alias gan='git add --intent-to-add'
|
|
||||||
alias ganpa='git add --intent-to-add . && git add --patch'
|
|
||||||
alias gapa='git add --patch'
|
alias gapa='git add --patch'
|
||||||
alias gau='git add --update'
|
alias gau='git add --update'
|
||||||
alias gav='git add --verbose'
|
alias gav='git add --verbose'
|
||||||
alias gwip='git add -A; git commit --no-verify --no-gpg-sign --message "--wip-- [skip ci]"'
|
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 gam='git am'
|
||||||
alias gama='git am --abort'
|
alias gama='git am --abort'
|
||||||
alias gamc='git am --continue'
|
alias gamc='git am --continue'
|
||||||
@@ -422,7 +392,6 @@ alias grm='git rm'
|
|||||||
alias grmc='git rm --cached'
|
alias grmc='git rm --cached'
|
||||||
alias gcount='git shortlog --summary --numbered'
|
alias gcount='git shortlog --summary --numbered'
|
||||||
alias gsh='git show'
|
alias gsh='git show'
|
||||||
alias gshs='git show --stat'
|
|
||||||
alias gsps='git show --pretty=short --show-signature'
|
alias gsps='git show --pretty=short --show-signature'
|
||||||
alias gstall='git stash --all'
|
alias gstall='git stash --all'
|
||||||
alias gstaa='git stash apply'
|
alias gstaa='git stash apply'
|
||||||
@@ -440,7 +409,6 @@ alias gss='git status --short'
|
|||||||
alias gsb='git status --short --branch'
|
alias gsb='git status --short --branch'
|
||||||
alias gsnut='git status --untracked-files=no'
|
alias gsnut='git status --untracked-files=no'
|
||||||
alias gsi='git submodule init'
|
alias gsi='git submodule init'
|
||||||
alias gsms='git submodule status'
|
|
||||||
alias gsu='git submodule update'
|
alias gsu='git submodule update'
|
||||||
alias gsuri='git submodule update --recursive --init'
|
alias gsuri='git submodule update --recursive --init'
|
||||||
alias gsd='git svn dcommit'
|
alias gsd='git svn dcommit'
|
||||||
|
|||||||
@@ -1,91 +0,0 @@
|
|||||||
#!/usr/bin/env zsh
|
|
||||||
|
|
||||||
emulate -LR zsh
|
|
||||||
|
|
||||||
plugin=${1:-${0:A:h:h}/git.plugin.zsh}
|
|
||||||
plugin=${plugin:A}
|
|
||||||
(( $+commands[git] )) || { print -u2 'Git is required for this test'; exit 1; }
|
|
||||||
real_version="${${(As: :)$(command git version)}[3]}"
|
|
||||||
test_dir=$(mktemp -d) || exit 1
|
|
||||||
trap 'command rm -rf -- "$test_dir"' EXIT
|
|
||||||
export ZSH_CACHE_DIR="$test_dir"
|
|
||||||
cache="$ZSH_CACHE_DIR/git-version"
|
|
||||||
|
|
||||||
typeset -i failures=0 tests=0
|
|
||||||
check() {
|
|
||||||
local description=$1
|
|
||||||
shift
|
|
||||||
(( tests++ ))
|
|
||||||
if "$@"; then
|
|
||||||
print -r -- "PASS: $description"
|
|
||||||
else
|
|
||||||
print -u2 -r -- "FAIL: $description"
|
|
||||||
(( failures++ ))
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Each source gets a fresh shell scope while sharing the persistent cache.
|
|
||||||
probe() (
|
|
||||||
local mode=$1 expected=$2 version
|
|
||||||
: > "$test_dir/versions"
|
|
||||||
autoload -Uz +X is-at-least
|
|
||||||
functions[_test_is_at_least]=$functions[is-at-least]
|
|
||||||
is-at-least() {
|
|
||||||
print -r -- "$2" >> "$test_dir/versions"
|
|
||||||
_test_is_at_least "$@"
|
|
||||||
}
|
|
||||||
compdef() { :; }
|
|
||||||
case $mode in
|
|
||||||
function) git() { print -r -- "git version $expected"; } ;;
|
|
||||||
alias) alias git="print -r -- 'git version $expected'" ;;
|
|
||||||
esac
|
|
||||||
source "$plugin"
|
|
||||||
local -a versions=("${(@f)$(<"$test_dir/versions")}")
|
|
||||||
(( $#versions == 4 )) || return 1
|
|
||||||
for version in "$versions[@]"; do
|
|
||||||
[[ "$version" == "$expected" ]] || return 1
|
|
||||||
done
|
|
||||||
if [[ "$expected" == 2.5.0 ]]; then
|
|
||||||
[[ "$aliases[gpf]" == 'git push --force-with-lease' \
|
|
||||||
&& "$aliases[gsta]" == 'git stash save' ]] || return 1
|
|
||||||
fi
|
|
||||||
)
|
|
||||||
|
|
||||||
check 'cold load probes the installed Git' probe binary "$real_version"
|
|
||||||
if [[ ! -f "$cache" ]]; then
|
|
||||||
print -u2 'This test requires a native Git executable eligible for caching'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
key="${${(f)$(<"$cache")}[1]}"
|
|
||||||
|
|
||||||
check 'warm load uses the installed version' probe binary "$real_version"
|
|
||||||
check 'function override bypasses an existing binary cache' probe function 2.5.0
|
|
||||||
check 'alias override bypasses an existing binary cache' probe alias 2.5.0
|
|
||||||
check 'shell overrides do not replace the binary cache' probe binary "$real_version"
|
|
||||||
|
|
||||||
# A different cached version distinguishes a cache hit from a fresh probe.
|
|
||||||
print -rl -- "$key" 2.5.0 > "$cache"
|
|
||||||
check 'valid warm cache avoids a new version probe' probe binary 2.5.0
|
|
||||||
|
|
||||||
print -r -- "$key" > "$cache"
|
|
||||||
check 'missing version line triggers a fresh probe' probe binary "$real_version"
|
|
||||||
print -rl -- "$key" '' > "$cache"
|
|
||||||
check 'empty version line triggers a fresh probe' probe binary "$real_version"
|
|
||||||
print -rl -- "$key" invalid > "$cache"
|
|
||||||
check 'invalid version line triggers a fresh probe' probe binary "$real_version"
|
|
||||||
print -rl -- 'different executable' 2.5.0 > "$cache"
|
|
||||||
check 'different binary key triggers a fresh probe' probe binary "$real_version"
|
|
||||||
|
|
||||||
print -rl -- "$key" 2.5.0 > "$cache"
|
|
||||||
touch -t 200001010000 "$cache"
|
|
||||||
check 'expired cache triggers a fresh probe' probe binary "$real_version"
|
|
||||||
|
|
||||||
rm "$cache"
|
|
||||||
check 'function override works without a cache' probe function 2.5.0
|
|
||||||
check 'function override does not write a cache' test ! -e "$cache"
|
|
||||||
rm -f "$cache"
|
|
||||||
check 'alias override works without a cache' probe alias 2.5.0
|
|
||||||
check 'alias override does not write a cache' test ! -e "$cache"
|
|
||||||
|
|
||||||
print -r -- "$tests tests, $failures failures"
|
|
||||||
(( failures == 0 ))
|
|
||||||
@@ -4,11 +4,7 @@ globalias() {
|
|||||||
# (A) makes it an array even if there's only one element
|
# (A) makes it an array even if there's only one element
|
||||||
local word=${${(Az)LBUFFER}[-1]}
|
local word=${${(Az)LBUFFER}[-1]}
|
||||||
if [[ $GLOBALIAS_FILTER_VALUES[(Ie)$word] -eq 0 ]]; then
|
if [[ $GLOBALIAS_FILTER_VALUES[(Ie)$word] -eq 0 ]]; then
|
||||||
# Completion also considers quoted strings and assignment values as aliases.
|
|
||||||
# Only expand when the complete shell word is an alias name.
|
|
||||||
if (( ${+aliases[$word]} || ${+galiases[$word]} )); then
|
|
||||||
zle _expand_alias
|
zle _expand_alias
|
||||||
fi
|
|
||||||
zle expand-word
|
zle expand-word
|
||||||
fi
|
fi
|
||||||
zle self-insert
|
zle self-insert
|
||||||
|
|||||||
@@ -1,81 +0,0 @@
|
|||||||
#!/usr/bin/env zsh
|
|
||||||
|
|
||||||
# Exercise the actual ZLE widgets in an isolated interactive shell.
|
|
||||||
emulate -L zsh
|
|
||||||
setopt err_return
|
|
||||||
zmodload zsh/zpty
|
|
||||||
zmodload zsh/zselect
|
|
||||||
|
|
||||||
local test_dir=$(mktemp -d)
|
|
||||||
export GLOBALIAS_TEST_PLUGIN=${0:A:h:h}/globalias.plugin.zsh
|
|
||||||
export GLOBALIAS_TEST_RESULT=$test_dir/result
|
|
||||||
|
|
||||||
wait_for_marker() {
|
|
||||||
local marker=$1 output received
|
|
||||||
local -i deadline=$(( SECONDS + 5 ))
|
|
||||||
while (( SECONDS < deadline )); do
|
|
||||||
if zpty -r globalias-test output; then
|
|
||||||
received+=$output
|
|
||||||
[[ $received == *$marker* ]] && return 0
|
|
||||||
else
|
|
||||||
zselect -t 1 || true
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
print -u2 -r -- "Timed out waiting for ZLE: $received"
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
check_expansion() {
|
|
||||||
local input=$1 expected=$2 actual
|
|
||||||
zpty -w -n globalias-test "$input"$' \x18'
|
|
||||||
wait_for_marker GLOBALIAS_TEST_CAPTURED
|
|
||||||
actual=$(< "$GLOBALIAS_TEST_RESULT")
|
|
||||||
if [[ $actual != "$expected" ]]; then
|
|
||||||
print -u2 -r -- "Input: ${(qqq)input}"
|
|
||||||
print -u2 -r -- "Expected: ${(qqq)expected}; got: ${(qqq)actual}"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
cat > "$test_dir/setup.zsh" <<'SETUP'
|
|
||||||
autoload -Uz compinit
|
|
||||||
compinit -D
|
|
||||||
source "$GLOBALIAS_TEST_PLUGIN"
|
|
||||||
alias 1='cd -1'
|
|
||||||
alias ll='ls -l'
|
|
||||||
alias -g G='| grep'
|
|
||||||
GLOBALIAS_FILTER_VALUES=(ll)
|
|
||||||
_globalias_test_capture() {
|
|
||||||
print -rn -- "$BUFFER" > "$GLOBALIAS_TEST_RESULT"
|
|
||||||
print -r -- $'\nGLOBALIAS_TEST_CAPTURED'
|
|
||||||
BUFFER=
|
|
||||||
zle .accept-line
|
|
||||||
}
|
|
||||||
zle -N _globalias_test_capture
|
|
||||||
bindkey '^X' _globalias_test_capture
|
|
||||||
PS1='GLOBALIAS_TEST_READY> '
|
|
||||||
RPROMPT=
|
|
||||||
SETUP
|
|
||||||
zpty -b globalias-test zsh -dfi
|
|
||||||
zpty -w globalias-test "source ${(q)test_dir}/setup.zsh"
|
|
||||||
wait_for_marker GLOBALIAS_TEST_READY
|
|
||||||
|
|
||||||
check_expansion 'DEBUG=1' 'DEBUG=1 '
|
|
||||||
check_expansion 'DEBUG="1"' 'DEBUG="1" '
|
|
||||||
check_expansion "DEBUG='1'" "DEBUG='1' "
|
|
||||||
check_expansion '1' 'cd -1 '
|
|
||||||
check_expansion '"1"' '"1" '
|
|
||||||
check_expansion "'1'" "'1' "
|
|
||||||
check_expansion '\1' '\1 '
|
|
||||||
check_expansion 'echo G' 'echo | grep '
|
|
||||||
check_expansion 'DEBUG=1 1' 'DEBUG=1 cd -1 '
|
|
||||||
check_expansion 'll' 'll '
|
|
||||||
check_expansion 'echo $((1+2))' 'echo 3 '
|
|
||||||
check_expansion 'echo {a,b}' 'echo a b '
|
|
||||||
check_expansion '' ' '
|
|
||||||
print 'All globalias expansion tests passed.'
|
|
||||||
} always {
|
|
||||||
zpty -d globalias-test 2>/dev/null || true
|
|
||||||
rm -rf -- "$test_dir"
|
|
||||||
}
|
|
||||||
@@ -22,7 +22,6 @@ plugins=(... golang)
|
|||||||
| gofx | `go fix` | Update packages to use a new API |
|
| gofx | `go fix` | Update packages to use a new API |
|
||||||
| gog | `go get` | Downloads packages and then installs them to $GOPATH |
|
| gog | `go get` | Downloads packages and then installs them to $GOPATH |
|
||||||
| goga | `go get ./...` | Installs all dependencies in current directory, recursively |
|
| goga | `go get ./...` | Installs all dependencies in current directory, recursively |
|
||||||
| goge | `go generate` | Generate Go files by processing source |
|
|
||||||
| goi | `go install` | Compiles and installs packages to $GOPATH |
|
| goi | `go install` | Compiles and installs packages to $GOPATH |
|
||||||
| gol | `go list` | Lists Go packages |
|
| gol | `go list` | Lists Go packages |
|
||||||
| gom | `go mod` | Access to operations on modules |
|
| gom | `go mod` | Access to operations on modules |
|
||||||
@@ -55,4 +54,3 @@ changes your prompt to:
|
|||||||
```
|
```
|
||||||
~/go/project$ ▋ 1.22.3
|
~/go/project$ ▋ 1.22.3
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -19,7 +19,6 @@ alias gofa='go fmt ./...'
|
|||||||
alias gofx='go fix'
|
alias gofx='go fix'
|
||||||
alias gog='go get'
|
alias gog='go get'
|
||||||
alias goga='go get ./...'
|
alias goga='go get ./...'
|
||||||
alias goge='go generate'
|
|
||||||
alias goi='go install'
|
alias goi='go install'
|
||||||
alias gol='go list'
|
alias gol='go list'
|
||||||
alias gom='go mod'
|
alias gom='go mod'
|
||||||
|
|||||||
@@ -5,40 +5,10 @@ Applies some fixes for some common issues encountered with [GPG's gpg-agent](htt
|
|||||||
More specifically, this plugin:
|
More specifically, this plugin:
|
||||||
|
|
||||||
- Updates the `GPG_TTY` environment variable before each shell execution.
|
- Updates the `GPG_TTY` environment variable before each shell execution.
|
||||||
- Updates the `SSH_AUTH_SOCK` environment variable if `gpg-agent` is your SSH
|
- Updates the `SSH_AUTH_SOCK` environment variable if `enable-ssh-support` is turned on.
|
||||||
agent. By default the plugin checks whether `enable-ssh-support` is turned
|
|
||||||
on. The [`ssh-support` setting](#settings) lets you say so yourself.
|
|
||||||
|
|
||||||
To use it, add `gpg-agent` to the plugins array of your zshrc file:
|
To use it, add `gpg-agent` to the plugins array of your zshrc file:
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
plugins=(... gpg-agent)
|
plugins=(... gpg-agent)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Settings
|
|
||||||
|
|
||||||
Every time a shell starts, the plugin runs `gpgconf --list-options gpg-agent` to
|
|
||||||
find out whether `enable-ssh-support` is turned on. That check can be slow. If
|
|
||||||
you already know the answer, state it with the `ssh-support` style and the
|
|
||||||
plugin skips the check. Set it in your zshrc, before Oh My Zsh is sourced.
|
|
||||||
|
|
||||||
If you don't use `gpg-agent` as your SSH agent:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
zstyle ':omz:plugins:gpg-agent' ssh-support no
|
|
||||||
```
|
|
||||||
|
|
||||||
The plugin then only sets `GPG_TTY`. It leaves `SSH_AUTH_SOCK` alone, and it
|
|
||||||
doesn't update the agent's tty before each command, which only SSH support
|
|
||||||
needs.
|
|
||||||
|
|
||||||
If you do use `gpg-agent` as your SSH agent:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
zstyle ':omz:plugins:gpg-agent' ssh-support yes
|
|
||||||
```
|
|
||||||
|
|
||||||
The plugin then sets `SSH_AUTH_SOCK` without checking. `enable-ssh-support`
|
|
||||||
still has to be set in your `gpg-agent.conf` for SSH to work.
|
|
||||||
|
|
||||||
Leave the style unset to keep the automatic check.
|
|
||||||
@@ -1,16 +1,5 @@
|
|||||||
export GPG_TTY=$TTY
|
export GPG_TTY=$TTY
|
||||||
|
|
||||||
# The ssh-support style says whether gpg-agent is used as the ssh agent.
|
|
||||||
# Setting it saves asking gpgconf, which can be slow.
|
|
||||||
zstyle -t ':omz:plugins:gpg-agent' ssh-support
|
|
||||||
_gpg_agent_ssh_support=$? # 0 if yes, 1 if no, 2 if not set
|
|
||||||
|
|
||||||
# Everything below is only needed for ssh support
|
|
||||||
if (( _gpg_agent_ssh_support == 1 )); then
|
|
||||||
unset _gpg_agent_ssh_support
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Fix for passphrase prompt on the correct tty
|
# Fix for passphrase prompt on the correct tty
|
||||||
# See https://www.gnupg.org/documentation/manuals/gnupg/Agent-Options.html#option-_002d_002denable_002dssh_002dsupport
|
# See https://www.gnupg.org/documentation/manuals/gnupg/Agent-Options.html#option-_002d_002denable_002dssh_002dsupport
|
||||||
function _gpg-agent_update-tty_preexec {
|
function _gpg-agent_update-tty_preexec {
|
||||||
@@ -20,13 +9,9 @@ autoload -U add-zsh-hook
|
|||||||
add-zsh-hook preexec _gpg-agent_update-tty_preexec
|
add-zsh-hook preexec _gpg-agent_update-tty_preexec
|
||||||
|
|
||||||
# If enable-ssh-support is set, fix ssh agent integration
|
# If enable-ssh-support is set, fix ssh agent integration
|
||||||
if (( _gpg_agent_ssh_support == 0 )) \
|
if [[ $(gpgconf --list-options gpg-agent 2>/dev/null | awk -F: '$1=="enable-ssh-support" {print $10}') = 1 ]]; then
|
||||||
|| [[ $(gpgconf --list-options gpg-agent 2>/dev/null \
|
|
||||||
| awk -F: '$1=="enable-ssh-support" {print $10}') = 1 ]]; then
|
|
||||||
unset SSH_AGENT_PID
|
unset SSH_AGENT_PID
|
||||||
if [[ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]]; then
|
if [[ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]]; then
|
||||||
export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
|
export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
unset _gpg_agent_ssh_support
|
|
||||||
@@ -112,37 +112,6 @@ plugins=(... hcloud)
|
|||||||
| hcst | `hcloud server-type list` | List all server types |
|
| hcst | `hcloud server-type list` | List all server types |
|
||||||
| hcit | `hcloud image list --type system` | List all system images |
|
| hcit | `hcloud image list --type system` | List all system images |
|
||||||
|
|
||||||
## Prompt function
|
|
||||||
|
|
||||||
This plugin provides `hcloud_prompt_info` which can be added to your prompt to display the current Hetzner Cloud context.
|
|
||||||
|
|
||||||
- If `HCLOUD_TOKEN` environment variable is set, it displays `HCLOUD_TOKEN` (indicating direct token usage)
|
|
||||||
- Otherwise, it displays the active context name
|
|
||||||
|
|
||||||
### Usage
|
|
||||||
|
|
||||||
Add `$(hcloud_prompt_info)` to your `PROMPT` or `RPROMPT` in your `.zshrc`:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
RPROMPT='$(hcloud_prompt_info)'
|
|
||||||
```
|
|
||||||
|
|
||||||
### Theme variables
|
|
||||||
|
|
||||||
| Variable | Default | Description |
|
|
||||||
| :----------------------------- | :-------------- | :----------------------------------------------- |
|
|
||||||
| `ZSH_THEME_HCLOUD_PREFIX` | `<hcloud:` | Prefix before the context name |
|
|
||||||
| `ZSH_THEME_HCLOUD_SUFFIX` | `>` | Suffix after the context name |
|
|
||||||
| `ZSH_THEME_HCLOUD_TOKEN_TEXT` | `HCLOUD_TOKEN` | Text shown when `HCLOUD_TOKEN` env var is set |
|
|
||||||
|
|
||||||
### Example with custom styling
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
ZSH_THEME_HCLOUD_PREFIX="%{$fg[blue]%}hcloud:("
|
|
||||||
ZSH_THEME_HCLOUD_SUFFIX=")%{$reset_color%}"
|
|
||||||
RPROMPT='$(hcloud_prompt_info)'
|
|
||||||
```
|
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
This plugin requires the [Hetzner Cloud CLI](https://github.com/hetznercloud/cli) to be installed.
|
This plugin requires the [Hetzner Cloud CLI](https://github.com/hetznercloud/cli) to be installed.
|
||||||
|
|||||||
Loaded 100 of 187 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user