mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-01-30 02:44:42 +01:00
Merge branch 'master' into add-git-grep-alias
This commit is contained in:
commit
6b7468772e
698 changed files with 61917 additions and 16123 deletions
|
|
@ -4,7 +4,8 @@ root = true
|
|||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
charset = utf-8
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
|
||||
[*.sh]
|
||||
[*.py]
|
||||
indent_size = 4
|
||||
indent_style = tab
|
||||
|
|
|
|||
15
.github/CODEOWNERS
vendored
15
.github/CODEOWNERS
vendored
|
|
@ -1,3 +1,14 @@
|
|||
# Plugin owners
|
||||
plugins/gitfast/ @felipec
|
||||
plugins/sdk/ @rgoldberg
|
||||
plugins/archlinux/ @ratijas
|
||||
plugins/dbt/ @msempere
|
||||
plugins/eza/ @pepoluan
|
||||
plugins/genpass/ @atoponce
|
||||
plugins/git-lfs/ @hellovietduc
|
||||
plugins/gitfast/ @felipec
|
||||
plugins/react-native @esthor
|
||||
plugins/sdk/ @rgoldberg
|
||||
plugins/shell-proxy/ @septs
|
||||
plugins/starship/ @axieax
|
||||
plugins/universalarchive/ @Konfekt
|
||||
plugins/wp-cli/ @joshmedeski
|
||||
plugins/zoxide/ @ajeetdsouza
|
||||
|
|
|
|||
2
.github/FUNDING.yml
vendored
Normal file
2
.github/FUNDING.yml
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
github: [ohmyzsh, robbyrussell, mcornella, larson-carter, carlosala]
|
||||
open_collective: ohmyzsh
|
||||
46
.github/ISSUE_TEMPLATE/bug_report.md
vendored
46
.github/ISSUE_TEMPLATE/bug_report.md
vendored
|
|
@ -1,46 +0,0 @@
|
|||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve Oh My Zsh
|
||||
labels: 'Type: support'
|
||||
|
||||
---
|
||||
|
||||
<!--
|
||||
Fill this out before posting. You can delete irrelevant sections, but
|
||||
an issue where no sections have been filled will be deleted without comment.
|
||||
-->
|
||||
|
||||
**Describe the bug**
|
||||
A clear description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior, for example:
|
||||
1. Enable this plugin '...'
|
||||
2. Run command '...' or try the autocomplete command '...'
|
||||
3. See error
|
||||
|
||||
**Expected behavior**
|
||||
A brief description of what should happen.
|
||||
|
||||
**Screenshots and/or Recordings**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
You can also record an asciinema session: https://asciinema.org/
|
||||
|
||||
**Self Check**
|
||||
|
||||
- Have you tried reaching out on the [Discord server](https://discord.gg/ohmyzsh)?
|
||||
This can help cut down on filling up issues. We always have a few people
|
||||
online that are in a variety of timezones that are willing to help you!
|
||||
|
||||
- Also searching existing [GitHub Issues](https://github.com/ohmyzsh/ohmyzsh/issues?q=) might help you get quicker support
|
||||
|
||||
**Desktop (please complete the following information):**
|
||||
|
||||
- OS / Distro: [e.g. Arch Linux, macOS]
|
||||
- If on Windows what version of WSL: [e.g. WSL1, WSL2]
|
||||
- Latest ohmyzsh update?: [e.g. Yes/No]
|
||||
- ZSH Version: [e.g. 5.6]
|
||||
- Terminal emulator: [e.g. iTerm2]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here. This can be themes, plugins, custom configs.
|
||||
68
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
68
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
name: Report a bug
|
||||
description: Report a bug that isn't caused by Oh My Zsh. If unsure, use this form
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
## Self Check
|
||||
- Look for similar errors in existing [GitHub Issues](https://github.com/ohmyzsh/ohmyzsh/issues?q=is%3Aissue) (open or closed).
|
||||
- Try reaching out on the [Discord server](https://discord.gg/ohmyzsh) for help.
|
||||
- type: textarea
|
||||
validations:
|
||||
required: true
|
||||
attributes:
|
||||
label: Describe the bug
|
||||
description: A clear description of what the bug is.
|
||||
- type: textarea
|
||||
validations:
|
||||
required: true
|
||||
attributes:
|
||||
label: Steps to reproduce
|
||||
description: |
|
||||
Steps to reproduce the problem.
|
||||
placeholder: |
|
||||
For example:
|
||||
1. Enable plugin '...'
|
||||
2. Run command '...' or try to complete command '...'
|
||||
3. See error
|
||||
- type: textarea
|
||||
validations:
|
||||
required: true
|
||||
attributes:
|
||||
label: Expected behavior
|
||||
description: A brief description of what should happen.
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Screenshots and recordings
|
||||
description: |
|
||||
If applicable, add screenshots to help explain your problem. You can also record an asciinema session: https://asciinema.org/
|
||||
- type: input
|
||||
validations:
|
||||
required: true
|
||||
attributes:
|
||||
label: OS / Linux distribution
|
||||
placeholder: Windows 10, Ubuntu 20.04, Arch Linux, macOS 10.15...
|
||||
- type: input
|
||||
validations:
|
||||
required: true
|
||||
attributes:
|
||||
label: Zsh version
|
||||
description: Run `echo $ZSH_VERSION` to check.
|
||||
placeholder: "5.6"
|
||||
- type: input
|
||||
validations:
|
||||
required: true
|
||||
attributes:
|
||||
label: Terminal emulator
|
||||
placeholder: iTerm2, GNOME Terminal, Terminal.app...
|
||||
- type: dropdown
|
||||
attributes:
|
||||
label: If using WSL on Windows, which version of WSL
|
||||
description: Run `wsl -l -v` to check.
|
||||
options:
|
||||
- WSL1
|
||||
- WSL2
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Additional context
|
||||
description: Add any other context about the problem here. This can be themes, plugins, custom settings...
|
||||
77
.github/ISSUE_TEMPLATE/bug_report_omz.yml
vendored
Normal file
77
.github/ISSUE_TEMPLATE/bug_report_omz.yml
vendored
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
name: Report a bug in Oh My Zsh
|
||||
description: Create a report to help us improve Oh My Zsh
|
||||
labels: ['Bug']
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
## Self Check
|
||||
- **Make sure this bug only happens with Oh My Zsh enabled**.
|
||||
- Look for similar errors in existing [GitHub Issues](https://github.com/ohmyzsh/ohmyzsh/issues?q=is%3Aissue) (open or closed).
|
||||
- Try reaching out on the [Discord server](https://discord.gg/ohmyzsh) for help.
|
||||
- type: textarea
|
||||
validations:
|
||||
required: true
|
||||
attributes:
|
||||
label: Describe the bug
|
||||
description: A clear description of what the bug is.
|
||||
- type: textarea
|
||||
validations:
|
||||
required: true
|
||||
attributes:
|
||||
label: Steps to reproduce
|
||||
description: |
|
||||
Steps to reproduce the problem.
|
||||
placeholder: |
|
||||
For example:
|
||||
1. Enable plugin '...'
|
||||
2. Run command '...' or try to complete command '...'
|
||||
3. See error
|
||||
- type: textarea
|
||||
validations:
|
||||
required: true
|
||||
attributes:
|
||||
label: Expected behavior
|
||||
description: A brief description of what should happen.
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Screenshots and recordings
|
||||
description: |
|
||||
If applicable, add screenshots to help explain your problem. You can also record an asciinema session: https://asciinema.org/
|
||||
- type: input
|
||||
validations:
|
||||
required: true
|
||||
attributes:
|
||||
label: OS / Linux distribution
|
||||
placeholder: Windows 10, Ubuntu 20.04, Arch Linux, macOS 10.15...
|
||||
- type: input
|
||||
validations:
|
||||
required: true
|
||||
attributes:
|
||||
label: Zsh version
|
||||
description: Run `echo $ZSH_VERSION` to check.
|
||||
placeholder: "5.6"
|
||||
- type: input
|
||||
validations:
|
||||
required: true
|
||||
attributes:
|
||||
label: Oh My Zsh version
|
||||
description: Run `omz version` to check.
|
||||
placeholder: master (bf303965)
|
||||
- type: input
|
||||
validations:
|
||||
required: true
|
||||
attributes:
|
||||
label: Terminal emulator
|
||||
placeholder: iTerm2, GNOME Terminal, Terminal.app...
|
||||
- type: dropdown
|
||||
attributes:
|
||||
label: If using WSL on Windows, which version of WSL
|
||||
description: Run `wsl -l -v` to check.
|
||||
options:
|
||||
- WSL1
|
||||
- WSL2
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Additional context
|
||||
description: Add any other context about the problem here. This can be themes, plugins, custom settings...
|
||||
3
.github/ISSUE_TEMPLATE/config.yml
vendored
3
.github/ISSUE_TEMPLATE/config.yml
vendored
|
|
@ -1,5 +1,8 @@
|
|||
blank_issues_enabled: true
|
||||
contact_links:
|
||||
- name: Support
|
||||
url: https://github.com/ohmyzsh/ohmyzsh/discussions
|
||||
about: Ask the community for support
|
||||
- name: Get help on Discord
|
||||
url: https://discord.gg/ohmyzsh
|
||||
about: Have a quick question? Join the Discord server and ask on the appropriate channel.
|
||||
|
|
|
|||
29
.github/ISSUE_TEMPLATE/feature_request.md
vendored
29
.github/ISSUE_TEMPLATE/feature_request.md
vendored
|
|
@ -1,29 +0,0 @@
|
|||
---
|
||||
name: Feature request
|
||||
about: Suggest a feature for Oh My Zsh
|
||||
labels: 'Type: feature'
|
||||
|
||||
---
|
||||
|
||||
<!--
|
||||
Fill this out before posting. You can delete irrelevant sections, but
|
||||
an issue where no sections have been filled will be deleted without comment.
|
||||
-->
|
||||
|
||||
**Is your feature request related to a particular plugin or theme? If so, specify it.**
|
||||
The name of the plugin, theme or alias that you would like us to improve. [...]
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A description of what you want to happen. [...]
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A description of any alternative solutions or features you've considered. This can also include other plugins or themes.
|
||||
|
||||
**Additional context**
|
||||
Add any other context, screenshots or discord conversations about the feature request here. Also if you have any PRs related to this issue that are already open that you would like us to look at.
|
||||
|
||||
**Related Issues**
|
||||
Is there any open or closed issues that is related to this feature request? If so please link them below! [...]
|
||||
37
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
Normal file
37
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
name: Feature request
|
||||
description: Suggest a feature for Oh My Zsh
|
||||
labels: ["Feature"]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
## Self Check
|
||||
- Look for similar features in existing [GitHub Issues](https://github.com/ohmyzsh/ohmyzsh/issues?q=is%3Aissue) (open or closed).
|
||||
- type: input
|
||||
attributes:
|
||||
label: If the feature request is for a plugin or theme, specify it here.
|
||||
description: The name of the plugin or theme that you would like us to improve.
|
||||
placeholder: e.g. Git plugin, Agnoster theme
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: If the feature solves a problem you have, specify it here.
|
||||
description: A description of what the problem is.
|
||||
placeholder: Ex. I'm always frustrated when...
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Describe the proposed feature.
|
||||
description: A description of what you want to happen. Be as specific as possible.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Describe alternatives you've considered
|
||||
description: A description of any alternative solutions or features you've considered. This can also include other plugins or themes.
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Additional context
|
||||
description: Add any other context, screenshots or Discord conversations about the feature request here. Also if you have any PRs related to this issue that are already open that you would like us to look at.
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Related Issues
|
||||
description: Is there any open or closed issues that is related to this feature request? If so please link them below!
|
||||
10
.github/ISSUE_TEMPLATE/support.md
vendored
10
.github/ISSUE_TEMPLATE/support.md
vendored
|
|
@ -1,10 +0,0 @@
|
|||
---
|
||||
name: Support
|
||||
about: Request support for any problem you're having with Oh My Zsh
|
||||
labels: 'Type: support'
|
||||
|
||||
---
|
||||
|
||||
1. Look for similar issues already posted (including closed ones)
|
||||
2. Include as much relevant information as possible
|
||||
3. Try to make sure the issue is due to Oh My Zsh
|
||||
3
.github/PULL_REQUEST_TEMPLATE.md
vendored
3
.github/PULL_REQUEST_TEMPLATE.md
vendored
|
|
@ -1,5 +1,7 @@
|
|||
## Standards checklist:
|
||||
|
||||
<!-- Fill with an x the ones that apply. Example: [x] -->
|
||||
|
||||
- [ ] 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.
|
||||
|
|
@ -7,6 +9,7 @@
|
|||
- [ ] The code is mine or it's from somewhere with an MIT-compatible license.
|
||||
- [ ] 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.
|
||||
|
||||
## Changes:
|
||||
|
||||
|
|
|
|||
12
.github/dependabot.yml
vendored
Normal file
12
.github/dependabot.yml
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: github-actions
|
||||
directory: /
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
day: "sunday"
|
||||
- package-ecosystem: "pip"
|
||||
directory: "/.github/workflows/dependencies"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
day: "sunday"
|
||||
46
.github/dependencies.yml
vendored
Normal file
46
.github/dependencies.yml
vendored
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
dependencies:
|
||||
plugins/gitfast:
|
||||
repo: felipec/git-completion
|
||||
branch: master
|
||||
version: tag:v2.1
|
||||
postcopy: |
|
||||
set -e
|
||||
rm -rf git-completion.plugin.zsh Makefile README.adoc t tools
|
||||
test -e git-completion.zsh && mv -f git-completion.zsh _git
|
||||
plugins/z:
|
||||
branch: master
|
||||
repo: agkozak/zsh-z
|
||||
version: afaf2965b41fdc6ca66066e09382726aa0b6aa04
|
||||
precopy: |
|
||||
set -e
|
||||
test -e README.md && mv -f README.md MANUAL.md
|
||||
postcopy: |
|
||||
set -e
|
||||
test -e _zshz && mv -f _zshz _z
|
||||
test -e zsh-z.plugin.zsh && mv -f zsh-z.plugin.zsh z.plugin.zsh
|
||||
plugins/history-substring-search:
|
||||
repo: zsh-users/zsh-history-substring-search
|
||||
branch: master
|
||||
version: 87ce96b1862928d84b1afe7c173316614b30e301
|
||||
precopy: |
|
||||
set -e
|
||||
rm -f zsh-history-substring-search.plugin.zsh
|
||||
test -e zsh-history-substring-search.zsh && mv zsh-history-substring-search.zsh history-substring-search.zsh
|
||||
postcopy: |
|
||||
set -e
|
||||
test -e dependencies/OMZ-README.md && cat dependencies/OMZ-README.md >> README.md
|
||||
plugins/gradle:
|
||||
repo: gradle/gradle-completion
|
||||
branch: master
|
||||
version: 25da917cf5a88f3e58f05be3868a7b2748c8afe6
|
||||
precopy: |
|
||||
set -e
|
||||
find . ! -name _gradle ! -name LICENSE -delete
|
||||
plugins/wd:
|
||||
repo: mfaerevaag/wd
|
||||
branch: master
|
||||
version: tag:v0.7.1
|
||||
precopy: |
|
||||
set -e
|
||||
rm -r test
|
||||
rm install.sh tty.gif wd.1
|
||||
36
.github/workflows/dependencies.yml
vendored
Normal file
36
.github/workflows/dependencies.yml
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
name: Update dependencies
|
||||
on:
|
||||
workflow_dispatch: {}
|
||||
schedule:
|
||||
- cron: "0 6 * * 0"
|
||||
|
||||
jobs:
|
||||
check:
|
||||
name: Check for updates
|
||||
runs-on: ubuntu-latest
|
||||
if: github.repository == 'ohmyzsh/ohmyzsh'
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Authenticate as @ohmyzsh
|
||||
id: generate_token
|
||||
uses: ohmyzsh/github-app-token@v2
|
||||
with:
|
||||
app_id: ${{ secrets.OHMYZSH_APP_ID }}
|
||||
private_key: ${{ secrets.OHMYZSH_APP_PRIVATE_KEY }}
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.12"
|
||||
cache: "pip"
|
||||
- name: Process dependencies
|
||||
env:
|
||||
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
|
||||
GIT_APP_NAME: ohmyzsh[bot]
|
||||
GIT_APP_EMAIL: 54982679+ohmyzsh[bot]@users.noreply.github.com
|
||||
TMP_DIR: ${{ runner.temp }}
|
||||
run: |
|
||||
pip install -r .github/workflows/dependencies/requirements.txt
|
||||
python3 .github/workflows/dependencies/updater.py
|
||||
7
.github/workflows/dependencies/requirements.txt
vendored
Normal file
7
.github/workflows/dependencies/requirements.txt
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
certifi==2024.7.4
|
||||
charset-normalizer==3.3.2
|
||||
idna==3.7
|
||||
PyYAML==6.0.1
|
||||
requests==2.32.3
|
||||
semver==3.0.2
|
||||
urllib3==2.2.2
|
||||
598
.github/workflows/dependencies/updater.py
vendored
Normal file
598
.github/workflows/dependencies/updater.py
vendored
Normal file
|
|
@ -0,0 +1,598 @@
|
|||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import timeit
|
||||
from copy import deepcopy
|
||||
from typing import Literal, NotRequired, Optional, TypedDict
|
||||
|
||||
import requests
|
||||
import yaml
|
||||
from semver import Version
|
||||
|
||||
# Get TMP_DIR variable from environment
|
||||
TMP_DIR = os.path.join(os.environ.get("TMP_DIR", "/tmp"), "ohmyzsh")
|
||||
# Relative path to dependencies.yml file
|
||||
DEPS_YAML_FILE = ".github/dependencies.yml"
|
||||
# Dry run flag
|
||||
DRY_RUN = os.environ.get("DRY_RUN", "0") == "1"
|
||||
|
||||
# utils for tag comparison
|
||||
BASEVERSION = re.compile(
|
||||
r"""[vV]?
|
||||
(?P<major>(0|[1-9])\d*)
|
||||
(\.
|
||||
(?P<minor>(0|[1-9])\d*)
|
||||
(\.
|
||||
(?P<patch>(0|[1-9])\d*)
|
||||
)?
|
||||
)?
|
||||
""",
|
||||
re.VERBOSE,
|
||||
)
|
||||
|
||||
|
||||
def coerce(version: str) -> Optional[Version]:
|
||||
match = BASEVERSION.search(version)
|
||||
if not match:
|
||||
return None
|
||||
|
||||
# BASEVERSION looks for `MAJOR.minor.patch` in the string given
|
||||
# it fills with None if any of them is missing (for example `2.1`)
|
||||
ver = {
|
||||
key: 0 if value is None else value for key, value in match.groupdict().items()
|
||||
}
|
||||
# Version takes `major`, `minor`, `patch` arguments
|
||||
ver = Version(**ver) # pyright: ignore[reportArgumentType]
|
||||
return ver
|
||||
|
||||
|
||||
class CodeTimer:
|
||||
def __init__(self, name=None):
|
||||
self.name = " '" + name + "'" if name else ""
|
||||
|
||||
def __enter__(self):
|
||||
self.start = timeit.default_timer()
|
||||
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
self.took = (timeit.default_timer() - self.start) * 1000.0
|
||||
print("Code block" + self.name + " took: " + str(self.took) + " ms")
|
||||
|
||||
|
||||
### YAML representation
|
||||
def str_presenter(dumper, data):
|
||||
"""
|
||||
Configures yaml for dumping multiline strings
|
||||
Ref: https://stackoverflow.com/a/33300001
|
||||
"""
|
||||
if len(data.splitlines()) > 1: # check for multiline string
|
||||
return dumper.represent_scalar("tag:yaml.org,2002:str", data, style="|")
|
||||
return dumper.represent_scalar("tag:yaml.org,2002:str", data)
|
||||
|
||||
|
||||
yaml.add_representer(str, str_presenter)
|
||||
yaml.representer.SafeRepresenter.add_representer(str, str_presenter)
|
||||
|
||||
|
||||
# Types
|
||||
class DependencyDict(TypedDict):
|
||||
repo: str
|
||||
branch: str
|
||||
version: str
|
||||
precopy: NotRequired[str]
|
||||
postcopy: NotRequired[str]
|
||||
|
||||
|
||||
class DependencyYAML(TypedDict):
|
||||
dependencies: dict[str, DependencyDict]
|
||||
|
||||
|
||||
class UpdateStatusFalse(TypedDict):
|
||||
has_updates: Literal[False]
|
||||
|
||||
|
||||
class UpdateStatusTrue(TypedDict):
|
||||
has_updates: Literal[True]
|
||||
version: str
|
||||
compare_url: str
|
||||
head_ref: str
|
||||
head_url: str
|
||||
|
||||
|
||||
class CommandRunner:
|
||||
class Exception(Exception):
|
||||
def __init__(self, message, returncode, stage, stdout, stderr):
|
||||
super().__init__(message)
|
||||
self.returncode = returncode
|
||||
self.stage = stage
|
||||
self.stdout = stdout
|
||||
self.stderr = stderr
|
||||
|
||||
@staticmethod
|
||||
def run_or_fail(command: list[str], stage: str, *args, **kwargs):
|
||||
if DRY_RUN and command[0] == "gh":
|
||||
command.insert(0, "echo")
|
||||
|
||||
result = subprocess.run(command, *args, capture_output=True, **kwargs)
|
||||
|
||||
if result.returncode != 0:
|
||||
raise CommandRunner.Exception(
|
||||
f"{stage} command failed with exit code {result.returncode}",
|
||||
returncode=result.returncode,
|
||||
stage=stage,
|
||||
stdout=result.stdout.decode("utf-8"),
|
||||
stderr=result.stderr.decode("utf-8"),
|
||||
)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
class DependencyStore:
|
||||
store: DependencyYAML = {"dependencies": {}}
|
||||
|
||||
@staticmethod
|
||||
def set(data: DependencyYAML):
|
||||
DependencyStore.store = data
|
||||
|
||||
@staticmethod
|
||||
def update_dependency_version(path: str, version: str) -> DependencyYAML:
|
||||
with CodeTimer(f"store deepcopy: {path}"):
|
||||
store_copy = deepcopy(DependencyStore.store)
|
||||
|
||||
dependency = store_copy["dependencies"].get(path)
|
||||
if dependency is None:
|
||||
raise ValueError(f"Dependency {path} {version} not found")
|
||||
dependency["version"] = version
|
||||
store_copy["dependencies"][path] = dependency
|
||||
|
||||
return store_copy
|
||||
|
||||
@staticmethod
|
||||
def write_store(file: str, data: DependencyYAML):
|
||||
with open(file, "w") as yaml_file:
|
||||
yaml.safe_dump(data, yaml_file, sort_keys=False)
|
||||
|
||||
|
||||
class Dependency:
|
||||
def __init__(self, path: str, values: DependencyDict):
|
||||
self.path = path
|
||||
self.values = values
|
||||
|
||||
self.name: str = ""
|
||||
self.desc: str = ""
|
||||
self.kind: str = ""
|
||||
|
||||
match path.split("/"):
|
||||
case ["plugins", name]:
|
||||
self.name = name
|
||||
self.kind = "plugin"
|
||||
self.desc = f"{name} plugin"
|
||||
case ["themes", name]:
|
||||
self.name = name.replace(".zsh-theme", "")
|
||||
self.kind = "theme"
|
||||
self.desc = f"{self.name} theme"
|
||||
case _:
|
||||
self.name = self.desc = path
|
||||
|
||||
def __str__(self):
|
||||
output: str = ""
|
||||
for key in DependencyDict.__dict__["__annotations__"].keys():
|
||||
if key not in self.values:
|
||||
output += f"{key}: None\n"
|
||||
continue
|
||||
|
||||
value = self.values[key]
|
||||
if "\n" not in value:
|
||||
output += f"{key}: {value}\n"
|
||||
else:
|
||||
output += f"{key}:\n "
|
||||
output += value.replace("\n", "\n ", value.count("\n") - 1)
|
||||
return output
|
||||
|
||||
def update_or_notify(self):
|
||||
# Print dependency settings
|
||||
print(f"Processing {self.desc}...", file=sys.stderr)
|
||||
print(self, file=sys.stderr)
|
||||
|
||||
# Check for updates
|
||||
repo = self.values["repo"]
|
||||
remote_branch = self.values["branch"]
|
||||
version = self.values["version"]
|
||||
is_tag = version.startswith("tag:")
|
||||
|
||||
try:
|
||||
with CodeTimer(f"update check: {repo}"):
|
||||
if is_tag:
|
||||
status = GitHub.check_newer_tag(repo, version.replace("tag:", ""))
|
||||
else:
|
||||
status = GitHub.check_updates(repo, remote_branch, version)
|
||||
|
||||
if status["has_updates"] is True:
|
||||
short_sha = status["head_ref"][:8]
|
||||
new_version = status["version"] if is_tag else short_sha
|
||||
|
||||
try:
|
||||
branch_name = f"update/{self.path}/{new_version}"
|
||||
|
||||
# Create new branch
|
||||
branch = Git.checkout_or_create_branch(branch_name)
|
||||
|
||||
# Update dependencies.yml file
|
||||
self.__update_yaml(
|
||||
f"tag:{new_version}" if is_tag else status["version"]
|
||||
)
|
||||
|
||||
# Update dependency files
|
||||
self.__apply_upstream_changes()
|
||||
|
||||
# Add all changes and commit
|
||||
has_new_commit = Git.add_and_commit(self.name, short_sha)
|
||||
|
||||
if has_new_commit:
|
||||
# Push changes to remote
|
||||
Git.push(branch)
|
||||
|
||||
# Create GitHub PR
|
||||
GitHub.create_pr(
|
||||
branch,
|
||||
f"feat({self.name}): update to version {new_version}",
|
||||
f"""## Description
|
||||
|
||||
Update for **{self.desc}**: update to version [{new_version}]({status['head_url']}).
|
||||
Check out the [list of changes]({status['compare_url']}).
|
||||
""",
|
||||
)
|
||||
|
||||
# Clean up repository
|
||||
Git.clean_repo()
|
||||
except (CommandRunner.Exception, shutil.Error) as e:
|
||||
# Handle exception on automatic update
|
||||
match type(e):
|
||||
case CommandRunner.Exception:
|
||||
# Print error message
|
||||
print(
|
||||
f"Error running {e.stage} command: {e.returncode}", # pyright: ignore[reportAttributeAccessIssue]
|
||||
file=sys.stderr,
|
||||
)
|
||||
print(e.stderr, file=sys.stderr) # pyright: ignore[reportAttributeAccessIssue]
|
||||
case shutil.Error:
|
||||
print(f"Error copying files: {e}", file=sys.stderr)
|
||||
|
||||
try:
|
||||
Git.clean_repo()
|
||||
except CommandRunner.Exception as e:
|
||||
print(
|
||||
f"Error reverting repository to clean state: {e}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
# Create a GitHub issue to notify maintainer
|
||||
title = f"{self.path}: update to {new_version}"
|
||||
body = f"""## Description
|
||||
|
||||
There is a new version of `{self.name}` {self.kind} available.
|
||||
|
||||
New version: [{new_version}]({status['head_url']})
|
||||
Check out the [list of changes]({status['compare_url']}).
|
||||
"""
|
||||
|
||||
print("Creating GitHub issue", file=sys.stderr)
|
||||
print(f"{title}\n\n{body}", file=sys.stderr)
|
||||
GitHub.create_issue(title, body)
|
||||
except Exception as e:
|
||||
print(e, file=sys.stderr)
|
||||
|
||||
def __update_yaml(self, new_version: str) -> None:
|
||||
dep_yaml = DependencyStore.update_dependency_version(self.path, new_version)
|
||||
DependencyStore.write_store(DEPS_YAML_FILE, dep_yaml)
|
||||
|
||||
def __apply_upstream_changes(self) -> None:
|
||||
# Patterns to ignore in copying files from upstream repo
|
||||
GLOBAL_IGNORE = [".git", ".github", ".gitignore"]
|
||||
|
||||
path = os.path.abspath(self.path)
|
||||
precopy = self.values.get("precopy")
|
||||
postcopy = self.values.get("postcopy")
|
||||
|
||||
repo = self.values["repo"]
|
||||
branch = self.values["branch"]
|
||||
remote_url = f"https://github.com/{repo}.git"
|
||||
repo_dir = os.path.join(TMP_DIR, repo)
|
||||
|
||||
# Clone repository
|
||||
Git.clone(remote_url, branch, repo_dir, reclone=True)
|
||||
|
||||
# Run precopy on tmp repo
|
||||
if precopy is not None:
|
||||
print("Running precopy script:", end="\n ", file=sys.stderr)
|
||||
print(
|
||||
precopy.replace("\n", "\n ", precopy.count("\n") - 1), file=sys.stderr
|
||||
)
|
||||
CommandRunner.run_or_fail(
|
||||
["bash", "-c", precopy], cwd=repo_dir, stage="Precopy"
|
||||
)
|
||||
|
||||
# Copy files from upstream repo
|
||||
print(f"Copying files from {repo_dir} to {path}", file=sys.stderr)
|
||||
shutil.copytree(
|
||||
repo_dir,
|
||||
path,
|
||||
dirs_exist_ok=True,
|
||||
ignore=shutil.ignore_patterns(*GLOBAL_IGNORE),
|
||||
)
|
||||
|
||||
# Run postcopy on our repository
|
||||
if postcopy is not None:
|
||||
print("Running postcopy script:", end="\n ", file=sys.stderr)
|
||||
print(
|
||||
postcopy.replace("\n", "\n ", postcopy.count("\n") - 1),
|
||||
file=sys.stderr,
|
||||
)
|
||||
CommandRunner.run_or_fail(
|
||||
["bash", "-c", postcopy], cwd=path, stage="Postcopy"
|
||||
)
|
||||
|
||||
|
||||
class Git:
|
||||
default_branch = "master"
|
||||
|
||||
@staticmethod
|
||||
def clone(remote_url: str, branch: str, repo_dir: str, reclone=False):
|
||||
# If repo needs to be fresh
|
||||
if reclone and os.path.exists(repo_dir):
|
||||
shutil.rmtree(repo_dir)
|
||||
|
||||
# Clone repo in tmp directory and checkout branch
|
||||
if not os.path.exists(repo_dir):
|
||||
print(
|
||||
f"Cloning {remote_url} to {repo_dir} and checking out {branch}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
CommandRunner.run_or_fail(
|
||||
["git", "clone", "--depth=1", "-b", branch, remote_url, repo_dir],
|
||||
stage="Clone",
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def checkout_or_create_branch(branch_name: str):
|
||||
# Get current branch name
|
||||
result = CommandRunner.run_or_fail(
|
||||
["git", "rev-parse", "--abbrev-ref", "HEAD"], stage="GetDefaultBranch"
|
||||
)
|
||||
Git.default_branch = result.stdout.decode("utf-8").strip()
|
||||
|
||||
# Create new branch and return created branch name
|
||||
try:
|
||||
# try to checkout already existing branch
|
||||
CommandRunner.run_or_fail(
|
||||
["git", "checkout", branch_name], stage="CreateBranch"
|
||||
)
|
||||
except CommandRunner.Exception:
|
||||
# otherwise create new branch
|
||||
CommandRunner.run_or_fail(
|
||||
["git", "checkout", "-b", branch_name], stage="CreateBranch"
|
||||
)
|
||||
return branch_name
|
||||
|
||||
@staticmethod
|
||||
def add_and_commit(scope: str, version: str) -> bool:
|
||||
"""
|
||||
Returns `True` if there were changes and were indeed commited.
|
||||
Returns `False` if the repo was clean and no changes were commited.
|
||||
"""
|
||||
# check if repo is clean (clean => no error, no commit)
|
||||
try:
|
||||
CommandRunner.run_or_fail(
|
||||
["git", "diff", "--exit-code"], stage="CheckRepoClean"
|
||||
)
|
||||
return False
|
||||
except CommandRunner.Exception:
|
||||
# if it's other kind of error just throw!
|
||||
pass
|
||||
|
||||
user_name = os.environ.get("GIT_APP_NAME")
|
||||
user_email = os.environ.get("GIT_APP_EMAIL")
|
||||
|
||||
# Add all files to git staging
|
||||
CommandRunner.run_or_fail(["git", "add", "-A", "-v"], stage="AddFiles")
|
||||
|
||||
# Reset environment and git config
|
||||
clean_env = os.environ.copy()
|
||||
clean_env["LANG"] = "C.UTF-8"
|
||||
clean_env["GIT_CONFIG_GLOBAL"] = "/dev/null"
|
||||
clean_env["GIT_CONFIG_NOSYSTEM"] = "1"
|
||||
|
||||
# Commit with settings above
|
||||
CommandRunner.run_or_fail(
|
||||
[
|
||||
"git",
|
||||
"-c",
|
||||
f"user.name={user_name}",
|
||||
"-c",
|
||||
f"user.email={user_email}",
|
||||
"commit",
|
||||
"-m",
|
||||
f"feat({scope}): update to {version}",
|
||||
],
|
||||
stage="CreateCommit",
|
||||
env=clean_env,
|
||||
)
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def push(branch: str):
|
||||
CommandRunner.run_or_fail(
|
||||
["git", "push", "-u", "origin", branch], stage="PushBranch"
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def clean_repo():
|
||||
CommandRunner.run_or_fail(
|
||||
["git", "reset", "--hard", "HEAD"], stage="ResetRepository"
|
||||
)
|
||||
CommandRunner.run_or_fail(
|
||||
["git", "checkout", Git.default_branch], stage="CheckoutDefaultBranch"
|
||||
)
|
||||
|
||||
|
||||
class GitHub:
|
||||
@staticmethod
|
||||
def check_newer_tag(repo, current_tag) -> UpdateStatusFalse | UpdateStatusTrue:
|
||||
# GET /repos/:owner/:repo/git/refs/tags
|
||||
url = f"https://api.github.com/repos/{repo}/git/refs/tags"
|
||||
|
||||
# Send a GET request to the GitHub API
|
||||
response = requests.get(url)
|
||||
current_version = coerce(current_tag)
|
||||
if current_version is None:
|
||||
raise ValueError(
|
||||
f"Stored {current_version} from {repo} does not follow semver"
|
||||
)
|
||||
|
||||
# If the request was successful
|
||||
if response.status_code == 200:
|
||||
# Parse the JSON response
|
||||
data = response.json()
|
||||
|
||||
if len(data) == 0:
|
||||
return {
|
||||
"has_updates": False,
|
||||
}
|
||||
|
||||
latest_ref = None
|
||||
latest_version: Optional[Version] = None
|
||||
for ref in data:
|
||||
# we find the tag since GitHub returns it as plain git ref
|
||||
tag_version = coerce(ref["ref"].replace("refs/tags/", ""))
|
||||
if tag_version is None:
|
||||
# we skip every tag that is not semver-complaint
|
||||
continue
|
||||
if latest_version is None or tag_version.compare(latest_version) > 0:
|
||||
# if we have a "greater" semver version, set it as latest
|
||||
latest_version = tag_version
|
||||
latest_ref = ref
|
||||
|
||||
# raise if no valid semver tag is found
|
||||
if latest_ref is None or latest_version is None:
|
||||
raise ValueError(f"No tags following semver found in {repo}")
|
||||
|
||||
# we get the tag since GitHub returns it as plain git ref
|
||||
latest_tag = latest_ref["ref"].replace("refs/tags/", "")
|
||||
|
||||
if latest_version.compare(current_version) <= 0:
|
||||
return {
|
||||
"has_updates": False,
|
||||
}
|
||||
|
||||
return {
|
||||
"has_updates": True,
|
||||
"version": latest_tag,
|
||||
"compare_url": f"https://github.com/{repo}/compare/{current_tag}...{latest_tag}",
|
||||
"head_ref": latest_ref["object"]["sha"],
|
||||
"head_url": f"https://github.com/{repo}/releases/tag/{latest_tag}",
|
||||
}
|
||||
else:
|
||||
# If the request was not successful, raise an exception
|
||||
raise Exception(
|
||||
f"GitHub API request failed with status code {response.status_code}: {response.json()}"
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def check_updates(repo, branch, version) -> UpdateStatusFalse | UpdateStatusTrue:
|
||||
url = f"https://api.github.com/repos/{repo}/compare/{version}...{branch}"
|
||||
|
||||
# Send a GET request to the GitHub API
|
||||
response = requests.get(url)
|
||||
|
||||
# If the request was successful
|
||||
if response.status_code == 200:
|
||||
# Parse the JSON response
|
||||
data = response.json()
|
||||
|
||||
# If the base is behind the head, there is a newer version
|
||||
has_updates = data["status"] != "identical"
|
||||
|
||||
if not has_updates:
|
||||
return {
|
||||
"has_updates": False,
|
||||
}
|
||||
|
||||
return {
|
||||
"has_updates": data["status"] != "identical",
|
||||
"version": data["commits"][-1]["sha"],
|
||||
"compare_url": data["permalink_url"],
|
||||
"head_ref": data["commits"][-1]["sha"],
|
||||
"head_url": data["commits"][-1]["html_url"],
|
||||
}
|
||||
else:
|
||||
# If the request was not successful, raise an exception
|
||||
raise Exception(
|
||||
f"GitHub API request failed with status code {response.status_code}: {response.json()}"
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def create_issue(title: str, body: str) -> None:
|
||||
cmd = ["gh", "issue", "create", "-t", title, "-b", body]
|
||||
CommandRunner.run_or_fail(cmd, stage="CreateIssue")
|
||||
|
||||
@staticmethod
|
||||
def create_pr(branch: str, title: str, body: str) -> None:
|
||||
# first of all let's check if PR is already open
|
||||
check_cmd = [
|
||||
"gh",
|
||||
"pr",
|
||||
"list",
|
||||
"--state",
|
||||
"open",
|
||||
"--head",
|
||||
branch,
|
||||
"--json",
|
||||
"title",
|
||||
]
|
||||
# returncode is 0 also if no PRs are found
|
||||
output = json.loads(
|
||||
CommandRunner.run_or_fail(check_cmd, stage="CheckPullRequestOpen")
|
||||
.stdout.decode("utf-8")
|
||||
.strip()
|
||||
)
|
||||
# we have PR in this case!
|
||||
if len(output) > 0:
|
||||
return
|
||||
cmd = [
|
||||
"gh",
|
||||
"pr",
|
||||
"create",
|
||||
"-B",
|
||||
Git.default_branch,
|
||||
"-H",
|
||||
branch,
|
||||
"-t",
|
||||
title,
|
||||
"-b",
|
||||
body,
|
||||
]
|
||||
CommandRunner.run_or_fail(cmd, stage="CreatePullRequest")
|
||||
|
||||
|
||||
def main():
|
||||
# Load the YAML file
|
||||
with open(DEPS_YAML_FILE, "r") as yaml_file:
|
||||
data: DependencyYAML = yaml.safe_load(yaml_file)
|
||||
|
||||
if "dependencies" not in data:
|
||||
raise Exception("dependencies.yml not properly formatted")
|
||||
|
||||
# Cache YAML version
|
||||
DependencyStore.set(data)
|
||||
|
||||
dependencies = data["dependencies"]
|
||||
for path in dependencies:
|
||||
dependency = Dependency(path, dependencies[path])
|
||||
dependency.update_or_notify()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
56
.github/workflows/installer.yml
vendored
Normal file
56
.github/workflows/installer.yml
vendored
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
name: Test and Deploy installer
|
||||
on:
|
||||
workflow_dispatch: {}
|
||||
push:
|
||||
paths:
|
||||
- 'tools/install.sh'
|
||||
- '.github/workflows/installer/**'
|
||||
- '.github/workflows/installer.yml'
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
||||
cancel-in-progress: false
|
||||
|
||||
permissions:
|
||||
contents: read # to checkout
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Test installer
|
||||
if: github.repository == 'ohmyzsh/ohmyzsh'
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os:
|
||||
- ubuntu-latest
|
||||
- macos-latest
|
||||
steps:
|
||||
- name: Set up git repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Install zsh
|
||||
if: runner.os == 'Linux'
|
||||
run: sudo apt-get update; sudo apt-get install zsh
|
||||
- name: Test installer
|
||||
run: sh ./tools/install.sh
|
||||
|
||||
deploy:
|
||||
name: Deploy installer in install.ohmyz.sh
|
||||
if: github.ref == 'refs/heads/master'
|
||||
runs-on: ubuntu-latest
|
||||
environment: vercel
|
||||
needs:
|
||||
- test
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Install Vercel CLI
|
||||
run: npm install -g vercel
|
||||
- name: Setup project and deploy
|
||||
env:
|
||||
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
|
||||
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
|
||||
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
|
||||
run: |
|
||||
cp tools/install.sh .github/workflows/installer/install.sh
|
||||
cd .github/workflows/installer
|
||||
vc deploy --prod -t "$VERCEL_TOKEN"
|
||||
1
.github/workflows/installer/.gitignore
vendored
Normal file
1
.github/workflows/installer/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
install.sh
|
||||
2
.github/workflows/installer/.vercelignore
vendored
Normal file
2
.github/workflows/installer/.vercelignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
/*
|
||||
!/install.sh
|
||||
23
.github/workflows/installer/vercel.json
vendored
Normal file
23
.github/workflows/installer/vercel.json
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"headers": [
|
||||
{
|
||||
"source": "/((?!favicon.ico).*)",
|
||||
"headers": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"value": "text/plain"
|
||||
},
|
||||
{
|
||||
"key": "Content-Disposition",
|
||||
"value": "inline; filename=\"install.sh\""
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"rewrites": [
|
||||
{
|
||||
"source": "/((?!favicon.ico|install.sh).*)",
|
||||
"destination": "/install.sh"
|
||||
}
|
||||
]
|
||||
}
|
||||
20
.github/workflows/main.yml
vendored
20
.github/workflows/main.yml
vendored
|
|
@ -7,24 +7,26 @@ on:
|
|||
branches:
|
||||
- master
|
||||
push:
|
||||
branches:
|
||||
branches:
|
||||
- master
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
||||
cancel-in-progress: true
|
||||
|
||||
permissions:
|
||||
contents: read # to fetch code (actions/checkout)
|
||||
|
||||
jobs:
|
||||
tests:
|
||||
name: Run tests
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest]
|
||||
runs-on: ubuntu-latest
|
||||
if: github.repository == 'ohmyzsh/ohmyzsh'
|
||||
steps:
|
||||
- name: Set up git repository
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v4
|
||||
- name: Install zsh
|
||||
if: runner.os == 'Linux'
|
||||
run: sudo apt-get update; sudo apt-get install zsh
|
||||
- name: Test installer
|
||||
run: sh ./tools/install.sh
|
||||
- name: Check syntax
|
||||
run: |
|
||||
for file in ./oh-my-zsh.sh \
|
||||
|
|
|
|||
146
.github/workflows/project.yml
vendored
Normal file
146
.github/workflows/project.yml
vendored
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
name: Project tracking
|
||||
on:
|
||||
issues:
|
||||
types: [opened, reopened]
|
||||
pull_request_target:
|
||||
types: [opened, reopened, synchronize]
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
||||
cancel-in-progress: true
|
||||
|
||||
permissions: {}
|
||||
jobs:
|
||||
add-to-project:
|
||||
name: Add to project
|
||||
runs-on: ubuntu-latest
|
||||
if: github.repository == 'ohmyzsh/ohmyzsh'
|
||||
steps:
|
||||
- name: Authenticate as @ohmyzsh
|
||||
id: generate_token
|
||||
uses: ohmyzsh/github-app-token@v2
|
||||
with:
|
||||
app_id: ${{ secrets.OHMYZSH_APP_ID }}
|
||||
private_key: ${{ secrets.OHMYZSH_APP_PRIVATE_KEY }}
|
||||
- name: Store app token
|
||||
run: echo "GH_TOKEN=${{ steps.generate_token.outputs.token }}" >> "$GITHUB_ENV"
|
||||
- name: Read project data
|
||||
env:
|
||||
ORGANIZATION: ohmyzsh
|
||||
PROJECT_NUMBER: "1"
|
||||
run: |
|
||||
# Get Project data
|
||||
gh api graphql -f query='
|
||||
query($org: String!, $number: Int!) {
|
||||
organization(login: $org){
|
||||
projectV2(number: $number) {
|
||||
id
|
||||
fields(first:20) {
|
||||
nodes {
|
||||
... on ProjectV2Field {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json
|
||||
|
||||
# Parse project data
|
||||
cat >> $GITHUB_ENV <<EOF
|
||||
PROJECT_ID=$(jq '.data.organization.projectV2.id' project_data.json)
|
||||
PLUGIN_FIELD_ID=$(jq '.data.organization.projectV2.fields.nodes[] | select(.name == "Plugin") | .id' project_data.json)
|
||||
THEME_FIELD_ID=$(jq '.data.organization.projectV2.fields.nodes[] | select(.name == "Theme") | .id' project_data.json)
|
||||
EOF
|
||||
|
||||
- name: Add to project
|
||||
env:
|
||||
ISSUE_OR_PR_ID: ${{ github.event.issue.node_id || github.event.pull_request.node_id }}
|
||||
run: |
|
||||
item_id="$(gh api graphql -f query='
|
||||
mutation($project: ID!, $content: ID!) {
|
||||
addProjectV2ItemById(input: {projectId: $project, contentId: $content}) {
|
||||
item {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
' -f project=$PROJECT_ID -f content=$ISSUE_OR_PR_ID --jq '.data.addProjectV2ItemById.item.id')"
|
||||
|
||||
echo "ITEM_ID=$item_id" >> $GITHUB_ENV
|
||||
|
||||
- name: Classify Pull Request
|
||||
if: github.event_name == 'pull_request_target'
|
||||
run: |
|
||||
touch plugins.list themes.list
|
||||
|
||||
gh pr view ${{ github.event.pull_request.number }} \
|
||||
--repo ${{ github.repository }} \
|
||||
--json files --jq '.files.[].path' | awk -F/ '
|
||||
/^plugins\// {
|
||||
plugins[$2] = 1
|
||||
}
|
||||
/^themes\// {
|
||||
gsub(/\.zsh-theme$/, "", $2)
|
||||
themes[$2] = 1
|
||||
}
|
||||
END {
|
||||
for (plugin in plugins) {
|
||||
print plugin >> "plugins.list"
|
||||
}
|
||||
for (theme in themes) {
|
||||
print theme >> "themes.list"
|
||||
}
|
||||
}
|
||||
'
|
||||
# If only one plugin is modified, add it to the plugin field
|
||||
if [[ $(wc -l < plugins.list) = 1 ]]; then
|
||||
echo "PLUGIN=$(cat plugins.list)" >> $GITHUB_ENV
|
||||
fi
|
||||
# If only one theme is modified, add it to the theme field
|
||||
if [[ $(wc -l < themes.list) = 1 ]]; then
|
||||
echo "THEME=$(cat themes.list)" >> $GITHUB_ENV
|
||||
fi
|
||||
|
||||
- name: Fill Pull Request fields in project
|
||||
if: github.event_name == 'pull_request_target'
|
||||
run: |
|
||||
gh api graphql -f query='
|
||||
mutation (
|
||||
$project: ID!
|
||||
$item: ID!
|
||||
$plugin_field: ID!
|
||||
$plugin_value: String!
|
||||
$theme_field: ID!
|
||||
$theme_value: String!
|
||||
) {
|
||||
set_plugin: updateProjectV2ItemFieldValue(input: {
|
||||
projectId: $project
|
||||
itemId: $item
|
||||
fieldId: $plugin_field
|
||||
value: {
|
||||
text: $plugin_value
|
||||
}
|
||||
}) {
|
||||
projectV2Item {
|
||||
id
|
||||
}
|
||||
}
|
||||
set_theme: updateProjectV2ItemFieldValue(input: {
|
||||
projectId: $project
|
||||
itemId: $item
|
||||
fieldId: $theme_field
|
||||
value: {
|
||||
text: $theme_value
|
||||
}
|
||||
}) {
|
||||
projectV2Item {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
' -f project=$PROJECT_ID -f item=$ITEM_ID \
|
||||
-f plugin_field=$PLUGIN_FIELD_ID -f plugin_value=$PLUGIN \
|
||||
-f theme_field=$THEME_FIELD_ID -f theme_value=$THEME \
|
||||
--silent
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -6,3 +6,7 @@ cache/
|
|||
log/
|
||||
*.swp
|
||||
.DS_Store
|
||||
|
||||
# editor configs
|
||||
.vscode
|
||||
.idea
|
||||
|
|
|
|||
5
.gitpod.Dockerfile
vendored
Normal file
5
.gitpod.Dockerfile
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
FROM gitpod/workspace-full
|
||||
|
||||
RUN sudo apt-get update && \
|
||||
sudo apt-get install -y zsh && \
|
||||
sudo rm -rf /var/lib/apt/lists/*
|
||||
9
.gitpod.yml
Normal file
9
.gitpod.yml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
image:
|
||||
file: .gitpod.Dockerfile
|
||||
|
||||
tasks:
|
||||
- init: |
|
||||
export EDITOR="command gp open -w" VISUAL="command gp open -w"
|
||||
cp -f /workspace/ohmyzsh/templates/zshrc.zsh-template ~/.zshrc
|
||||
ln -sf /workspace/ohmyzsh ~/.oh-my-zsh
|
||||
command: exec zsh
|
||||
4
.prettierrc
Normal file
4
.prettierrc
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"printWidth": 110,
|
||||
"proseWrap": "always"
|
||||
}
|
||||
156
CONTRIBUTING.md
156
CONTRIBUTING.md
|
|
@ -11,16 +11,22 @@ issues and pull requests. Please read them closely.
|
|||
Foremost, be so kind as to [search](#use-the-search-luke). This ensures any contribution
|
||||
you would make is not already covered.
|
||||
|
||||
* [Issues](#reporting-issues)
|
||||
* [You have a problem](#you-have-a-problem)
|
||||
* [You have a suggestion](#you-have-a-suggestion)
|
||||
* [Pull Requests](#submitting-pull-requests)
|
||||
* [Getting started](#getting-started)
|
||||
* [You have a solution](#you-have-a-solution)
|
||||
* [You have an addition](#you-have-an-addition)
|
||||
* [Information sources (_aka_ search)](#use-the-search-luke)
|
||||
<!-- TOC updateonsave:true depthfrom:2 -->
|
||||
|
||||
**BONUS:** [Volunteering](#you-have-spare-time-to-volunteer)
|
||||
- [Reporting Issues](#reporting-issues)
|
||||
- [You have a problem](#you-have-a-problem)
|
||||
- [You have a suggestion](#you-have-a-suggestion)
|
||||
- [Submitting Pull Requests](#submitting-pull-requests)
|
||||
- [Getting started](#getting-started)
|
||||
- [You have a solution](#you-have-a-solution)
|
||||
- [You have an addition](#you-have-an-addition)
|
||||
- [Use the Search, Luke](#use-the-search-luke)
|
||||
- [Commit Guidelines](#commit-guidelines)
|
||||
- [Format](#format)
|
||||
- [Style](#style)
|
||||
- [Volunteer](#volunteer)
|
||||
|
||||
<!-- /TOC -->
|
||||
|
||||
## Reporting Issues
|
||||
|
||||
|
|
@ -29,19 +35,19 @@ you would make is not already covered.
|
|||
Please be so kind as to [search](#use-the-search-luke) for any open issue already covering
|
||||
your problem.
|
||||
|
||||
If you find one, comment on it so we can know there are more people experiencing it.
|
||||
If you find one, comment on it, so we know more people are experiencing it.
|
||||
|
||||
If not, look at the [Troubleshooting](https://github.com/ohmyzsh/ohmyzsh/wiki/Troubleshooting)
|
||||
page for instructions on how to gather data to better debug your problem.
|
||||
|
||||
Then, you can go ahead and create an issue with as much detail as you can provide.
|
||||
It should include the data gathered as indicated above, along with:
|
||||
It should include the data gathered as indicated above, along with the following:
|
||||
|
||||
1. How to reproduce the problem
|
||||
2. What the correct behavior should be
|
||||
3. What the actual behavior is
|
||||
|
||||
Please copy to anyone relevant (_eg_ plugin maintainers) by mentioning their GitHub handle
|
||||
Please copy to anyone relevant (e.g. plugin maintainers) by mentioning their GitHub handle
|
||||
(starting with `@`) in your message.
|
||||
|
||||
We will do our very best to help you.
|
||||
|
|
@ -51,9 +57,9 @@ We will do our very best to help you.
|
|||
Please be so kind as to [search](#use-the-search-luke) for any open issue already covering
|
||||
your suggestion.
|
||||
|
||||
If you find one, comment on it so we can know there are more people supporting it.
|
||||
If you find one, comment on it, so we know more people are supporting it.
|
||||
|
||||
If not, you can go ahead and create an issue. Please copy to anyone relevant (_eg_ plugin
|
||||
If not, you can go ahead and create an issue. Please copy to anyone relevant (e.g. plugin
|
||||
maintainers) by mentioning their GitHub handle (starting with `@`) in your message.
|
||||
|
||||
## Submitting Pull Requests
|
||||
|
|
@ -78,7 +84,7 @@ your [problem](#you-have-a-problem), and any pending/merged/rejected PR covering
|
|||
|
||||
If the solution is already reported, try it out and +1 the pull request if the
|
||||
solution works ok. On the other hand, if you think your solution is better, post
|
||||
it with a reference to the other one so we can have both solutions to compare.
|
||||
it with reference to the other one so we can have both solutions to compare.
|
||||
|
||||
If not, then go ahead and submit a PR. Please copy to anyone relevant (e.g. plugin
|
||||
maintainers) by mentioning their GitHub handle (starting with `@`) in your message.
|
||||
|
|
@ -93,10 +99,31 @@ covering or related to what you want to add.
|
|||
|
||||
If you find one, try it out and work with the author on a common solution.
|
||||
|
||||
If not, then go ahead and submit a PR. Please copy to anyone relevant (_eg_ plugin
|
||||
If not, then go ahead and submit a PR. Please copy to anyone relevant (e.g. plugin
|
||||
maintainers) by mentioning their GitHub handle (starting with `@`) in your message.
|
||||
|
||||
For any extensive change, _eg_ a new plugin, you will have to find testers to +1 your PR.
|
||||
For any extensive change, such as a new plugin, you will have to find testers to +1 your PR.
|
||||
|
||||
### New plugin aliases
|
||||
|
||||
We acknowledge that aliases are a core part of Oh My Zsh. There are plugins that have +100 aliases!
|
||||
|
||||
This has become an issue for two opposing reasons:
|
||||
|
||||
- Some users want to have their personal aliases in Oh My Zsh.
|
||||
- Some users don't want any aliases at all and feel that there are too many.
|
||||
|
||||
Because of this, from now on, we require that new aliases follow these conditions:
|
||||
|
||||
1. They will be used by many people, not just a few.
|
||||
2. The aliases will be used many times and for common tasks.
|
||||
3. Prefer one generic alias over many specific ones.
|
||||
4. When justifying the need for an alias, talk about workflows where you'll use it,
|
||||
preferably in combination with other aliases.
|
||||
5. If a command with the same name exists, look for a different alias name.
|
||||
|
||||
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.
|
||||
|
||||
----
|
||||
|
||||
|
|
@ -117,7 +144,100 @@ and [create an issue](#reporting-issues) or [submit a PR](#submitting-pull-reque
|
|||
|
||||
----
|
||||
|
||||
### You have spare time to volunteer
|
||||
## Commit Guidelines
|
||||
|
||||
Oh My Zsh uses the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)
|
||||
specification. The automatic changelog tool uses these to automatically generate
|
||||
a changelog based on the commit messages. Here's a guide to writing a commit message
|
||||
to allow this:
|
||||
|
||||
### Format
|
||||
|
||||
```
|
||||
type(scope)!: subject
|
||||
```
|
||||
|
||||
- `type`: the type of the commit is one of the following:
|
||||
|
||||
- `feat`: new features.
|
||||
- `fix`: bug fixes.
|
||||
- `docs`: documentation changes.
|
||||
- `refactor`: refactor of a particular code section without introducing
|
||||
new features or bug fixes.
|
||||
- `style`: code style improvements.
|
||||
- `perf`: performance improvements.
|
||||
- `test`: changes to the test suite.
|
||||
- `ci`: changes to the CI system.
|
||||
- `build`: changes to the build system (we don't yet have one so this shouldn't apply).
|
||||
- `chore`: for other changes that don't match previous types. This doesn't appear
|
||||
in the changelog.
|
||||
|
||||
- `scope`: section of the codebase that the commit makes changes to. If it makes changes to
|
||||
many sections, or if no section in particular is modified, leave blank without the parentheses.
|
||||
Examples:
|
||||
|
||||
- Commit that changes the `git` plugin:
|
||||
```
|
||||
feat(git): add alias for `git commit`
|
||||
```
|
||||
|
||||
- Commit that changes many plugins:
|
||||
```
|
||||
style: fix inline declaration of arrays
|
||||
```
|
||||
|
||||
For changes to plugins or themes, the scope should be the plugin or theme name:
|
||||
|
||||
- ✅ `fix(agnoster): commit subject`
|
||||
- ❌ `fix(theme/agnoster): commit subject`
|
||||
|
||||
- `!`: this goes after the `scope` (or the `type` if scope is empty), to indicate that the commit
|
||||
introduces breaking changes.
|
||||
|
||||
Optionally, you can specify a message that the changelog tool will display to the user to indicate
|
||||
what's changed and what they can do to deal with it. You can use multiple lines to type this message;
|
||||
the changelog parser will keep reading until the end of the commit message or until it finds an empty
|
||||
line.
|
||||
|
||||
Example (made up):
|
||||
|
||||
```
|
||||
style(agnoster)!: change dirty git repo glyph
|
||||
|
||||
BREAKING CHANGE: the glyph to indicate when a git repository is dirty has
|
||||
changed from a Powerline character to a standard UTF-8 emoji. You can
|
||||
change it back by setting `ZSH_THEME_DIRTY_GLYPH`.
|
||||
|
||||
Fixes #420
|
||||
|
||||
Co-authored-by: Username <email>
|
||||
```
|
||||
|
||||
- `subject`: a brief description of the changes. This will be displayed in the changelog. If you need
|
||||
to specify other details, you can use the commit body, but it won't be visible.
|
||||
|
||||
Formatting tricks: the commit subject may contain:
|
||||
|
||||
- Links to related issues or PRs by writing `#issue`. This will be highlighted by the changelog tool:
|
||||
```
|
||||
feat(archlinux): add support for aura AUR helper (#9467)
|
||||
```
|
||||
|
||||
- Formatted inline code by using backticks: the text between backticks will also be highlighted by
|
||||
the changelog tool:
|
||||
```
|
||||
feat(shell-proxy): enable unexported `DEFAULT_PROXY` setting (#9774)
|
||||
```
|
||||
|
||||
### Style
|
||||
|
||||
Try to keep the first commit line short. It's harder to do using this commit style but try to be
|
||||
concise, and if you need more space, you can use the commit body. Try to make sure that the commit
|
||||
subject is clear and precise enough that users will know what changed by just looking at the changelog.
|
||||
|
||||
----
|
||||
|
||||
## Volunteer
|
||||
|
||||
Very nice!! :)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2009-2020 Robby Russell and contributors (https://github.com/ohmyzsh/ohmyzsh/contributors)
|
||||
Copyright (c) 2009-2022 Robby Russell and contributors (https://github.com/ohmyzsh/ohmyzsh/contributors)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
|||
323
README.md
323
README.md
|
|
@ -1,59 +1,117 @@
|
|||
<p align="center">
|
||||
<img src="https://s3.amazonaws.com/ohmyzsh/oh-my-zsh-logo.png" alt="Oh My Zsh">
|
||||
</p>
|
||||
<p align="center"><img src="https://ohmyzsh.s3.amazonaws.com/omz-ansi-github.png" alt="Oh My Zsh"></p>
|
||||
|
||||
Oh My Zsh is an open source, community-driven framework for managing your [zsh](https://www.zsh.org/) configuration.
|
||||
|
||||
Sounds boring. Let's try again.
|
||||
|
||||
__Oh My Zsh will not make you a 10x developer...but you may feel like one.__
|
||||
**Oh My Zsh will not make you a 10x developer...but you may feel like one.**
|
||||
|
||||
Once installed, your terminal shell will become the talk of the town _or your money back!_ With each keystroke in your command prompt, you'll take advantage of the hundreds of powerful plugins and beautiful themes. Strangers will come up to you in cafés and ask you, _"that is amazing! are you some sort of genius?"_
|
||||
|
||||
Finally, you'll begin to get the sort of attention that you have always felt you deserved. ...or maybe you'll use the time that you're saving to start flossing more often. 😬
|
||||
|
||||
To learn more, visit [ohmyz.sh](https://ohmyz.sh), follow [@ohmyzsh](https://twitter.com/ohmyzsh) on Twitter, and/or join us on [Discord](https://discord.gg/ohmyzsh).
|
||||
To learn more, visit [ohmyz.sh](https://ohmyz.sh), follow [@ohmyzsh](https://x.com/ohmyzsh) on X (formerly Twitter), and join us on [Discord](https://discord.gg/ohmyzsh).
|
||||
|
||||
[](https://github.com/ohmyzsh/ohmyzsh/actions?query=workflow%3ACI)
|
||||
[](https://twitter.com/intent/follow?screen_name=ohmyzsh)
|
||||
[](https://twitter.com/intent/follow?screen_name=ohmyzsh)
|
||||
[](https://mstdn.social/@ohmyzsh)
|
||||
[](https://discord.gg/ohmyzsh)
|
||||
[](https://gitpod.io/#https://github.com/ohmyzsh/ohmyzsh)
|
||||
|
||||
<details>
|
||||
<summary>Table of Contents</summary>
|
||||
|
||||
- [Getting Started](#getting-started)
|
||||
- [Operating System Compatibility](#operating-system-compatibility)
|
||||
- [Prerequisites](#prerequisites)
|
||||
- [Basic Installation](#basic-installation)
|
||||
- [Manual Inspection](#manual-inspection)
|
||||
- [Using Oh My Zsh](#using-oh-my-zsh)
|
||||
- [Plugins](#plugins)
|
||||
- [Enabling Plugins](#enabling-plugins)
|
||||
- [Using Plugins](#using-plugins)
|
||||
- [Themes](#themes)
|
||||
- [Selecting A Theme](#selecting-a-theme)
|
||||
- [FAQ](#faq)
|
||||
- [Advanced Topics](#advanced-topics)
|
||||
- [Advanced Installation](#advanced-installation)
|
||||
- [Custom Directory](#custom-directory)
|
||||
- [Unattended Install](#unattended-install)
|
||||
- [Installing From A Forked Repository](#installing-from-a-forked-repository)
|
||||
- [Manual Installation](#manual-installation)
|
||||
- [Installation Problems](#installation-problems)
|
||||
- [Custom Plugins And Themes](#custom-plugins-and-themes)
|
||||
- [Enable GNU ls In macOS And freeBSD Systems](#enable-gnu-ls-in-macos-and-freebsd-systems)
|
||||
- [Skip Aliases](#skip-aliases)
|
||||
- [Disable async git prompt](#disable-async-git-prompt)
|
||||
- [Getting Updates](#getting-updates)
|
||||
- [Updates Verbosity](#updates-verbosity)
|
||||
- [Manual Updates](#manual-updates)
|
||||
- [Uninstalling Oh My Zsh](#uninstalling-oh-my-zsh)
|
||||
- [How Do I Contribute To Oh My Zsh?](#how-do-i-contribute-to-oh-my-zsh)
|
||||
- [Do Not Send Us Themes](#do-not-send-us-themes)
|
||||
- [Contributors](#contributors)
|
||||
- [Follow Us](#follow-us)
|
||||
- [Merchandise](#merchandise)
|
||||
- [License](#license)
|
||||
- [About Planet Argon](#about-planet-argon)
|
||||
|
||||
</details>
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Operating System Compatibility
|
||||
|
||||
| O/S | Status |
|
||||
| :------------- | :-----: |
|
||||
| Android | ✅ |
|
||||
| freeBSD | ✅ |
|
||||
| LCARS | 🛸 |
|
||||
| Linux | ✅ |
|
||||
| macOS | ✅ |
|
||||
| OS/2 Warp | ❌ |
|
||||
| Windows (WSL2) | ✅ |
|
||||
|
||||
|
||||
### Prerequisites
|
||||
|
||||
* A Unix-like operating system: macOS, Linux, BSD. On Windows: WSL2 is preferred, but cygwin or msys also mostly work.
|
||||
* [Zsh](https://www.zsh.org) should be installed (v4.3.9 or more recent is fine but we prefer 5.0.8 and newer). If not pre-installed (run `zsh --version` to confirm), check the following wiki instructions here: [Installing ZSH](https://github.com/ohmyzsh/ohmyzsh/wiki/Installing-ZSH)
|
||||
* `curl` or `wget` should be installed
|
||||
* `git` should be installed (recommended v2.4.11 or higher)
|
||||
- [Zsh](https://www.zsh.org) should be installed (v4.3.9 or more recent is fine but we prefer 5.0.8 and newer). If not pre-installed (run `zsh --version` to confirm), check the following wiki instructions here: [Installing ZSH](https://github.com/ohmyzsh/ohmyzsh/wiki/Installing-ZSH)
|
||||
- `curl` or `wget` should be installed
|
||||
- `git` should be installed (recommended v2.4.11 or higher)
|
||||
|
||||
### Basic Installation
|
||||
|
||||
Oh My Zsh is installed by running one of the following commands in your terminal. You can install this via the command-line with either `curl` or `wget`, whichever is installed on your machine.
|
||||
Oh My Zsh is installed by running one of the following commands in your terminal. You can install this via the command-line with either `curl`, `wget` or another similar tool.
|
||||
|
||||
#### via curl
|
||||
| Method | Command |
|
||||
| :-------- | :------------------------------------------------------------------------------------------------ |
|
||||
| **curl** | `sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"` |
|
||||
| **wget** | `sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"` |
|
||||
| **fetch** | `sh -c "$(fetch -o - https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"` |
|
||||
|
||||
```shell
|
||||
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
|
||||
```
|
||||
Alternatively, the installer is also mirrored outside GitHub. Using this URL instead may be required if you're in a country like China or India (for certain ISPs), that blocks `raw.githubusercontent.com`:
|
||||
|
||||
#### via wget
|
||||
| Method | Command |
|
||||
| :-------- | :------------------------------------------------------------------------------------------------ |
|
||||
| **curl** | `sh -c "$(curl -fsSL https://install.ohmyz.sh/)"` |
|
||||
| **wget** | `sh -c "$(wget -O- https://install.ohmyz.sh/)"` |
|
||||
| **fetch** | `sh -c "$(fetch -o - https://install.ohmyz.sh/)"` |
|
||||
|
||||
```shell
|
||||
sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
|
||||
```
|
||||
_Note that any previous `.zshrc` will be renamed to `.zshrc.pre-oh-my-zsh`. After installation, you can move the configuration you want to preserve into the new `.zshrc`._
|
||||
|
||||
#### Manual inspection
|
||||
#### Manual Inspection
|
||||
|
||||
It's a good idea to inspect the install script from projects you don't yet know. You can do
|
||||
that by downloading the install script first, looking through it so everything looks normal,
|
||||
then running it:
|
||||
|
||||
```shell
|
||||
curl -Lo install.sh https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
|
||||
```sh
|
||||
wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
|
||||
sh install.sh
|
||||
```
|
||||
|
||||
If the above URL times out or otherwise fails, you may have to substitute the URL for `https://install.ohmyz.sh` to be able to get the script.
|
||||
|
||||
## Using Oh My Zsh
|
||||
|
||||
### Plugins
|
||||
|
|
@ -64,18 +122,18 @@ Oh My Zsh comes with a shitload of plugins for you to take advantage of. You can
|
|||
|
||||
Once you spot a plugin (or several) that you'd like to use with Oh My Zsh, you'll need to enable them in the `.zshrc` file. You'll find the zshrc file in your `$HOME` directory. Open it with your favorite text editor and you'll see a spot to list all the plugins you want to load.
|
||||
|
||||
```shell
|
||||
```sh
|
||||
vi ~/.zshrc
|
||||
```
|
||||
|
||||
For example, this might begin to look like this:
|
||||
|
||||
```shell
|
||||
```sh
|
||||
plugins=(
|
||||
git
|
||||
bundler
|
||||
dotenv
|
||||
osx
|
||||
macos
|
||||
rake
|
||||
rbenv
|
||||
ruby
|
||||
|
|
@ -86,30 +144,30 @@ _Note that the plugins are separated by whitespace (spaces, tabs, new lines...).
|
|||
|
||||
#### Using Plugins
|
||||
|
||||
Each plugin includes a __README__, documenting it. This README should show the aliases (if the plugin adds any) and extra goodies that are inclued in that particular plugin.
|
||||
Each built-in plugin includes a **README**, documenting it. This README should show the aliases (if the plugin adds any) and extra goodies that are included in that particular plugin.
|
||||
|
||||
### Themes
|
||||
|
||||
We'll admit it. Early in the Oh My Zsh world, we may have gotten a bit too theme happy. We have over one hundred and fifty themes now bundled. Most of them have [screenshots](https://github.com/ohmyzsh/ohmyzsh/wiki/Themes) on the wiki (We are working on updating this!). Check them out!
|
||||
|
||||
#### Selecting a Theme
|
||||
#### Selecting A Theme
|
||||
|
||||
_Robby's theme is the default one. It's not the fanciest one. It's not the simplest one. It's just the right one (for him)._
|
||||
|
||||
Once you find a theme that you'd like to use, you will need to edit the `~/.zshrc` file. You'll see an environment variable (all caps) in there that looks like:
|
||||
|
||||
```shell
|
||||
```sh
|
||||
ZSH_THEME="robbyrussell"
|
||||
```
|
||||
|
||||
To use a different theme, simply change the value to match the name of your desired theme. For example:
|
||||
|
||||
```shell
|
||||
```sh
|
||||
ZSH_THEME="agnoster" # (this is one of the fancy ones)
|
||||
# see https://github.com/ohmyzsh/ohmyzsh/wiki/Themes#agnoster
|
||||
```
|
||||
|
||||
_Note: many themes require installing the [Powerline Fonts](https://github.com/powerline/fonts) in order to render properly._
|
||||
_Note: many themes require installing a [Powerline Font](https://github.com/powerline/fonts) or a [Nerd Font](https://github.com/ryanoasis/nerd-fonts) in order to render properly. Without them, these themes will render [weird prompt symbols](https://github.com/ohmyzsh/ohmyzsh/wiki/FAQ#i-have-a-weird-character-in-my-prompt)_
|
||||
|
||||
Open up a new terminal window and your prompt should look something like this:
|
||||
|
||||
|
|
@ -119,24 +177,23 @@ In case you did not find a suitable theme for your needs, please have a look at
|
|||
|
||||
If you're feeling feisty, you can let the computer select one randomly for you each time you open a new terminal window.
|
||||
|
||||
|
||||
```shell
|
||||
```sh
|
||||
ZSH_THEME="random" # (...please let it be pie... please be some pie..)
|
||||
```
|
||||
|
||||
And if you want to pick random theme from a list of your favorite themes:
|
||||
|
||||
```shell
|
||||
```sh
|
||||
ZSH_THEME_RANDOM_CANDIDATES=(
|
||||
"robbyrussell"
|
||||
"agnoster"
|
||||
)
|
||||
```
|
||||
|
||||
If you only know which themes you don't like, you can add them similarly to a blacklist:
|
||||
If you only know which themes you don't like, you can add them similarly to an ignored list:
|
||||
|
||||
```shell
|
||||
ZSH_THEME_RANDOM_BLACKLIST=(pygmalion tjkirch_mod)
|
||||
```sh
|
||||
ZSH_THEME_RANDOM_IGNORED=(pygmalion tjkirch_mod)
|
||||
```
|
||||
|
||||
### FAQ
|
||||
|
|
@ -160,23 +217,25 @@ If you'd like to change the install directory with the `ZSH` environment variabl
|
|||
`export ZSH=/your/path` before installing, or by setting it before the end of the install pipeline
|
||||
like this:
|
||||
|
||||
```shell
|
||||
```sh
|
||||
ZSH="$HOME/.dotfiles/oh-my-zsh" sh install.sh
|
||||
```
|
||||
|
||||
#### Unattended install
|
||||
#### Unattended Install
|
||||
|
||||
If you're running the Oh My Zsh install script as part of an automated install, you can pass the
|
||||
flag `--unattended` to the `install.sh` script. This will have the effect of not trying to change
|
||||
the default shell, and also won't run `zsh` when the installation has finished.
|
||||
If you're running the Oh My Zsh install script as part of an automated install, you can pass the `--unattended`
|
||||
flag to the `install.sh` script. This will have the effect of not trying to change
|
||||
the default shell, and it also won't run `zsh` when the installation has finished.
|
||||
|
||||
```shell
|
||||
```sh
|
||||
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
|
||||
```
|
||||
|
||||
#### Installing from a forked repository
|
||||
If you're in China, India, or another country that blocks `raw.githubusercontent.com`, you may have to substitute the URL for `https://install.ohmyz.sh` for it to install.
|
||||
|
||||
The install script also accepts these variables to allow installation of a different repository:
|
||||
#### Installing From A Forked Repository
|
||||
|
||||
The install script also accepts these variables to allow the installation of a different repository:
|
||||
|
||||
- `REPO` (default: `ohmyzsh/ohmyzsh`): this takes the form of `owner/repository`. If you set
|
||||
this variable, the installer will look for a repository at `https://github.com/{owner}/{repository}`.
|
||||
|
|
@ -193,41 +252,41 @@ The install script also accepts these variables to allow installation of a diffe
|
|||
|
||||
For example:
|
||||
|
||||
```shell
|
||||
```sh
|
||||
REPO=apjanke/oh-my-zsh BRANCH=edge sh install.sh
|
||||
```
|
||||
|
||||
#### Manual Installation
|
||||
|
||||
##### 1. Clone the repository:
|
||||
##### 1. Clone The Repository <!-- omit in toc -->
|
||||
|
||||
```shell
|
||||
```sh
|
||||
git clone https://github.com/ohmyzsh/ohmyzsh.git ~/.oh-my-zsh
|
||||
```
|
||||
|
||||
##### 2. *Optionally*, backup your existing `~/.zshrc` file:
|
||||
##### 2. _Optionally_, Backup Your Existing `~/.zshrc` File <!-- omit in toc -->
|
||||
|
||||
```shell
|
||||
```sh
|
||||
cp ~/.zshrc ~/.zshrc.orig
|
||||
```
|
||||
|
||||
##### 3. Create a new zsh configuration file
|
||||
##### 3. Create A New Zsh Configuration File <!-- omit in toc -->
|
||||
|
||||
You can create a new zsh config file by copying the template that we have included for you.
|
||||
|
||||
```shell
|
||||
```sh
|
||||
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
|
||||
```
|
||||
|
||||
##### 4. Change your default shell
|
||||
##### 4. Change Your Default Shell <!-- omit in toc -->
|
||||
|
||||
```shell
|
||||
```sh
|
||||
chsh -s $(which zsh)
|
||||
```
|
||||
|
||||
You must log out from your user session and log back in to see this change.
|
||||
|
||||
##### 5. Initialize your new zsh configuration
|
||||
##### 5. Initialize Your New Zsh Configuration <!-- omit in toc -->
|
||||
|
||||
Once you open up a new terminal window, it should load zsh with Oh My Zsh's configuration.
|
||||
|
||||
|
|
@ -235,12 +294,10 @@ Once you open up a new terminal window, it should load zsh with Oh My Zsh's conf
|
|||
|
||||
If you have any hiccups installing, here are a few common fixes.
|
||||
|
||||
* You _might_ need to modify your `PATH` in `~/.zshrc` if you're not able to find some commands after
|
||||
switching to `oh-my-zsh`.
|
||||
* If you installed manually or changed the install location, check the `ZSH` environment variable in
|
||||
`~/.zshrc`.
|
||||
- You _might_ need to modify your `PATH` in `~/.zshrc` if you're not able to find some commands after switching to `oh-my-zsh`.
|
||||
- If you installed manually or changed the install location, check the `ZSH` environment variable in `~/.zshrc`.
|
||||
|
||||
### Custom Plugins and Themes
|
||||
### Custom Plugins And Themes
|
||||
|
||||
If you want to override any of the default behaviors, just add a new file (ending in `.zsh`) in the `custom/` directory.
|
||||
|
||||
|
|
@ -248,26 +305,132 @@ If you have many functions that go well together, you can put them as a `XYZ.plu
|
|||
|
||||
If you would like to override the functionality of a plugin distributed with Oh My Zsh, create a plugin of the same name in the `custom/plugins/` directory and it will be loaded instead of the one in `plugins/`.
|
||||
|
||||
## Getting Updates
|
||||
### Enable GNU ls In macOS And freeBSD Systems
|
||||
|
||||
By default, you will be prompted to check for upgrades every few weeks. If you would like `oh-my-zsh` to automatically upgrade itself without prompting you, set the following in your `~/.zshrc`:
|
||||
<a name="enable-gnu-ls"></a>
|
||||
|
||||
```shell
|
||||
DISABLE_UPDATE_PROMPT=true
|
||||
The default behaviour in Oh My Zsh is to use BSD `ls` in macOS and FreeBSD systems. If GNU `ls` is installed
|
||||
(as `gls` command), you can choose to use it instead. To do it, you can use zstyle-based config before
|
||||
sourcing `oh-my-zsh.sh`:
|
||||
|
||||
```zsh
|
||||
zstyle ':omz:lib:theme-and-appearance' gnu-ls yes
|
||||
```
|
||||
|
||||
To disable automatic upgrades, set the following in your `~/.zshrc`:
|
||||
_Note: this is not compatible with `DISABLE_LS_COLORS=true`_
|
||||
|
||||
```shell
|
||||
DISABLE_AUTO_UPDATE=true
|
||||
### Skip Aliases
|
||||
|
||||
<a name="remove-directories-aliases"></a>
|
||||
|
||||
If you want to skip default Oh My Zsh aliases (those defined in `lib/*` files) or plugin aliases,
|
||||
you can use the settings below in your `~/.zshrc` file, **before Oh My Zsh is loaded**. Note that
|
||||
there are many different ways to skip aliases, depending on your needs.
|
||||
|
||||
```sh
|
||||
# Skip all aliases, in lib files and enabled plugins
|
||||
zstyle ':omz:*' aliases no
|
||||
|
||||
# Skip all aliases in lib files
|
||||
zstyle ':omz:lib:*' aliases no
|
||||
# Skip only aliases defined in the directories.zsh lib file
|
||||
zstyle ':omz:lib:directories' aliases no
|
||||
|
||||
# Skip all plugin aliases
|
||||
zstyle ':omz:plugins:*' aliases no
|
||||
# Skip only the aliases from the git plugin
|
||||
zstyle ':omz:plugins:git' aliases no
|
||||
```
|
||||
|
||||
You can combine these in other ways taking into account that more specific scopes take precedence:
|
||||
|
||||
```sh
|
||||
# Skip all plugin aliases, except for the git plugin
|
||||
zstyle ':omz:plugins:*' aliases no
|
||||
zstyle ':omz:plugins:git' aliases yes
|
||||
```
|
||||
|
||||
A previous version of this feature was using the setting below, which has been removed:
|
||||
|
||||
```sh
|
||||
zstyle ':omz:directories' aliases no
|
||||
```
|
||||
|
||||
Instead, you can now use the following:
|
||||
|
||||
```sh
|
||||
zstyle ':omz:lib:directories' aliases no
|
||||
```
|
||||
|
||||
### Disable async git prompt
|
||||
|
||||
Async prompt functions are an experimental feature (included on April 3, 2024) that allows Oh My Zsh to render prompt information
|
||||
asynchronously. This can improve prompt rendering performance, but it might not work well with some setups. We hope that's not an
|
||||
issue, but if you're seeing problems with this new feature, you can turn it off by setting the following in your .zshrc file,
|
||||
before Oh My Zsh is sourced:
|
||||
|
||||
```sh
|
||||
zstyle ':omz:alpha:lib:git' async-prompt no
|
||||
```
|
||||
|
||||
#### Notice <!-- omit in toc -->
|
||||
|
||||
> This feature is currently in a testing phase and it may be subject to change in the future.
|
||||
> It is also not currently compatible with plugin managers such as zpm or zinit, which don't
|
||||
> source the init script (`oh-my-zsh.sh`) where this feature is implemented in.
|
||||
|
||||
> It is also not currently aware of "aliases" that are defined as functions. Example of such
|
||||
> are `gccd`, `ggf`, or `ggl` functions from the git plugin.
|
||||
|
||||
## Getting Updates
|
||||
|
||||
By default, you will be prompted to check for updates every 2 weeks. You can choose other update modes by adding a line to your `~/.zshrc` file, **before Oh My Zsh is loaded**:
|
||||
|
||||
1. Automatic update without confirmation prompt:
|
||||
|
||||
```sh
|
||||
zstyle ':omz:update' mode auto
|
||||
```
|
||||
|
||||
2. Just offer a reminder every few days, if there are updates available:
|
||||
|
||||
```sh
|
||||
zstyle ':omz:update' mode reminder
|
||||
```
|
||||
|
||||
3. To disable automatic updates entirely:
|
||||
|
||||
```sh
|
||||
zstyle ':omz:update' mode disabled
|
||||
```
|
||||
|
||||
NOTE: you can control how often Oh My Zsh checks for updates with the following setting:
|
||||
|
||||
```sh
|
||||
# This will check for updates every 7 days
|
||||
zstyle ':omz:update' frequency 7
|
||||
# This will check for updates every time you open the terminal (not recommended)
|
||||
zstyle ':omz:update' frequency 0
|
||||
```
|
||||
|
||||
### Updates Verbosity
|
||||
|
||||
You can also limit the update verbosity with the following settings:
|
||||
|
||||
```sh
|
||||
zstyle ':omz:update' verbose default # default update prompt
|
||||
|
||||
zstyle ':omz:update' verbose minimal # only few lines
|
||||
|
||||
zstyle ':omz:update' verbose silent # only errors
|
||||
```
|
||||
|
||||
### Manual Updates
|
||||
|
||||
If you'd like to upgrade at any point in time (maybe someone just released a new plugin and you don't want to wait a week?) you just need to run:
|
||||
If you'd like to update at any point in time (maybe someone just released a new plugin and you don't want to wait a week?) you just need to run:
|
||||
|
||||
```shell
|
||||
upgrade_oh_my_zsh
|
||||
```sh
|
||||
omz update
|
||||
```
|
||||
|
||||
Magic! 🎉
|
||||
|
|
@ -278,17 +441,17 @@ Oh My Zsh isn't for everyone. We'll miss you, but we want to make this an easy b
|
|||
|
||||
If you want to uninstall `oh-my-zsh`, just run `uninstall_oh_my_zsh` from the command-line. It will remove itself and revert your previous `bash` or `zsh` configuration.
|
||||
|
||||
## How do I contribute to Oh My Zsh?
|
||||
## How Do I Contribute To Oh My Zsh?
|
||||
|
||||
Before you participate in our delightful community, please read the [code of conduct](CODE_OF_CONDUCT.md).
|
||||
|
||||
I'm far from being a [Zsh](https://www.zsh.org/) expert and suspect there are many ways to improve – if you have ideas on how to make the configuration easier to maintain (and faster), don't hesitate to fork and send pull requests!
|
||||
|
||||
We also need people to test out pull-requests. So take a look through [the open issues](https://github.com/ohmyzsh/ohmyzsh/issues) and help where you can.
|
||||
We also need people to test out pull requests. So take a look through [the open issues](https://github.com/ohmyzsh/ohmyzsh/issues) and help where you can.
|
||||
|
||||
See [Contributing](CONTRIBUTING.md) for more details.
|
||||
|
||||
### Do NOT send us themes
|
||||
### Do Not Send Us Themes
|
||||
|
||||
We have (more than) enough themes for the time being. Please add your theme to the [external themes](https://github.com/ohmyzsh/ohmyzsh/wiki/External-themes) wiki page.
|
||||
|
||||
|
|
@ -298,14 +461,18 @@ Oh My Zsh has a vibrant community of happy users and delightful contributors. Wi
|
|||
|
||||
Thank you so much!
|
||||
|
||||
<a href="https://github.com/ohmyzsh/ohmyzsh/graphs/contributors">
|
||||
<img src="https://contrib.rocks/image?repo=ohmyzsh/ohmyzsh" width="100%"/>
|
||||
</a>
|
||||
|
||||
## Follow Us
|
||||
|
||||
We're on the social media.
|
||||
We're on social media:
|
||||
|
||||
* [@ohmyzsh](https://twitter.com/ohmyzsh) on Twitter. You should follow it.
|
||||
* [FaceBook](https://www.facebook.com/Oh-My-Zsh-296616263819290/) poke us.
|
||||
* [Instagram](https://www.instagram.com/_ohmyzsh/) tag us in your post showing Oh My Zsh!
|
||||
* [Discord](https://discord.gg/ohmyzsh) to chat with us!
|
||||
- [@ohmyzsh](https://x.com/ohmyzsh) on X (formerly Twitter). You should follow it.
|
||||
- [Facebook](https://www.facebook.com/Oh-My-Zsh-296616263819290/) poke us.
|
||||
- [Instagram](https://www.instagram.com/_ohmyzsh/) tag us in your post showing Oh My Zsh!
|
||||
- [Discord](https://discord.gg/ohmyzsh) to chat with us!
|
||||
|
||||
## Merchandise
|
||||
|
||||
|
|
@ -319,4 +486,4 @@ Oh My Zsh is released under the [MIT license](LICENSE.txt).
|
|||
|
||||

|
||||
|
||||
Oh My Zsh was started by the team at [Planet Argon](https://www.planetargon.com/?utm_source=github), a [Ruby on Rails development agency](https://www.planetargon.com/skills/ruby-on-rails-development?utm_source=github). Check out our [other open source projects](https://www.planetargon.com/open-source?utm_source=github).
|
||||
Oh My Zsh was started by the team at [Planet Argon](https://www.planetargon.com/?utm_source=github), a [Ruby on Rails development agency](https://www.planetargon.com/services/ruby-on-rails-development?utm_source=github). Check out our [other open source projects](https://www.planetargon.com/open-source?utm_source=github).
|
||||
|
|
|
|||
23
SECURITY.md
Normal file
23
SECURITY.md
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
At the moment Oh My Zsh only considers the very latest commit to be supported.
|
||||
We combine that with our fast response to incidents and the automated updates
|
||||
to minimize the time between vulnerability publication and patch release.
|
||||
|
||||
| Version | Supported |
|
||||
|:-------------- |:------------------ |
|
||||
| master | :white_check_mark: |
|
||||
| other commits | :x: |
|
||||
|
||||
In the near future we will introduce versioning, so expect this section to change.
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
**Do not submit an issue or pull request**: this might reveal the vulnerability.
|
||||
|
||||
Instead, you should email the maintainers directly at: [**security@ohmyz.sh**](mailto:security@ohmyz.sh),
|
||||
or using the link to [privately report a vulnerability with GitHub](https://github.com/ohmyzsh/ohmyzsh/security/advisories/new).
|
||||
|
||||
We will deal with the vulnerability privately and submit a patch as soon as possible.
|
||||
|
|
@ -1,10 +1,12 @@
|
|||
# You can put files here to add functionality separated per file, which
|
||||
# will be ignored by git.
|
||||
# Files on the custom/ directory will be automatically loaded by the init
|
||||
# script, in alphabetical order.
|
||||
|
||||
# For example: add yourself some shortcuts to projects you often work on.
|
||||
# Put files in this folder to add your own custom functionality.
|
||||
# See: https://github.com/ohmyzsh/ohmyzsh/wiki/Customization
|
||||
#
|
||||
# Files in the custom/ directory will be:
|
||||
# - loaded automatically by the init script, in alphabetical order
|
||||
# - loaded last, after all built-ins in the lib/ directory, to override them
|
||||
# - ignored by git by default
|
||||
#
|
||||
# Example: add custom/shortcuts.zsh for shortcuts to your local projects
|
||||
#
|
||||
# brainstormr=~/Projects/development/planetargon/brainstormr
|
||||
# cd $brainstormr
|
||||
#
|
||||
|
|
|
|||
|
|
@ -1,2 +1,3 @@
|
|||
# Add your own custom plugins in the custom/plugins directory. Plugins placed
|
||||
# here will override ones with the same name in the main plugins directory.
|
||||
# See: https://github.com/ohmyzsh/ohmyzsh/wiki/Customization#overriding-and-adding-plugins
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
# Put your custom themes in this folder.
|
||||
# See: https://github.com/ohmyzsh/ohmyzsh/wiki/Customization#overriding-and-adding-themes
|
||||
#
|
||||
# Example:
|
||||
|
||||
PROMPT="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m %{$fg[yellow]%}%~ %{$reset_color%}%% "
|
||||
|
|
|
|||
144
lib/async_prompt.zsh
Normal file
144
lib/async_prompt.zsh
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
# The async code is taken from
|
||||
# https://github.com/zsh-users/zsh-autosuggestions/blob/master/src/async.zsh
|
||||
# https://github.com/woefe/git-prompt.zsh/blob/master/git-prompt.zsh
|
||||
|
||||
zmodload zsh/system
|
||||
autoload -Uz is-at-least
|
||||
|
||||
# For now, async prompt function handlers are set up like so:
|
||||
# First, define the async function handler and register the handler
|
||||
# with _omz_register_handler:
|
||||
#
|
||||
# function _git_prompt_status_async {
|
||||
# # Do some expensive operation that outputs to stdout
|
||||
# }
|
||||
# _omz_register_handler _git_prompt_status_async
|
||||
#
|
||||
# Then add a stub prompt function in `$PROMPT` or similar prompt variables,
|
||||
# which will show the output of "$_OMZ_ASYNC_OUTPUT[handler_name]":
|
||||
#
|
||||
# function git_prompt_status {
|
||||
# echo -n $_OMZ_ASYNC_OUTPUT[_git_prompt_status_async]
|
||||
# }
|
||||
#
|
||||
# RPROMPT='$(git_prompt_status)'
|
||||
#
|
||||
# This API is subject to change and optimization. Rely on it at your own risk.
|
||||
|
||||
function _omz_register_handler {
|
||||
setopt localoptions noksharrays
|
||||
typeset -ga _omz_async_functions
|
||||
# we want to do nothing if there's no $1 function or we already set it up
|
||||
if [[ -z "$1" ]] || (( ! ${+functions[$1]} )) \
|
||||
|| (( ${_omz_async_functions[(Ie)$1]} )); then
|
||||
return
|
||||
fi
|
||||
_omz_async_functions+=("$1")
|
||||
# let's add the hook to async_request if it's not there yet
|
||||
if (( ! ${precmd_functions[(Ie)_omz_async_request]} )) \
|
||||
&& (( ${+functions[_omz_async_request]})); then
|
||||
autoload -Uz add-zsh-hook
|
||||
add-zsh-hook precmd _omz_async_request
|
||||
fi
|
||||
}
|
||||
|
||||
# Set up async handlers and callbacks
|
||||
function _omz_async_request {
|
||||
local -i ret=$?
|
||||
typeset -gA _OMZ_ASYNC_FDS _OMZ_ASYNC_PIDS _OMZ_ASYNC_OUTPUT
|
||||
|
||||
# executor runs a subshell for all async requests based on key
|
||||
local handler
|
||||
for handler in ${_omz_async_functions}; do
|
||||
(( ${+functions[$handler]} )) || continue
|
||||
|
||||
local fd=${_OMZ_ASYNC_FDS[$handler]:--1}
|
||||
local pid=${_OMZ_ASYNC_PIDS[$handler]:--1}
|
||||
|
||||
# If we've got a pending request, cancel it
|
||||
if (( fd != -1 && pid != -1 )) && { true <&$fd } 2>/dev/null; then
|
||||
# Close the file descriptor and remove the handler
|
||||
exec {fd}<&-
|
||||
zle -F $fd
|
||||
|
||||
# Zsh will make a new process group for the child process only if job
|
||||
# control is enabled (MONITOR option)
|
||||
if [[ -o MONITOR ]]; then
|
||||
# Send the signal to the process group to kill any processes that may
|
||||
# have been forked by the async function handler
|
||||
kill -TERM -$pid 2>/dev/null
|
||||
else
|
||||
# Kill just the child process since it wasn't placed in a new process
|
||||
# group. If the async function handler forked any child processes they may
|
||||
# be orphaned and left behind.
|
||||
kill -TERM $pid 2>/dev/null
|
||||
fi
|
||||
fi
|
||||
|
||||
# Define global variables to store the file descriptor, PID and output
|
||||
_OMZ_ASYNC_FDS[$handler]=-1
|
||||
_OMZ_ASYNC_PIDS[$handler]=-1
|
||||
|
||||
# Fork a process to fetch the git status and open a pipe to read from it
|
||||
exec {fd}< <(
|
||||
# Tell parent process our PID
|
||||
builtin echo ${sysparams[pid]}
|
||||
# Set exit code for the handler if used
|
||||
() { return $ret }
|
||||
# Run the async function handler
|
||||
$handler
|
||||
)
|
||||
|
||||
# Save FD for handler
|
||||
_OMZ_ASYNC_FDS[$handler]=$fd
|
||||
|
||||
# There's a weird bug here where ^C stops working unless we force a fork
|
||||
# See https://github.com/zsh-users/zsh-autosuggestions/issues/364
|
||||
# and https://github.com/zsh-users/zsh-autosuggestions/pull/612
|
||||
is-at-least 5.8 || command true
|
||||
|
||||
# Save the PID from the handler child process
|
||||
read -u $fd "_OMZ_ASYNC_PIDS[$handler]"
|
||||
|
||||
# When the fd is readable, call the response handler
|
||||
zle -F "$fd" _omz_async_callback
|
||||
done
|
||||
}
|
||||
|
||||
# Called when new data is ready to be read from the pipe
|
||||
function _omz_async_callback() {
|
||||
emulate -L zsh
|
||||
|
||||
local fd=$1 # First arg will be fd ready for reading
|
||||
local err=$2 # Second arg will be passed in case of error
|
||||
|
||||
if [[ -z "$err" || "$err" == "hup" ]]; then
|
||||
# Get handler name from fd
|
||||
local handler="${(k)_OMZ_ASYNC_FDS[(r)$fd]}"
|
||||
|
||||
# Store old output which is supposed to be already printed
|
||||
local old_output="${_OMZ_ASYNC_OUTPUT[$handler]}"
|
||||
|
||||
# Read output from fd
|
||||
IFS= read -r -u $fd -d '' "_OMZ_ASYNC_OUTPUT[$handler]"
|
||||
|
||||
# Repaint prompt if output has changed
|
||||
if [[ "$old_output" != "${_OMZ_ASYNC_OUTPUT[$handler]}" ]]; then
|
||||
zle .reset-prompt
|
||||
zle -R
|
||||
fi
|
||||
|
||||
# Close the fd
|
||||
exec {fd}<&-
|
||||
fi
|
||||
|
||||
# Always remove the handler
|
||||
zle -F "$fd"
|
||||
|
||||
# Unset global FD variable to prevent closing user created FDs in the precmd hook
|
||||
_OMZ_ASYNC_FDS[$handler]=-1
|
||||
_OMZ_ASYNC_PIDS[$handler]=-1
|
||||
}
|
||||
|
||||
autoload -Uz add-zsh-hook
|
||||
add-zsh-hook precmd _omz_async_request
|
||||
923
lib/cli.zsh
923
lib/cli.zsh
|
|
@ -1,210 +1,839 @@
|
|||
#!/usr/bin/env zsh
|
||||
|
||||
function omz {
|
||||
[[ $# -gt 0 ]] || {
|
||||
_omz::help
|
||||
return 1
|
||||
}
|
||||
[[ $# -gt 0 ]] || {
|
||||
_omz::help
|
||||
return 1
|
||||
}
|
||||
|
||||
local command="$1"
|
||||
shift
|
||||
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
|
||||
}
|
||||
# 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 "$@"
|
||||
_omz::$command "$@"
|
||||
}
|
||||
|
||||
function _omz {
|
||||
local -a cmds subcmds
|
||||
cmds=(
|
||||
'help:Usage information'
|
||||
'update:Update Oh My Zsh'
|
||||
'pr:Commands for Oh My Zsh Pull Requests'
|
||||
)
|
||||
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'
|
||||
'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
|
||||
pr) subcmds=( 'test:Test a Pull Request' 'clean:Delete all Pull Request branches' )
|
||||
_describe 'command' subcmds ;;
|
||||
esac
|
||||
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
|
||||
|
||||
return 0
|
||||
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 ;;
|
||||
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
|
||||
}
|
||||
|
||||
compdef _omz omz
|
||||
# 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 <<EOF
|
||||
cat >&2 <<EOF
|
||||
Usage: omz <command> [options]
|
||||
|
||||
Available commands:
|
||||
|
||||
help Print this help message
|
||||
update Update Oh My Zsh
|
||||
pr <command> Commands for Oh My Zsh Pull Requests
|
||||
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
|
||||
theme <command> Manage themes
|
||||
update Update Oh My Zsh
|
||||
version Show the version
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
function _omz::log {
|
||||
# if promptsubst is set, a message with `` or $()
|
||||
# will be run even if quoted due to `print -P`
|
||||
setopt localoptions nopromptsubst
|
||||
function _omz::changelog {
|
||||
local version=${1:-HEAD} format=${3:-"--text"}
|
||||
|
||||
# $1 = info|warn|error|debug
|
||||
# $@ = 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]
|
||||
|
||||
local logtype=$1
|
||||
local logname=${${functrace[1]#_}%:*}
|
||||
shift
|
||||
NOTE: <version> must be a valid branch, tag or commit.
|
||||
EOF
|
||||
return 1
|
||||
fi
|
||||
|
||||
# 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: $@" ;;
|
||||
debug) print -P "%F{white}$logname%f: $@" ;;
|
||||
info) print -P "%F{green}$logname%f: $@" ;;
|
||||
warn) print -P "%S%F{yellow}$logname%f%s: $@" ;;
|
||||
error) print -P "%S%F{red}$logname%f%s: $@" ;;
|
||||
esac >&2
|
||||
"$ZSH/tools/changelog.sh" "$version" "${2:-}" "$format"
|
||||
}
|
||||
|
||||
function _omz::pr {
|
||||
(( $# > 0 && $+functions[_omz::pr::$1] )) || {
|
||||
cat <<EOF
|
||||
Usage: omz pr <command> [options]
|
||||
function _omz::plugin {
|
||||
(( $# > 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
|
||||
disable <plugin> Disable plugin(s)
|
||||
enable <plugin> Enable plugin(s)
|
||||
info <plugin> Get information of a plugin
|
||||
list List all available Oh My Zsh plugins
|
||||
load <plugin> Load plugin(s)
|
||||
|
||||
EOF
|
||||
return 1
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
local command="$1"
|
||||
shift
|
||||
local command="$1"
|
||||
shift
|
||||
|
||||
_omz::pr::$command "$@"
|
||||
$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
|
||||
/^[ \t]*plugins=\(/ {
|
||||
multi=1
|
||||
}
|
||||
|
||||
# if multi flag is enabled and we find a valid closing parenthesis,
|
||||
# add new plugins and disable multi flag
|
||||
multi == 1 && /^[^#]*\)/ {
|
||||
multi=0
|
||||
sub(/\)/, \" $add_plugins&\")
|
||||
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 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
|
||||
(( ${+commands[less]} )) && less "$readme" || cat "$readme"
|
||||
return 0
|
||||
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
|
||||
custom_plugins=("$ZSH_CUSTOM"/plugins/*(-/N:t))
|
||||
builtin_plugins=("$ZSH"/plugins/*(-/N:t))
|
||||
|
||||
# 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=$(( $#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"
|
||||
(
|
||||
set -e
|
||||
builtin cd -q "$ZSH"
|
||||
|
||||
_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
|
||||
)
|
||||
# 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
|
||||
# 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: omz pr test <PR_NUMBER_or_URL>"
|
||||
return 1
|
||||
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
|
||||
# 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 found the ohmyzsh git remote. Aborting..."
|
||||
return 1
|
||||
}
|
||||
|
||||
# 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
|
||||
}
|
||||
|
||||
# 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"
|
||||
# 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
|
||||
|
||||
# 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
|
||||
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
|
||||
}
|
||||
|
||||
(( $found )) || {
|
||||
_omz::log error "could not found the ohmyzsh git remote. Aborting..."
|
||||
return 1
|
||||
}
|
||||
_omz::log info "fetch of PR #${1} successful."
|
||||
)
|
||||
|
||||
# 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
|
||||
}
|
||||
# If there was an error, abort running zsh to test the PR
|
||||
[[ $? -eq 0 ]] || return 1
|
||||
|
||||
# Rebase pull request branch against the current master
|
||||
_omz::log info "rebasing PR #$1..."
|
||||
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
|
||||
}
|
||||
# Run zsh to test the changes
|
||||
_omz::log info "running \`zsh\` to test the changes. Run \`exit\` to go back."
|
||||
command zsh -l
|
||||
|
||||
_omz::log info "fetch of PR #${1} successful."
|
||||
)
|
||||
# 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
|
||||
|
||||
# If there was an error, abort running zsh to test the PR
|
||||
[[ $? -eq 0 ]] || return 1
|
||||
(
|
||||
set -e
|
||||
builtin cd -q "$ZSH"
|
||||
|
||||
# Run zsh to test the changes
|
||||
_omz::log info "running \`zsh\` to test the changes. Run \`exit\` to go back."
|
||||
command zsh -l
|
||||
command git checkout "$branch" -- || {
|
||||
_omz::log error "could not go back to the previous branch ('$branch')."
|
||||
return 1
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
# After testing, go back to the previous HEAD if the user wants
|
||||
_omz::log prompt "do you want to go back to the previous branch? [Y/n] "
|
||||
read -r -k 1
|
||||
function _omz::reload {
|
||||
# Delete current completion cache
|
||||
command rm -f $_comp_dumpfile $ZSH_COMPDUMP
|
||||
|
||||
# If no newline entered, add a newline
|
||||
[[ "$REPLY" != $'\n' ]] && echo
|
||||
# If NO selected, do nothing else
|
||||
[[ "$REPLY" = [nN] ]] && return
|
||||
# Old zsh versions don't have ZSH_ARGZERO
|
||||
local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"
|
||||
# Check whether to run a login shell
|
||||
[[ "$zsh" = -* || -o login ]] && exec -l "${zsh#-}" || exec "$zsh"
|
||||
}
|
||||
|
||||
(
|
||||
set -e
|
||||
builtin cd -q "$ZSH"
|
||||
function _omz::theme {
|
||||
(( $# > 0 && $+functions[$0::$1] )) || {
|
||||
cat >&2 <<EOF
|
||||
Usage: ${(j: :)${(s.::.)0#_}} <command> [options]
|
||||
|
||||
command git checkout "$branch" -- || {
|
||||
_omz::log error "could not go back to the previous branch ('$branch')."
|
||||
return 1
|
||||
}
|
||||
)
|
||||
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 {
|
||||
env ZSH="$ZSH" sh "$ZSH/tools/upgrade.sh"
|
||||
# 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"
|
||||
# Check if git command is available
|
||||
(( $+commands[git] )) || {
|
||||
_omz::log error "git is not installed. Aborting..."
|
||||
return 1
|
||||
}
|
||||
|
||||
local last_commit=$(builtin cd -q "$ZSH"; git rev-parse HEAD 2>/dev/null)
|
||||
[[ $? -eq 0 ]] || {
|
||||
_omz::log error "\`$ZSH\` is not a git directory. Aborting..."
|
||||
return 1
|
||||
}
|
||||
|
||||
# Run update script
|
||||
zstyle -s ':omz:update' verbose verbose_mode || verbose_mode=default
|
||||
if [[ "$1" != --unattended ]]; then
|
||||
ZSH="$ZSH" command zsh -f "$ZSH/tools/upgrade.sh" -i -v $verbose_mode || return $?
|
||||
else
|
||||
ZSH="$ZSH" command zsh -f "$ZSH/tools/upgrade.sh" -v $verbose_mode || return $?
|
||||
fi
|
||||
|
||||
# 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 [[ "$1" != --unattended && "$(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]%:*}}"
|
||||
# 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"
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@
|
|||
# - pbcopy, pbpaste (macOS)
|
||||
# - cygwin (Windows running Cygwin)
|
||||
# - wl-copy, wl-paste (if $WAYLAND_DISPLAY is set)
|
||||
# - xclip (if $DISPLAY is set)
|
||||
# - xsel (if $DISPLAY is set)
|
||||
# - xclip (if $DISPLAY is set)
|
||||
# - lemonade (for SSH) https://github.com/pocke/lemonade
|
||||
# - doitclient (for SSH) http://www.chiark.greenend.org.uk/~sgtatham/doit/
|
||||
# - win32yank (Windows)
|
||||
|
|
@ -52,38 +52,38 @@ function detect-clipboard() {
|
|||
emulate -L zsh
|
||||
|
||||
if [[ "${OSTYPE}" == darwin* ]] && (( ${+commands[pbcopy]} )) && (( ${+commands[pbpaste]} )); then
|
||||
function clipcopy() { pbcopy < "${1:-/dev/stdin}"; }
|
||||
function clipcopy() { cat "${1:-/dev/stdin}" | pbcopy; }
|
||||
function clippaste() { pbpaste; }
|
||||
elif [[ "${OSTYPE}" == (cygwin|msys)* ]]; then
|
||||
function clipcopy() { cat "${1:-/dev/stdin}" > /dev/clipboard; }
|
||||
function clippaste() { cat /dev/clipboard; }
|
||||
elif (( $+commands[clip.exe] )) && (( $+commands[powershell.exe] )); then
|
||||
function clipcopy() { cat "${1:-/dev/stdin}" | clip.exe; }
|
||||
function clippaste() { powershell.exe -noprofile -command Get-Clipboard; }
|
||||
elif [ -n "${WAYLAND_DISPLAY:-}" ] && (( ${+commands[wl-copy]} )) && (( ${+commands[wl-paste]} )); then
|
||||
function clipcopy() { wl-copy < "${1:-/dev/stdin}"; }
|
||||
function clippaste() { wl-paste; }
|
||||
elif [ -n "${DISPLAY:-}" ] && (( ${+commands[xclip]} )); then
|
||||
function clipcopy() { xclip -in -selection clipboard < "${1:-/dev/stdin}"; }
|
||||
function clippaste() { xclip -out -selection clipboard; }
|
||||
function clipcopy() { cat "${1:-/dev/stdin}" | wl-copy &>/dev/null &|; }
|
||||
function clippaste() { wl-paste --no-newline; }
|
||||
elif [ -n "${DISPLAY:-}" ] && (( ${+commands[xsel]} )); then
|
||||
function clipcopy() { xsel --clipboard --input < "${1:-/dev/stdin}"; }
|
||||
function clipcopy() { cat "${1:-/dev/stdin}" | xsel --clipboard --input; }
|
||||
function clippaste() { xsel --clipboard --output; }
|
||||
elif [ -n "${DISPLAY:-}" ] && (( ${+commands[xclip]} )); then
|
||||
function clipcopy() { cat "${1:-/dev/stdin}" | xclip -selection clipboard -in &>/dev/null &|; }
|
||||
function clippaste() { xclip -out -selection clipboard; }
|
||||
elif (( ${+commands[lemonade]} )); then
|
||||
function clipcopy() { lemonade copy < "${1:-/dev/stdin}"; }
|
||||
function clipcopy() { cat "${1:-/dev/stdin}" | lemonade copy; }
|
||||
function clippaste() { lemonade paste; }
|
||||
elif (( ${+commands[doitclient]} )); then
|
||||
function clipcopy() { doitclient wclip < "${1:-/dev/stdin}"; }
|
||||
function clipcopy() { cat "${1:-/dev/stdin}" | doitclient wclip; }
|
||||
function clippaste() { doitclient wclip -r; }
|
||||
elif (( ${+commands[win32yank]} )); then
|
||||
function clipcopy() { win32yank -i < "${1:-/dev/stdin}"; }
|
||||
function clipcopy() { cat "${1:-/dev/stdin}" | win32yank -i; }
|
||||
function clippaste() { win32yank -o; }
|
||||
elif [[ $OSTYPE == linux-android* ]] && (( $+commands[termux-clipboard-set] )); then
|
||||
function clipcopy() { termux-clipboard-set "${1:-/dev/stdin}"; }
|
||||
function clipcopy() { cat "${1:-/dev/stdin}" | termux-clipboard-set; }
|
||||
function clippaste() { termux-clipboard-get; }
|
||||
elif [ -n "${TMUX:-}" ] && (( ${+commands[tmux]} )); then
|
||||
function clipcopy() { tmux load-buffer "${1:--}"; }
|
||||
function clippaste() { tmux save-buffer -; }
|
||||
elif [[ $(uname -r) = *icrosoft* ]]; then
|
||||
function clipcopy() { clip.exe < "${1:-/dev/stdin}"; }
|
||||
function clippaste() { powershell.exe -noprofile -command Get-Clipboard; }
|
||||
else
|
||||
function _retry_clipboard_detection_or_fail() {
|
||||
local clipcmd="${1}"; shift
|
||||
|
|
@ -100,8 +100,8 @@ function detect-clipboard() {
|
|||
fi
|
||||
}
|
||||
|
||||
# Detect at startup. A non-zero exit here indicates that the dummy clipboards were set,
|
||||
# which is not really an error. If the user calls them, they will attempt to redetect
|
||||
# (for example, perhaps the user has now installed xclip) and then either print an error
|
||||
# or proceed successfully.
|
||||
detect-clipboard || true
|
||||
function clipcopy clippaste {
|
||||
unfunction clipcopy clippaste
|
||||
detect-clipboard || true # let one retry
|
||||
"$0" "$@"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ function handle_completion_insecurities() {
|
|||
# /usr/share/zsh/5.0.6
|
||||
#
|
||||
# Since the ignorable first line is printed to stderr and thus not captured,
|
||||
# stderr is squelched to prevent this output from leaking to the user.
|
||||
# stderr is squelched to prevent this output from leaking to the user.
|
||||
local -aU insecure_dirs
|
||||
insecure_dirs=( ${(f@):-"$(compaudit 2>/dev/null)"} )
|
||||
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ if [[ "$CASE_SENSITIVE" = true ]]; then
|
|||
zstyle ':completion:*' matcher-list 'r:|=*' 'l:|=* r:|=*'
|
||||
else
|
||||
if [[ "$HYPHEN_INSENSITIVE" = true ]]; then
|
||||
zstyle ':completion:*' matcher-list 'm:{a-zA-Z-_}={A-Za-z_-}' 'r:|=*' 'l:|=* r:|=*'
|
||||
zstyle ':completion:*' matcher-list 'm:{[:lower:][:upper:]-_}={[:upper:][:lower:]_-}' 'r:|=*' 'l:|=* r:|=*'
|
||||
else
|
||||
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|=*' 'l:|=* r:|=*'
|
||||
zstyle ':completion:*' matcher-list 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' 'r:|=*' 'l:|=* r:|=*'
|
||||
fi
|
||||
fi
|
||||
unset CASE_SENSITIVE HYPHEN_INSENSITIVE
|
||||
|
|
@ -32,9 +32,9 @@ zstyle ':completion:*' list-colors ''
|
|||
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
|
||||
|
||||
if [[ "$OSTYPE" = solaris* ]]; then
|
||||
zstyle ':completion:*:*:*:*:processes' command "ps -u $USER -o pid,user,comm"
|
||||
zstyle ':completion:*:*:*:*:processes' command "ps -u $USERNAME -o pid,user,comm"
|
||||
else
|
||||
zstyle ':completion:*:*:*:*:processes' command "ps -u $USER -o pid,user,comm -w -w"
|
||||
zstyle ':completion:*:*:*:*:processes' command "ps -u $USERNAME -o pid,user,comm -w -w"
|
||||
fi
|
||||
|
||||
# disable named-directories autocompletion
|
||||
|
|
@ -49,7 +49,7 @@ zstyle ':completion:*:*:*:users' ignored-patterns \
|
|||
adm amanda apache at avahi avahi-autoipd beaglidx bin cacti canna \
|
||||
clamav daemon dbus distcache dnsmasq dovecot fax ftp games gdm \
|
||||
gkrellmd gopher hacluster haldaemon halt hsqldb ident junkbust kdm \
|
||||
ldap lp mail mailman mailnull man messagebus mldonkey mysql nagios \
|
||||
ldap lp mail mailman mailnull man messagebus mldonkey mysql nagios \
|
||||
named netdump news nfsnobody nobody nscd ntp nut nx obsrun openvpn \
|
||||
operator pcap polkitd postfix postgres privoxy pulse pvm quagga radvd \
|
||||
rpc rpcuser rpm rtkit scard shutdown squid sshd statd svn sync tftp \
|
||||
|
|
@ -58,9 +58,12 @@ zstyle ':completion:*:*:*:users' ignored-patterns \
|
|||
# ... unless we really want to.
|
||||
zstyle '*' single-ignored show
|
||||
|
||||
if [[ $COMPLETION_WAITING_DOTS = true ]]; then
|
||||
if [[ ${COMPLETION_WAITING_DOTS:-false} != false ]]; then
|
||||
expand-or-complete-with-dots() {
|
||||
print -Pn "%F{red}…%f"
|
||||
# use $COMPLETION_WAITING_DOTS either as toggle or as the sequence to show
|
||||
[[ $COMPLETION_WAITING_DOTS = true ]] && COMPLETION_WAITING_DOTS="%F{red}…%f"
|
||||
# turn off line wrapping and print prompt-expanded "dot" sequence
|
||||
printf '\e[?7l%s\e[?7h' "${(%)COMPLETION_WAITING_DOTS}"
|
||||
zle expand-or-complete
|
||||
zle redisplay
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,10 @@
|
|||
if [[ "$ENABLE_CORRECTION" == "true" ]]; then
|
||||
alias cp='nocorrect cp'
|
||||
alias ebuild='nocorrect ebuild'
|
||||
alias gist='nocorrect gist'
|
||||
alias heroku='nocorrect heroku'
|
||||
alias hpodder='nocorrect hpodder'
|
||||
alias man='nocorrect man'
|
||||
alias mkdir='nocorrect mkdir'
|
||||
alias mv='nocorrect mv'
|
||||
alias mysql='nocorrect mysql'
|
||||
alias sudo='nocorrect sudo'
|
||||
alias su='nocorrect su'
|
||||
|
||||
setopt correct_all
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
#
|
||||
# This is written in a defensive style so it still works (and can detect) cases when
|
||||
# basic functionality like echo and which have been redefined. In particular, almost
|
||||
# everything is invoked with "builtin" or "command", to work in the face of user
|
||||
# everything is invoked with "builtin" or "command", to work in the face of user
|
||||
# redefinitions.
|
||||
#
|
||||
# OPTIONS
|
||||
|
|
@ -59,7 +59,7 @@ function omz_diagnostic_dump() {
|
|||
emulate -L zsh
|
||||
|
||||
builtin echo "Generating diagnostic dump; please be patient..."
|
||||
|
||||
|
||||
local thisfcn=omz_diagnostic_dump
|
||||
local -A opts
|
||||
local opt_verbose opt_noverbose opt_outfile
|
||||
|
|
@ -90,7 +90,7 @@ function omz_diagnostic_dump() {
|
|||
builtin echo
|
||||
builtin echo Diagnostic dump file created at: "$outfile"
|
||||
builtin echo
|
||||
builtin echo To share this with OMZ developers, post it as a gist on GitHub
|
||||
builtin echo To share this with OMZ developers, post it as a gist on GitHub
|
||||
builtin echo at "https://gist.github.com" and share the link to the gist.
|
||||
builtin echo
|
||||
builtin echo "WARNING: This dump file contains all your zsh and omz configuration files,"
|
||||
|
|
@ -105,14 +105,14 @@ function _omz_diag_dump_one_big_text() {
|
|||
builtin echo oh-my-zsh diagnostic dump
|
||||
builtin echo
|
||||
builtin echo $outfile
|
||||
builtin echo
|
||||
|
||||
builtin echo
|
||||
|
||||
# Basic system and zsh information
|
||||
command date
|
||||
command uname -a
|
||||
builtin echo OSTYPE=$OSTYPE
|
||||
builtin echo ZSH_VERSION=$ZSH_VERSION
|
||||
builtin echo User: $USER
|
||||
builtin echo User: $USERNAME
|
||||
builtin echo umask: $(umask)
|
||||
builtin echo
|
||||
_omz_diag_dump_os_specific_version
|
||||
|
|
@ -151,7 +151,7 @@ function _omz_diag_dump_one_big_text() {
|
|||
|
||||
# Core command definitions
|
||||
_omz_diag_dump_check_core_commands || return 1
|
||||
builtin echo
|
||||
builtin echo
|
||||
|
||||
# ZSH Process state
|
||||
builtin echo Process state:
|
||||
|
|
@ -167,7 +167,7 @@ function _omz_diag_dump_one_big_text() {
|
|||
#TODO: Should this include `env` instead of or in addition to `export`?
|
||||
builtin echo Exported:
|
||||
builtin echo $(builtin export | command sed 's/=.*//')
|
||||
builtin echo
|
||||
builtin echo
|
||||
builtin echo Locale:
|
||||
command locale
|
||||
builtin echo
|
||||
|
|
@ -181,7 +181,7 @@ function _omz_diag_dump_one_big_text() {
|
|||
builtin echo
|
||||
builtin echo 'compaudit output:'
|
||||
compaudit
|
||||
builtin echo
|
||||
builtin echo
|
||||
builtin echo '$fpath directories:'
|
||||
command ls -lad $fpath
|
||||
builtin echo
|
||||
|
|
@ -224,7 +224,7 @@ function _omz_diag_dump_one_big_text() {
|
|||
local cfgfile cfgfiles
|
||||
# Some files for bash that zsh does not use are intentionally included
|
||||
# to help with diagnosing behavior differences between bash and zsh
|
||||
cfgfiles=( /etc/zshenv /etc/zprofile /etc/zshrc /etc/zlogin /etc/zlogout
|
||||
cfgfiles=( /etc/zshenv /etc/zprofile /etc/zshrc /etc/zlogin /etc/zlogout
|
||||
$zdotdir/.zshenv $zdotdir/.zprofile $zdotdir/.zshrc $zdotdir/.zlogin $zdotdir/.zlogout
|
||||
~/.zsh.pre-oh-my-zsh
|
||||
/etc/bashrc /etc/profile ~/.bashrc ~/.profile ~/.bash_profile ~/.bash_logout )
|
||||
|
|
@ -258,8 +258,8 @@ function _omz_diag_dump_check_core_commands() {
|
|||
# (For back-compatibility, if any of these are newish, they should be removed,
|
||||
# or at least made conditional on the version of the current running zsh.)
|
||||
# "history" is also excluded because OMZ is known to redefine that
|
||||
reserved_words=( do done esac then elif else fi for case if while function
|
||||
repeat time until select coproc nocorrect foreach end '!' '[[' '{' '}'
|
||||
reserved_words=( do done esac then elif else fi for case if while function
|
||||
repeat time until select coproc nocorrect foreach end '!' '[[' '{' '}'
|
||||
)
|
||||
builtins=( alias autoload bg bindkey break builtin bye cd chdir command
|
||||
comparguments compcall compctl compdescribe compfiles compgroups compquote comptags
|
||||
|
|
@ -331,11 +331,11 @@ function _omz_diag_dump_os_specific_version() {
|
|||
case "$OSTYPE" in
|
||||
darwin*)
|
||||
osname=$(command sw_vers -productName)
|
||||
osver=$(command sw_vers -productVersion)
|
||||
osver=$(command sw_vers -productVersion)
|
||||
builtin echo "OS Version: $osname $osver build $(sw_vers -buildVersion)"
|
||||
;;
|
||||
cygwin)
|
||||
command systeminfo | command head -4 | command tail -2
|
||||
command systeminfo | command head -n 4 | command tail -n 2
|
||||
;;
|
||||
esac
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,17 @@
|
|||
# Changing/making/removing directory
|
||||
setopt auto_cd
|
||||
setopt auto_pushd
|
||||
setopt pushd_ignore_dups
|
||||
setopt pushdminus
|
||||
|
||||
|
||||
alias -g ...='../..'
|
||||
alias -g ....='../../..'
|
||||
alias -g .....='../../../..'
|
||||
alias -g ......='../../../../..'
|
||||
|
||||
alias -- -='cd -'
|
||||
alias 1='cd -'
|
||||
alias 1='cd -1'
|
||||
alias 2='cd -2'
|
||||
alias 3='cd -3'
|
||||
alias 4='cd -4'
|
||||
|
|
@ -26,7 +28,7 @@ function d () {
|
|||
if [[ -n $1 ]]; then
|
||||
dirs "$@"
|
||||
else
|
||||
dirs -v | head -10
|
||||
dirs -v | head -n 10
|
||||
fi
|
||||
}
|
||||
compdef _dirs d
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
function zsh_stats() {
|
||||
fc -l 1 | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n20
|
||||
fc -l 1 \
|
||||
| awk '{ CMD[$2]++; count++; } END { for (a in CMD) print CMD[a] " " CMD[a]*100/count "% " a }' \
|
||||
| grep -v "./" | sort -nr | head -n 20 | column -c3 -s " " -t | nl
|
||||
}
|
||||
|
||||
function uninstall_oh_my_zsh() {
|
||||
env ZSH="$ZSH" sh "$ZSH/tools/uninstall.sh"
|
||||
command env ZSH="$ZSH" sh "$ZSH/tools/uninstall.sh"
|
||||
}
|
||||
|
||||
function upgrade_oh_my_zsh() {
|
||||
|
|
@ -11,10 +13,6 @@ function upgrade_oh_my_zsh() {
|
|||
omz update
|
||||
}
|
||||
|
||||
function take() {
|
||||
mkdir -p $@ && cd ${@:$#}
|
||||
}
|
||||
|
||||
function open_command() {
|
||||
local open_cmd
|
||||
|
||||
|
|
@ -32,9 +30,48 @@ function open_command() {
|
|||
;;
|
||||
esac
|
||||
|
||||
# If a URL is passed, $BROWSER might be set to a local browser within SSH.
|
||||
# See https://github.com/ohmyzsh/ohmyzsh/issues/11098
|
||||
if [[ -n "$BROWSER" && "$1" = (http|https)://* ]]; then
|
||||
"$BROWSER" "$@"
|
||||
return
|
||||
fi
|
||||
|
||||
${=open_cmd} "$@" &>/dev/null
|
||||
}
|
||||
|
||||
# take functions
|
||||
|
||||
# mkcd is equivalent to takedir
|
||||
function mkcd takedir() {
|
||||
mkdir -p $@ && cd ${@:$#}
|
||||
}
|
||||
|
||||
function takeurl() {
|
||||
local data thedir
|
||||
data="$(mktemp)"
|
||||
curl -L "$1" > "$data"
|
||||
tar xf "$data"
|
||||
thedir="$(tar tf "$data" | head -n 1)"
|
||||
rm "$data"
|
||||
cd "$thedir"
|
||||
}
|
||||
|
||||
function takegit() {
|
||||
git clone "$1"
|
||||
cd "$(basename ${1%%.git})"
|
||||
}
|
||||
|
||||
function take() {
|
||||
if [[ $1 =~ ^(https?|ftp).*\.(tar\.(gz|bz2|xz)|tgz)$ ]]; then
|
||||
takeurl "$1"
|
||||
elif [[ $1 =~ ^([A-Za-z0-9]\+@|https?|git|ssh|ftps?|rsync).*\.git/?$ ]]; then
|
||||
takegit "$1"
|
||||
else
|
||||
takedir "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# Get the value of an alias.
|
||||
#
|
||||
|
|
@ -114,7 +151,7 @@ zmodload zsh/langinfo
|
|||
# Returns nonzero if encoding failed.
|
||||
#
|
||||
# Usage:
|
||||
# omz_urlencode [-r] [-m] [-P] <string>
|
||||
# omz_urlencode [-r] [-m] [-P] <string> [<string> ...]
|
||||
#
|
||||
# -r causes reserved characters (;/?:@&=+$,) to be escaped
|
||||
#
|
||||
|
|
@ -123,9 +160,10 @@ zmodload zsh/langinfo
|
|||
# -P causes spaces to be encoded as '%20' instead of '+'
|
||||
function omz_urlencode() {
|
||||
emulate -L zsh
|
||||
local -a opts
|
||||
zparseopts -D -E -a opts r m P
|
||||
|
||||
local in_str=$1
|
||||
local in_str="$@"
|
||||
local url_str=""
|
||||
local spaces_as_plus
|
||||
if [[ -z $opts[(r)-P] ]]; then spaces_as_plus=1; fi
|
||||
|
|
@ -144,6 +182,8 @@ function omz_urlencode() {
|
|||
fi
|
||||
|
||||
# Use LC_CTYPE=C to process text byte-by-byte
|
||||
# Note that this doesn't work in Termux, as it only has UTF-8 locale.
|
||||
# Characters will be processed as UTF-8, which is fine for URLs.
|
||||
local i byte ord LC_ALL=C
|
||||
export LC_ALL
|
||||
local reserved=';/?:@&=+$,'
|
||||
|
|
@ -168,6 +208,9 @@ function omz_urlencode() {
|
|||
else
|
||||
if [[ "$byte" == " " && -n $spaces_as_plus ]]; then
|
||||
url_str+="+"
|
||||
elif [[ "$PREFIX" = *com.termux* ]]; then
|
||||
# Termux does not have non-UTF8 locales, so just send the UTF-8 character directly
|
||||
url_str+="$byte"
|
||||
else
|
||||
ord=$(( [##16] #byte ))
|
||||
url_str+="%$ord"
|
||||
|
|
@ -206,12 +249,11 @@ function omz_urldecode {
|
|||
tmp=${tmp:gs/\\/\\\\/}
|
||||
# Handle %-escapes by turning them into `\xXX` printf escapes
|
||||
tmp=${tmp:gs/%/\\x/}
|
||||
local decoded
|
||||
eval "decoded=\$'$tmp'"
|
||||
local decoded="$(printf -- "$tmp")"
|
||||
|
||||
# Now we have a UTF-8 encoded string in the variable. We need to re-encode
|
||||
# it if caller is in a non-UTF-8 locale.
|
||||
local safe_encodings
|
||||
local -a safe_encodings
|
||||
safe_encodings=(UTF-8 utf8 US-ASCII)
|
||||
if [[ -z ${safe_encodings[(r)$caller_encoding]} ]]; then
|
||||
decoded=$(echo -E "$decoded" | iconv -f UTF-8 -t $caller_encoding)
|
||||
|
|
|
|||
216
lib/git.zsh
216
lib/git.zsh
|
|
@ -1,3 +1,5 @@
|
|||
autoload -Uz is-at-least
|
||||
|
||||
# The git prompt's git commands are read-only and should not interfere with
|
||||
# other processes. This environment variable is equivalent to running with `git
|
||||
# --no-optional-locks`, but falls back gracefully for older versions of git.
|
||||
|
|
@ -9,16 +11,85 @@ function __git_prompt_git() {
|
|||
GIT_OPTIONAL_LOCKS=0 command git "$@"
|
||||
}
|
||||
|
||||
# Outputs current branch info in prompt format
|
||||
function git_prompt_info() {
|
||||
local ref
|
||||
if [[ "$(__git_prompt_git config --get oh-my-zsh.hide-status 2>/dev/null)" != "1" ]]; then
|
||||
ref=$(__git_prompt_git symbolic-ref HEAD 2> /dev/null) || \
|
||||
ref=$(__git_prompt_git rev-parse --short HEAD 2> /dev/null) || return 0
|
||||
echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
|
||||
function _omz_git_prompt_info() {
|
||||
# If we are on a folder not tracked by git, get out.
|
||||
# Otherwise, check for hide-info at global and local repository level
|
||||
if ! __git_prompt_git rev-parse --git-dir &> /dev/null \
|
||||
|| [[ "$(__git_prompt_git config --get oh-my-zsh.hide-info 2>/dev/null)" == 1 ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Get either:
|
||||
# - the current branch name
|
||||
# - the tag name if we are on a tag
|
||||
# - the short SHA of the current commit
|
||||
local ref
|
||||
ref=$(__git_prompt_git symbolic-ref --short HEAD 2> /dev/null) \
|
||||
|| ref=$(__git_prompt_git describe --tags --exact-match HEAD 2> /dev/null) \
|
||||
|| ref=$(__git_prompt_git rev-parse --short HEAD 2> /dev/null) \
|
||||
|| return 0
|
||||
|
||||
# Use global ZSH_THEME_GIT_SHOW_UPSTREAM=1 for including upstream remote info
|
||||
local upstream
|
||||
if (( ${+ZSH_THEME_GIT_SHOW_UPSTREAM} )); then
|
||||
upstream=$(__git_prompt_git rev-parse --abbrev-ref --symbolic-full-name "@{upstream}" 2>/dev/null) \
|
||||
&& upstream=" -> ${upstream}"
|
||||
fi
|
||||
|
||||
echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${ref:gs/%/%%}${upstream:gs/%/%%}$(parse_git_dirty)${ZSH_THEME_GIT_PROMPT_SUFFIX}"
|
||||
}
|
||||
|
||||
# Use async version if setting is enabled, or unset but zsh version is at least 5.0.6.
|
||||
# This avoids async prompt issues caused by previous zsh versions:
|
||||
# - https://github.com/ohmyzsh/ohmyzsh/issues/12331
|
||||
# - https://github.com/ohmyzsh/ohmyzsh/issues/12360
|
||||
# TODO(2024-06-12): @mcornella remove workaround when CentOS 7 reaches EOL
|
||||
if zstyle -t ':omz:alpha:lib:git' async-prompt \
|
||||
|| { is-at-least 5.0.6 && zstyle -T ':omz:alpha:lib:git' async-prompt }; then
|
||||
function git_prompt_info() {
|
||||
if [[ -n "${_OMZ_ASYNC_OUTPUT[_omz_git_prompt_info]}" ]]; then
|
||||
echo -n "${_OMZ_ASYNC_OUTPUT[_omz_git_prompt_info]}"
|
||||
fi
|
||||
}
|
||||
|
||||
function git_prompt_status() {
|
||||
if [[ -n "${_OMZ_ASYNC_OUTPUT[_omz_git_prompt_status]}" ]]; then
|
||||
echo -n "${_OMZ_ASYNC_OUTPUT[_omz_git_prompt_status]}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Conditionally register the async handler, only if it's needed in $PROMPT
|
||||
# or any of the other prompt variables
|
||||
function _defer_async_git_register() {
|
||||
# Check if git_prompt_info is used in a prompt variable
|
||||
case "${PS1}:${PS2}:${PS3}:${PS4}:${RPROMPT}:${RPS1}:${RPS2}:${RPS3}:${RPS4}" in
|
||||
*(\$\(git_prompt_info\)|\`git_prompt_info\`)*)
|
||||
_omz_register_handler _omz_git_prompt_info
|
||||
;;
|
||||
esac
|
||||
|
||||
case "${PS1}:${PS2}:${PS3}:${PS4}:${RPROMPT}:${RPS1}:${RPS2}:${RPS3}:${RPS4}" in
|
||||
*(\$\(git_prompt_status\)|\`git_prompt_status\`)*)
|
||||
_omz_register_handler _omz_git_prompt_status
|
||||
;;
|
||||
esac
|
||||
|
||||
add-zsh-hook -d precmd _defer_async_git_register
|
||||
unset -f _defer_async_git_register
|
||||
}
|
||||
|
||||
# Register the async handler first. This needs to be done before
|
||||
# the async request prompt is run
|
||||
precmd_functions=(_defer_async_git_register $precmd_functions)
|
||||
else
|
||||
function git_prompt_info() {
|
||||
_omz_git_prompt_info
|
||||
}
|
||||
function git_prompt_status() {
|
||||
_omz_git_prompt_status
|
||||
}
|
||||
fi
|
||||
|
||||
# Checks if working tree is dirty
|
||||
function parse_git_dirty() {
|
||||
local STATUS
|
||||
|
|
@ -38,7 +109,7 @@ function parse_git_dirty() {
|
|||
FLAGS+="--ignore-submodules=${GIT_STATUS_IGNORE_SUBMODULES:-dirty}"
|
||||
;;
|
||||
esac
|
||||
STATUS=$(__git_prompt_git status ${FLAGS} 2> /dev/null | tail -n1)
|
||||
STATUS=$(__git_prompt_git status ${FLAGS} 2> /dev/null | tail -n 1)
|
||||
fi
|
||||
if [[ -n $STATUS ]]; then
|
||||
echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
|
||||
|
|
@ -69,7 +140,7 @@ function git_remote_status() {
|
|||
fi
|
||||
|
||||
if [[ -n $ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_DETAILED ]]; then
|
||||
git_remote_status="$ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_PREFIX$remote$git_remote_status_detailed$ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_SUFFIX"
|
||||
git_remote_status="$ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_PREFIX${remote:gs/%/%%}$git_remote_status_detailed$ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_SUFFIX"
|
||||
fi
|
||||
|
||||
echo $git_remote_status
|
||||
|
|
@ -147,44 +218,103 @@ function git_prompt_long_sha() {
|
|||
SHA=$(__git_prompt_git rev-parse HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
|
||||
}
|
||||
|
||||
# Get the status of the working tree
|
||||
function git_prompt_status() {
|
||||
emulate -L zsh
|
||||
function _omz_git_prompt_status() {
|
||||
[[ "$(__git_prompt_git config --get oh-my-zsh.hide-status 2>/dev/null)" = 1 ]] && return
|
||||
|
||||
local INDEX STATUS
|
||||
INDEX=$(__git_prompt_git status --porcelain -b 2> /dev/null) || return 0
|
||||
STATUS=""
|
||||
if [[ "${INDEX}" =~ $'(^|\n)\\?\\? ' ]]; then
|
||||
STATUS="$ZSH_THEME_GIT_PROMPT_UNTRACKED$STATUS"
|
||||
# Maps a git status prefix to an internal constant
|
||||
# This cannot use the prompt constants, as they may be empty
|
||||
local -A prefix_constant_map
|
||||
prefix_constant_map=(
|
||||
'\?\? ' 'UNTRACKED'
|
||||
'A ' 'ADDED'
|
||||
'M ' 'ADDED'
|
||||
'MM ' 'MODIFIED'
|
||||
' M ' 'MODIFIED'
|
||||
'AM ' 'MODIFIED'
|
||||
' T ' 'MODIFIED'
|
||||
'R ' 'RENAMED'
|
||||
' D ' 'DELETED'
|
||||
'D ' 'DELETED'
|
||||
'UU ' 'UNMERGED'
|
||||
'ahead' 'AHEAD'
|
||||
'behind' 'BEHIND'
|
||||
'diverged' 'DIVERGED'
|
||||
'stashed' 'STASHED'
|
||||
)
|
||||
|
||||
# Maps the internal constant to the prompt theme
|
||||
local -A constant_prompt_map
|
||||
constant_prompt_map=(
|
||||
'UNTRACKED' "$ZSH_THEME_GIT_PROMPT_UNTRACKED"
|
||||
'ADDED' "$ZSH_THEME_GIT_PROMPT_ADDED"
|
||||
'MODIFIED' "$ZSH_THEME_GIT_PROMPT_MODIFIED"
|
||||
'RENAMED' "$ZSH_THEME_GIT_PROMPT_RENAMED"
|
||||
'DELETED' "$ZSH_THEME_GIT_PROMPT_DELETED"
|
||||
'UNMERGED' "$ZSH_THEME_GIT_PROMPT_UNMERGED"
|
||||
'AHEAD' "$ZSH_THEME_GIT_PROMPT_AHEAD"
|
||||
'BEHIND' "$ZSH_THEME_GIT_PROMPT_BEHIND"
|
||||
'DIVERGED' "$ZSH_THEME_GIT_PROMPT_DIVERGED"
|
||||
'STASHED' "$ZSH_THEME_GIT_PROMPT_STASHED"
|
||||
)
|
||||
|
||||
# The order that the prompt displays should be added to the prompt
|
||||
local status_constants
|
||||
status_constants=(
|
||||
UNTRACKED ADDED MODIFIED RENAMED DELETED
|
||||
STASHED UNMERGED AHEAD BEHIND DIVERGED
|
||||
)
|
||||
|
||||
local status_text
|
||||
status_text="$(__git_prompt_git status --porcelain -b 2> /dev/null)"
|
||||
|
||||
# Don't continue on a catastrophic failure
|
||||
if [[ $? -eq 128 ]]; then
|
||||
return 1
|
||||
fi
|
||||
if [[ "${INDEX}" =~ $'(^|\n)(A |M |MM) ' ]]; then
|
||||
STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS"
|
||||
|
||||
# A lookup table of each git status encountered
|
||||
local -A statuses_seen
|
||||
|
||||
if __git_prompt_git rev-parse --verify refs/stash &>/dev/null; then
|
||||
statuses_seen[STASHED]=1
|
||||
fi
|
||||
if [[ "${INDEX}" =~ $'(^|\n)([ AM]M| T) ' ]]; then
|
||||
STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS"
|
||||
|
||||
local status_lines
|
||||
status_lines=("${(@f)${status_text}}")
|
||||
|
||||
# If the tracking line exists, get and parse it
|
||||
if [[ "$status_lines[1]" =~ "^## [^ ]+ \[(.*)\]" ]]; then
|
||||
local branch_statuses
|
||||
branch_statuses=("${(@s/,/)match}")
|
||||
for branch_status in $branch_statuses; do
|
||||
if [[ ! $branch_status =~ "(behind|diverged|ahead) ([0-9]+)?" ]]; then
|
||||
continue
|
||||
fi
|
||||
local last_parsed_status=$prefix_constant_map[$match[1]]
|
||||
statuses_seen[$last_parsed_status]=$match[2]
|
||||
done
|
||||
fi
|
||||
if [[ "${INDEX}" =~ $'(^|\n)R ' ]]; then
|
||||
STATUS="$ZSH_THEME_GIT_PROMPT_RENAMED$STATUS"
|
||||
fi
|
||||
if [[ "${INDEX}" =~ $'(^|\n)([A ]D|D ) ' ]]; then
|
||||
STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS"
|
||||
fi
|
||||
if $(__git_prompt_git rev-parse --verify refs/stash >/dev/null 2>&1); then
|
||||
STATUS="$ZSH_THEME_GIT_PROMPT_STASHED$STATUS"
|
||||
fi
|
||||
if [[ "${INDEX}" =~ $'(^|\n)UU ' ]]; then
|
||||
STATUS="$ZSH_THEME_GIT_PROMPT_UNMERGED$STATUS"
|
||||
fi
|
||||
if [[ "${INDEX}" =~ $'(^|\n)## [^ ]\+ .*ahead' ]]; then
|
||||
STATUS="$ZSH_THEME_GIT_PROMPT_AHEAD$STATUS"
|
||||
fi
|
||||
if [[ "${INDEX}" =~ $'(^|\n)## [^ ]\+ .*behind' ]]; then
|
||||
STATUS="$ZSH_THEME_GIT_PROMPT_BEHIND$STATUS"
|
||||
fi
|
||||
if [[ "${INDEX}" =~ $'(^|\n)## [^ ]\+ .*diverged' ]]; then
|
||||
STATUS="$ZSH_THEME_GIT_PROMPT_DIVERGED$STATUS"
|
||||
fi
|
||||
echo $STATUS
|
||||
|
||||
# For each status prefix, do a regex comparison
|
||||
for status_prefix in ${(k)prefix_constant_map}; do
|
||||
local status_constant="${prefix_constant_map[$status_prefix]}"
|
||||
local status_regex=$'(^|\n)'"$status_prefix"
|
||||
|
||||
if [[ "$status_text" =~ $status_regex ]]; then
|
||||
statuses_seen[$status_constant]=1
|
||||
fi
|
||||
done
|
||||
|
||||
# Display the seen statuses in the order specified
|
||||
local status_prompt
|
||||
for status_constant in $status_constants; do
|
||||
if (( ${+statuses_seen[$status_constant]} )); then
|
||||
local next_display=$constant_prompt_map[$status_constant]
|
||||
status_prompt="$next_display$status_prompt"
|
||||
fi
|
||||
done
|
||||
|
||||
echo $status_prompt
|
||||
}
|
||||
|
||||
# Outputs the name of the current user
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ else
|
|||
if [[ -n "$GREP_OPTIONS" ]]; then
|
||||
# export grep, egrep and fgrep settings
|
||||
alias grep="grep $GREP_OPTIONS"
|
||||
alias egrep="egrep $GREP_OPTIONS"
|
||||
alias fgrep="fgrep $GREP_OPTIONS"
|
||||
alias egrep="grep -E $GREP_OPTIONS"
|
||||
alias fgrep="grep -F $GREP_OPTIONS"
|
||||
|
||||
# write to cache file if cache directory is writable
|
||||
if [[ -w "$ZSH_CACHE_DIR" ]]; then
|
||||
|
|
|
|||
|
|
@ -1,18 +1,27 @@
|
|||
## History wrapper
|
||||
function omz_history {
|
||||
local clear list
|
||||
zparseopts -E c=clear l=list
|
||||
# parse arguments and remove from $@
|
||||
local clear list stamp REPLY
|
||||
zparseopts -E -D c=clear l=list f=stamp E=stamp i=stamp t:=stamp
|
||||
|
||||
if [[ -n "$clear" ]]; then
|
||||
# if -c provided, clobber the history file
|
||||
echo -n >| "$HISTFILE"
|
||||
echo >&2 History file deleted. Reload the session to see its effects.
|
||||
elif [[ -n "$list" ]]; then
|
||||
# if -l provided, run as if calling `fc' directly
|
||||
builtin fc "$@"
|
||||
|
||||
# confirm action before deleting history
|
||||
print -nu2 "This action will irreversibly delete your command history. Are you sure? [y/N] "
|
||||
builtin read -E
|
||||
[[ "$REPLY" = [yY] ]] || return 0
|
||||
|
||||
print -nu2 >| "$HISTFILE"
|
||||
fc -p "$HISTFILE"
|
||||
|
||||
print -u2 History file deleted.
|
||||
elif [[ $# -eq 0 ]]; then
|
||||
# if no arguments provided, show full history starting from 1
|
||||
builtin fc $stamp -l 1
|
||||
else
|
||||
# unless a number is provided, show all history events (starting from 1)
|
||||
[[ ${@[-1]-} = *[0-9]* ]] && builtin fc -l "$@" || builtin fc -l "$@" 1
|
||||
# otherwise, run `fc -l` with a custom format
|
||||
builtin fc $stamp -l "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,19 +32,26 @@ if [[ -n "${terminfo[knp]}" ]]; then
|
|||
fi
|
||||
|
||||
# Start typing + [Up-Arrow] - fuzzy find history forward
|
||||
if [[ -n "${terminfo[kcuu1]}" ]]; then
|
||||
autoload -U up-line-or-beginning-search
|
||||
zle -N up-line-or-beginning-search
|
||||
autoload -U up-line-or-beginning-search
|
||||
zle -N up-line-or-beginning-search
|
||||
|
||||
bindkey -M emacs "^[[A" up-line-or-beginning-search
|
||||
bindkey -M viins "^[[A" up-line-or-beginning-search
|
||||
bindkey -M vicmd "^[[A" up-line-or-beginning-search
|
||||
if [[ -n "${terminfo[kcuu1]}" ]]; then
|
||||
bindkey -M emacs "${terminfo[kcuu1]}" up-line-or-beginning-search
|
||||
bindkey -M viins "${terminfo[kcuu1]}" up-line-or-beginning-search
|
||||
bindkey -M vicmd "${terminfo[kcuu1]}" up-line-or-beginning-search
|
||||
fi
|
||||
# Start typing + [Down-Arrow] - fuzzy find history backward
|
||||
if [[ -n "${terminfo[kcud1]}" ]]; then
|
||||
autoload -U down-line-or-beginning-search
|
||||
zle -N down-line-or-beginning-search
|
||||
|
||||
# Start typing + [Down-Arrow] - fuzzy find history backward
|
||||
autoload -U down-line-or-beginning-search
|
||||
zle -N down-line-or-beginning-search
|
||||
|
||||
bindkey -M emacs "^[[B" down-line-or-beginning-search
|
||||
bindkey -M viins "^[[B" down-line-or-beginning-search
|
||||
bindkey -M vicmd "^[[B" down-line-or-beginning-search
|
||||
if [[ -n "${terminfo[kcud1]}" ]]; then
|
||||
bindkey -M emacs "${terminfo[kcud1]}" down-line-or-beginning-search
|
||||
bindkey -M viins "${terminfo[kcud1]}" down-line-or-beginning-search
|
||||
bindkey -M vicmd "${terminfo[kcud1]}" down-line-or-beginning-search
|
||||
|
|
|
|||
21
lib/misc.zsh
21
lib/misc.zsh
|
|
@ -15,21 +15,24 @@ if [[ $DISABLE_MAGIC_FUNCTIONS != true ]]; then
|
|||
done
|
||||
fi
|
||||
|
||||
## jobs
|
||||
setopt long_list_jobs
|
||||
setopt multios # enable redirect to multiple streams: echo >file1 >file2
|
||||
setopt long_list_jobs # show long list format job notifications
|
||||
setopt interactivecomments # recognize comments
|
||||
|
||||
env_default 'PAGER' 'less'
|
||||
env_default 'LESS' '-R'
|
||||
# define pager dependant on what is available (less or more)
|
||||
if (( ${+commands[less]} )); then
|
||||
env_default 'PAGER' 'less'
|
||||
env_default 'LESS' '-R'
|
||||
elif (( ${+commands[more]} )); then
|
||||
env_default 'PAGER' 'more'
|
||||
fi
|
||||
|
||||
## super user alias
|
||||
alias _='sudo '
|
||||
|
||||
## more intelligent acking for ubuntu users
|
||||
## more intelligent acking for ubuntu users and no alias for users without ack
|
||||
if (( $+commands[ack-grep] )); then
|
||||
alias afind='ack-grep -il'
|
||||
else
|
||||
elif (( $+commands[ack] )); then
|
||||
alias afind='ack -il'
|
||||
fi
|
||||
|
||||
# recognize comments
|
||||
setopt interactivecomments
|
||||
|
|
|
|||
11
lib/nvm.zsh
11
lib/nvm.zsh
|
|
@ -1,9 +1,6 @@
|
|||
# get the node.js version
|
||||
# get the nvm-controlled node.js version
|
||||
function nvm_prompt_info() {
|
||||
[[ -f "$NVM_DIR/nvm.sh" ]] || return
|
||||
local nvm_prompt
|
||||
nvm_prompt=$(node -v 2>/dev/null)
|
||||
[[ "${nvm_prompt}x" == "x" ]] && return
|
||||
nvm_prompt=${nvm_prompt:1}
|
||||
echo "${ZSH_THEME_NVM_PROMPT_PREFIX}${nvm_prompt}${ZSH_THEME_NVM_PROMPT_SUFFIX}"
|
||||
which nvm &>/dev/null || return
|
||||
local nvm_prompt=${$(nvm current)#v}
|
||||
echo "${ZSH_THEME_NVM_PROMPT_PREFIX}${nvm_prompt:gs/%/%%}${ZSH_THEME_NVM_PROMPT_SUFFIX}"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ function chruby_prompt_info \
|
|||
vi_mode_prompt_info \
|
||||
virtualenv_prompt_info \
|
||||
jenv_prompt_info \
|
||||
azure_prompt_info \
|
||||
tf_prompt_info \
|
||||
{
|
||||
return 1
|
||||
}
|
||||
|
|
@ -29,7 +31,7 @@ function rvm_prompt_info() {
|
|||
local rvm_prompt
|
||||
rvm_prompt=$($HOME/.rvm/bin/rvm-prompt ${=ZSH_THEME_RVM_PROMPT_OPTIONS} 2>/dev/null)
|
||||
[[ -z "${rvm_prompt}" ]] && return 1
|
||||
echo "${ZSH_THEME_RUBY_PROMPT_PREFIX}${rvm_prompt}${ZSH_THEME_RUBY_PROMPT_SUFFIX}"
|
||||
echo "${ZSH_THEME_RUBY_PROMPT_PREFIX}${rvm_prompt:gs/%/%%}${ZSH_THEME_RUBY_PROMPT_SUFFIX}"
|
||||
}
|
||||
|
||||
ZSH_THEME_RVM_PROMPT_OPTIONS="i v g"
|
||||
|
|
@ -38,5 +40,5 @@ ZSH_THEME_RVM_PROMPT_OPTIONS="i v g"
|
|||
# use this to enable users to see their ruby version, no matter which
|
||||
# version management system they use
|
||||
function ruby_prompt_info() {
|
||||
echo $(rvm_prompt_info || rbenv_prompt_info || chruby_prompt_info)
|
||||
echo "$(rvm_prompt_info || rbenv_prompt_info || chruby_prompt_info)"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ typeset -AHg FX FG BG
|
|||
FX=(
|
||||
reset "%{[00m%}"
|
||||
bold "%{[01m%}" no-bold "%{[22m%}"
|
||||
dim "%{[02m%}" no-dim "%{[22m%}"
|
||||
italic "%{[03m%}" no-italic "%{[23m%}"
|
||||
underline "%{[04m%}" no-underline "%{[24m%}"
|
||||
blink "%{[05m%}" no-blink "%{[25m%}"
|
||||
|
|
@ -20,16 +21,18 @@ done
|
|||
|
||||
# Show all 256 colors with color number
|
||||
function spectrum_ls() {
|
||||
setopt localoptions nopromptsubst
|
||||
local ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-Arma virumque cano Troiae qui primus ab oris}
|
||||
for code in {000..255}; do
|
||||
print -P -- "$code: $FG[$code]$ZSH_SPECTRUM_TEXT%{$reset_color%}"
|
||||
print -P -- "$code: ${FG[$code]}${ZSH_SPECTRUM_TEXT}%{$reset_color%}"
|
||||
done
|
||||
}
|
||||
|
||||
# Show all 256 colors where the background is set to specific color
|
||||
function spectrum_bls() {
|
||||
setopt localoptions nopromptsubst
|
||||
local ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-Arma virumque cano Troiae qui primus ab oris}
|
||||
for code in {000..255}; do
|
||||
print -P -- "$code: $BG[$code]$ZSH_SPECTRUM_TEXT%{$reset_color%}"
|
||||
print -P -- "$code: ${BG[$code]}${ZSH_SPECTRUM_TEXT}%{$reset_color%}"
|
||||
done
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,34 +7,31 @@
|
|||
# (In screen, only short_tab_title is used)
|
||||
# Limited support for Apple Terminal (Terminal can't set window and tab separately)
|
||||
function title {
|
||||
emulate -L zsh
|
||||
setopt prompt_subst
|
||||
setopt localoptions nopromptsubst
|
||||
|
||||
[[ "$EMACS" == *term* ]] && return
|
||||
# Don't set the title if inside emacs, unless using vterm
|
||||
[[ -n "${INSIDE_EMACS:-}" && "$INSIDE_EMACS" != vterm ]] && return
|
||||
|
||||
# if $2 is unset use $1 as default
|
||||
# if it is set and empty, leave it as is
|
||||
: ${2=$1}
|
||||
|
||||
case "$TERM" in
|
||||
cygwin|xterm*|putty*|rxvt*|konsole*|ansi|mlterm*)
|
||||
print -Pn "\e]2;$2:q\a" # set window name
|
||||
print -Pn "\e]1;$1:q\a" # set tab name
|
||||
cygwin|xterm*|putty*|rxvt*|konsole*|ansi|mlterm*|alacritty*|st*|foot*|contour*)
|
||||
print -Pn "\e]2;${2:q}\a" # set window name
|
||||
print -Pn "\e]1;${1:q}\a" # set tab name
|
||||
;;
|
||||
screen*|tmux*)
|
||||
print -Pn "\ek$1:q\e\\" # set screen hardstatus
|
||||
print -Pn "\ek${1:q}\e\\" # set screen hardstatus
|
||||
;;
|
||||
*)
|
||||
if [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
|
||||
print -Pn "\e]2;$2:q\a" # set window name
|
||||
print -Pn "\e]1;$1:q\a" # set tab name
|
||||
print -Pn "\e]2;${2:q}\a" # set window 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 set title
|
||||
if [[ -n "$terminfo[fsl]" ]] && [[ -n "$terminfo[tsl]" ]]; then
|
||||
echoti tsl
|
||||
print -Pn "$1"
|
||||
echoti fsl
|
||||
# Try to use terminfo to set the title if the feature is available
|
||||
if (( ${+terminfo[fsl]} && ${+terminfo[tsl]} )); then
|
||||
print -Pn "${terminfo[tsl]}$1${terminfo[fsl]}"
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
|
|
@ -42,7 +39,7 @@ function title {
|
|||
}
|
||||
|
||||
ZSH_THEME_TERM_TAB_TITLE_IDLE="%15<..<%~%<<" #15 char left truncated PWD
|
||||
ZSH_THEME_TERM_TITLE_IDLE="%n@%m: %~"
|
||||
ZSH_THEME_TERM_TITLE_IDLE="%n@%m:%~"
|
||||
# Avoid duplication of directory in terminals with independent dir display
|
||||
if [[ "$TERM_PROGRAM" == Apple_Terminal ]]; then
|
||||
ZSH_THEME_TERM_TITLE_IDLE="%n@%m"
|
||||
|
|
@ -50,13 +47,13 @@ fi
|
|||
|
||||
# Runs before showing the prompt
|
||||
function omz_termsupport_precmd {
|
||||
[[ "${DISABLE_AUTO_TITLE:-}" == true ]] && return
|
||||
title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE
|
||||
[[ "${DISABLE_AUTO_TITLE:-}" != true ]] || return
|
||||
title "$ZSH_THEME_TERM_TAB_TITLE_IDLE" "$ZSH_THEME_TERM_TITLE_IDLE"
|
||||
}
|
||||
|
||||
# Runs before executing the command
|
||||
function omz_termsupport_preexec {
|
||||
[[ "${DISABLE_AUTO_TITLE:-}" == true ]] && return
|
||||
[[ "${DISABLE_AUTO_TITLE:-}" != true ]] || return
|
||||
|
||||
emulate -L zsh
|
||||
setopt extended_glob
|
||||
|
|
@ -99,39 +96,68 @@ function omz_termsupport_preexec {
|
|||
fi
|
||||
|
||||
# cmd name only, or if this is sudo or ssh, the next cmd
|
||||
local CMD=${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%}
|
||||
local CMD="${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%}"
|
||||
local LINE="${2:gs/%/%%}"
|
||||
|
||||
title '$CMD' '%100>...>$LINE%<<'
|
||||
title "$CMD" "%100>...>${LINE}%<<"
|
||||
}
|
||||
|
||||
autoload -U add-zsh-hook
|
||||
add-zsh-hook precmd omz_termsupport_precmd
|
||||
add-zsh-hook preexec omz_termsupport_preexec
|
||||
autoload -Uz add-zsh-hook
|
||||
|
||||
|
||||
# Keep Apple Terminal.app's current working directory updated
|
||||
# Based on this answer: https://superuser.com/a/315029
|
||||
# With extra fixes to handle multibyte chars and non-UTF-8 locales
|
||||
|
||||
if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]]; then
|
||||
# Emits the control sequence to notify Terminal.app of the cwd
|
||||
# Identifies the directory using a file: URI scheme, including
|
||||
# the host name to disambiguate local vs. remote paths.
|
||||
function update_terminalapp_cwd() {
|
||||
emulate -L zsh
|
||||
|
||||
# Percent-encode the host and path names.
|
||||
local URL_HOST URL_PATH
|
||||
URL_HOST="$(omz_urlencode -P $HOST)" || return 1
|
||||
URL_PATH="$(omz_urlencode -P $PWD)" || return 1
|
||||
|
||||
# Undocumented Terminal.app-specific control sequence
|
||||
printf '\e]7;%s\a' "file://$URL_HOST$URL_PATH"
|
||||
}
|
||||
|
||||
# Use a precmd hook instead of a chpwd hook to avoid contaminating output
|
||||
add-zsh-hook precmd update_terminalapp_cwd
|
||||
# Run once to get initial cwd set
|
||||
update_terminalapp_cwd
|
||||
if [[ -z "$INSIDE_EMACS" || "$INSIDE_EMACS" = vterm ]]; then
|
||||
add-zsh-hook precmd omz_termsupport_precmd
|
||||
add-zsh-hook preexec omz_termsupport_preexec
|
||||
fi
|
||||
|
||||
# Keep terminal emulator's current working directory correct,
|
||||
# even if the current working directory path contains symbolic links
|
||||
#
|
||||
# References:
|
||||
# - Apple's Terminal.app: https://superuser.com/a/315029
|
||||
# - iTerm2: https://iterm2.com/documentation-escape-codes.html (iTerm2 Extension / CurrentDir+RemoteHost)
|
||||
# - Konsole: https://bugs.kde.org/show_bug.cgi?id=327720#c1
|
||||
# - libvte (gnome-terminal, mate-terminal, …): https://bugzilla.gnome.org/show_bug.cgi?id=675987#c14
|
||||
# Apparently it had a bug before ~2012 were it would display the unknown OSC 7 code
|
||||
#
|
||||
# As of May 2021 mlterm, PuTTY, rxvt, screen, termux & xterm simply ignore the unknown OSC.
|
||||
|
||||
# Don't define the function if we're inside Emacs or in an SSH session (#11696)
|
||||
if [[ -n "$INSIDE_EMACS" || -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
# Don't define the function if we're in an unsupported terminal
|
||||
case "$TERM" in
|
||||
# all of these either process OSC 7 correctly or ignore entirely
|
||||
xterm*|putty*|rxvt*|konsole*|mlterm*|alacritty*|screen*|tmux*) ;;
|
||||
contour*|foot*) ;;
|
||||
*)
|
||||
# Terminal.app and iTerm2 process OSC 7 correctly
|
||||
case "$TERM_PROGRAM" in
|
||||
Apple_Terminal|iTerm.app) ;;
|
||||
*) return ;;
|
||||
esac ;;
|
||||
esac
|
||||
|
||||
# Emits the control sequence to notify many terminal emulators
|
||||
# of the cwd
|
||||
#
|
||||
# Identifies the directory using a file: URI scheme, including
|
||||
# the host name to disambiguate local vs. remote paths.
|
||||
function omz_termsupport_cwd {
|
||||
# Percent-encode the host and path names.
|
||||
local URL_HOST URL_PATH
|
||||
URL_HOST="$(omz_urlencode -P $HOST)" || return 1
|
||||
URL_PATH="$(omz_urlencode -P $PWD)" || return 1
|
||||
|
||||
# Konsole errors if the HOST is provided
|
||||
[[ -z "$KONSOLE_PROFILE_NAME" && -z "$KONSOLE_DBUS_SESSION" ]] || URL_HOST=""
|
||||
|
||||
# common control sequence (OSC 7) to set current host and path
|
||||
printf "\e]7;file://%s%s\e\\" "${URL_HOST}" "${URL_PATH}"
|
||||
}
|
||||
|
||||
# Use a precmd hook instead of a chpwd hook to avoid contaminating output
|
||||
# i.e. when a script or function changes directory without `cd -q`, chpwd
|
||||
# will be called the output may be swallowed by the script or function.
|
||||
add-zsh-hook precmd omz_termsupport_cwd
|
||||
|
|
|
|||
169
lib/tests/cli.test.zsh
Normal file
169
lib/tests/cli.test.zsh
Normal file
|
|
@ -0,0 +1,169 @@
|
|||
#!/usr/bin/zsh -df
|
||||
|
||||
run_awk() {
|
||||
local -a dis_plugins=(${=1})
|
||||
local input_text="$2"
|
||||
|
||||
(( ! DEBUG )) || set -xv
|
||||
|
||||
local awk_subst_plugins="\
|
||||
gsub(/[ \t]+(${(j:|:)dis_plugins})[ \t]+/, \" \") # with spaces before or after
|
||||
gsub(/[ \t]+(${(j:|:)dis_plugins})$/, \"\") # with spaces before and EOL
|
||||
gsub(/^(${(j:|:)dis_plugins})[ \t]+/, \"\") # with BOL and spaces after
|
||||
|
||||
gsub(/\((${(j:|:)dis_plugins})[ \t]+/, \"(\") # with parenthesis before and spaces after
|
||||
gsub(/[ \t]+(${(j:|:)dis_plugins})\)/, \")\") # with spaces before or parenthesis after
|
||||
gsub(/\((${(j:|:)dis_plugins})\)/, \"()\") # with only parentheses
|
||||
|
||||
gsub(/^(${(j:|:)dis_plugins})\)/, \")\") # with BOL and closing parenthesis
|
||||
gsub(/\((${(j:|:)dis_plugins})$/, \"(\") # with opening parenthesis and EOL
|
||||
"
|
||||
# Disable plugins awk script
|
||||
local awk_script="
|
||||
# if plugins=() is in oneline form, substitute disabled plugins and go to next line
|
||||
/^[ \t]*plugins=\([^#]+\).*\$/ {
|
||||
$awk_subst_plugins
|
||||
print \$0
|
||||
next
|
||||
}
|
||||
|
||||
# if plugins=() is in multiline form, enable multi flag and disable plugins if they're there
|
||||
/^[ \t]*plugins=\(/ {
|
||||
multi=1
|
||||
$awk_subst_plugins
|
||||
print \$0
|
||||
next
|
||||
}
|
||||
|
||||
# if multi flag is enabled and we find a valid closing parenthesis, remove plugins and disable multi flag
|
||||
multi == 1 && /^[^#]*\)/ {
|
||||
multi=0
|
||||
$awk_subst_plugins
|
||||
print \$0
|
||||
next
|
||||
}
|
||||
|
||||
multi == 1 && length(\$0) > 0 {
|
||||
$awk_subst_plugins
|
||||
if (length(\$0) > 0) print \$0
|
||||
next
|
||||
}
|
||||
|
||||
{ print \$0 }
|
||||
"
|
||||
|
||||
command awk "$awk_script" <<< "$input_text"
|
||||
|
||||
(( ! DEBUG )) || set +xv
|
||||
}
|
||||
|
||||
# runs awk against stdin, checks if the resulting file is not empty and then checks if the file has valid zsh syntax
|
||||
run_awk_and_test() {
|
||||
local description="$1"
|
||||
local plugins_to_disable="$2"
|
||||
local input_text="$3"
|
||||
local expected_output="$4"
|
||||
|
||||
local tmpfile==(:)
|
||||
|
||||
{
|
||||
print -u2 "Test: $description"
|
||||
DEBUG=0 run_awk "$plugins_to_disable" "$input_text" >| $tmpfile
|
||||
|
||||
if [[ ! -s "$tmpfile" ]]; then
|
||||
print -u2 "\e[31mError\e[0m: output file empty"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! zsh -n $tmpfile; then
|
||||
print -u2 "\e[31mError\e[0m: zsh syntax error"
|
||||
diff -u $tmpfile <(echo "$expected_output")
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! diff -u --color=always $tmpfile <(echo "$expected_output"); then
|
||||
if (( DEBUG )); then
|
||||
print -u2 ""
|
||||
DEBUG=1 run_awk "$plugins_to_disable" "$input_text"
|
||||
print -u2 ""
|
||||
fi
|
||||
print -u2 "\e[31mError\e[0m: output file does not match expected output"
|
||||
return 1
|
||||
fi
|
||||
|
||||
print -u2 "\e[32mSuccess\e[0m"
|
||||
} always {
|
||||
print -u2 ""
|
||||
command rm -f "$tmpfile"
|
||||
}
|
||||
}
|
||||
|
||||
# These tests are for the `omz plugin disable` command
|
||||
run_awk_and_test \
|
||||
"it should delete a single plugin in oneline format" \
|
||||
"git" \
|
||||
"plugins=(git)" \
|
||||
"plugins=()"
|
||||
|
||||
run_awk_and_test \
|
||||
"it should delete a single plugin in multiline format" \
|
||||
"github" \
|
||||
"plugins=(
|
||||
github
|
||||
)" \
|
||||
"plugins=(
|
||||
)"
|
||||
|
||||
run_awk_and_test \
|
||||
"it should delete multiple plugins in oneline format" \
|
||||
"github git z" \
|
||||
"plugins=(github git z)" \
|
||||
"plugins=()"
|
||||
|
||||
run_awk_and_test \
|
||||
"it should delete multiple plugins in multiline format" \
|
||||
"github git z" \
|
||||
"plugins=(
|
||||
github
|
||||
git
|
||||
z
|
||||
)" \
|
||||
"plugins=(
|
||||
)"
|
||||
|
||||
run_awk_and_test \
|
||||
"it should delete a single plugin among multiple in oneline format" \
|
||||
"git" \
|
||||
"plugins=(github git z)" \
|
||||
"plugins=(github z)"
|
||||
|
||||
run_awk_and_test \
|
||||
"it should delete a single plugin among multiple in multiline format" \
|
||||
"git" \
|
||||
"plugins=(
|
||||
github
|
||||
git
|
||||
z
|
||||
)" \
|
||||
"plugins=(
|
||||
github
|
||||
z
|
||||
)"
|
||||
|
||||
run_awk_and_test \
|
||||
"it should delete multiple plugins in mixed format" \
|
||||
"git z" \
|
||||
"plugins=(github
|
||||
git z)" \
|
||||
"plugins=(github
|
||||
)"
|
||||
|
||||
run_awk_and_test \
|
||||
"it should delete multiple plugins in mixed format 2" \
|
||||
"github z" \
|
||||
"plugins=(github
|
||||
git
|
||||
z)" \
|
||||
"plugins=(
|
||||
git
|
||||
)"
|
||||
|
|
@ -1,59 +1,81 @@
|
|||
# ls colors
|
||||
# Sets color variable such as $fg, $bg, $color and $reset_color
|
||||
autoload -U colors && colors
|
||||
|
||||
# Enable ls colors
|
||||
# Expand variables and commands in PROMPT variables
|
||||
setopt prompt_subst
|
||||
|
||||
# Prompt function theming defaults
|
||||
ZSH_THEME_GIT_PROMPT_PREFIX="git:(" # Beginning of the git prompt, before the branch name
|
||||
ZSH_THEME_GIT_PROMPT_SUFFIX=")" # End of the git prompt
|
||||
ZSH_THEME_GIT_PROMPT_DIRTY="*" # Text to display if the branch is dirty
|
||||
ZSH_THEME_GIT_PROMPT_CLEAN="" # Text to display if the branch is clean
|
||||
ZSH_THEME_RUBY_PROMPT_PREFIX="("
|
||||
ZSH_THEME_RUBY_PROMPT_SUFFIX=")"
|
||||
|
||||
|
||||
# Use diff --color if available
|
||||
if command diff --color /dev/null{,} &>/dev/null; then
|
||||
function diff {
|
||||
command diff --color "$@"
|
||||
}
|
||||
fi
|
||||
|
||||
# Don't set ls coloring if disabled
|
||||
[[ "$DISABLE_LS_COLORS" != true ]] || return 0
|
||||
|
||||
# Default coloring for BSD-based ls
|
||||
export LSCOLORS="Gxfxcxdxbxegedabagacad"
|
||||
|
||||
# TODO organise this chaotic logic
|
||||
|
||||
if [[ "$DISABLE_LS_COLORS" != "true" ]]; then
|
||||
# Find the option for using colors in ls, depending on the version
|
||||
if [[ "$OSTYPE" == netbsd* ]]; then
|
||||
# On NetBSD, test if "gls" (GNU ls) is installed (this one supports colors);
|
||||
# otherwise, leave ls as is, because NetBSD's ls doesn't support -G
|
||||
gls --color -d . &>/dev/null && alias ls='gls --color=tty'
|
||||
elif [[ "$OSTYPE" == openbsd* ]]; then
|
||||
# On OpenBSD, "gls" (ls from GNU coreutils) and "colorls" (ls from base,
|
||||
# with color and multibyte support) are available from ports. "colorls"
|
||||
# will be installed on purpose and can't be pulled in by installing
|
||||
# coreutils, so prefer it to "gls".
|
||||
gls --color -d . &>/dev/null && alias ls='gls --color=tty'
|
||||
colorls -G -d . &>/dev/null && alias ls='colorls -G'
|
||||
elif [[ "$OSTYPE" == (darwin|freebsd)* ]]; then
|
||||
# this is a good alias, it works by default just using $LSCOLORS
|
||||
ls -G . &>/dev/null && alias ls='ls -G'
|
||||
|
||||
# only use coreutils ls if there is a dircolors customization present ($LS_COLORS or .dircolors file)
|
||||
# otherwise, gls will use the default color scheme which is ugly af
|
||||
[[ -n "$LS_COLORS" || -f "$HOME/.dircolors" ]] && gls --color -d . &>/dev/null && alias ls='gls --color=tty'
|
||||
# Default coloring for GNU-based ls
|
||||
if [[ -z "$LS_COLORS" ]]; then
|
||||
# Define LS_COLORS via dircolors if available. Otherwise, set a default
|
||||
# equivalent to LSCOLORS (generated via https://geoff.greer.fm/lscolors)
|
||||
if (( $+commands[dircolors] )); then
|
||||
[[ -f "$HOME/.dircolors" ]] \
|
||||
&& source <(dircolors -b "$HOME/.dircolors") \
|
||||
|| source <(dircolors -b)
|
||||
else
|
||||
# For GNU ls, we use the default ls color theme. They can later be overwritten by themes.
|
||||
if [[ -z "$LS_COLORS" ]]; then
|
||||
(( $+commands[dircolors] )) && eval "$(dircolors -b)"
|
||||
fi
|
||||
|
||||
ls --color -d . &>/dev/null && alias ls='ls --color=tty' || { ls -G . &>/dev/null && alias ls='ls -G' }
|
||||
|
||||
# Take advantage of $LS_COLORS for completion as well.
|
||||
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
|
||||
export LS_COLORS="di=1;36:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43"
|
||||
fi
|
||||
fi
|
||||
|
||||
# enable diff color if possible.
|
||||
if command diff --color . . &>/dev/null; then
|
||||
alias diff='diff --color'
|
||||
fi
|
||||
function test-ls-args {
|
||||
local cmd="$1" # ls, gls, colorls, ...
|
||||
local args="${@[2,-1]}" # arguments except the first one
|
||||
command "$cmd" "$args" /dev/null &>/dev/null
|
||||
}
|
||||
|
||||
setopt auto_cd
|
||||
setopt multios
|
||||
setopt prompt_subst
|
||||
# Find the option for using colors in ls, depending on the version
|
||||
case "$OSTYPE" in
|
||||
netbsd*)
|
||||
# On NetBSD, test if `gls` (GNU ls) is installed (this one supports colors);
|
||||
# otherwise, leave ls as is, because NetBSD's ls doesn't support -G
|
||||
test-ls-args gls --color && alias ls='gls --color=tty'
|
||||
;;
|
||||
openbsd*)
|
||||
# On OpenBSD, `gls` (ls from GNU coreutils) and `colorls` (ls from base,
|
||||
# with color and multibyte support) are available from ports.
|
||||
# `colorls` will be installed on purpose and can't be pulled in by installing
|
||||
# coreutils (which might be installed for ), so prefer it to `gls`.
|
||||
test-ls-args gls --color && alias ls='gls --color=tty'
|
||||
test-ls-args colorls -G && alias ls='colorls -G'
|
||||
;;
|
||||
(darwin|freebsd)*)
|
||||
# This alias works by default just using $LSCOLORS
|
||||
test-ls-args ls -G && alias ls='ls -G'
|
||||
# Only use GNU ls if installed and there are user defaults for $LS_COLORS,
|
||||
# as the default coloring scheme is not very pretty
|
||||
zstyle -t ':omz:lib:theme-and-appearance' gnu-ls \
|
||||
&& test-ls-args gls --color \
|
||||
&& alias ls='gls --color=tty'
|
||||
;;
|
||||
*)
|
||||
if test-ls-args ls --color; then
|
||||
alias ls='ls --color=tty'
|
||||
elif test-ls-args ls -G; then
|
||||
alias ls='ls -G'
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
[[ -n "$WINDOW" ]] && SCREEN_NO="%B$WINDOW%b " || SCREEN_NO=""
|
||||
|
||||
# git theming default: Variables for theming the git info prompt
|
||||
ZSH_THEME_GIT_PROMPT_PREFIX="git:(" # Prefix at the very beginning of the prompt, before the branch name
|
||||
ZSH_THEME_GIT_PROMPT_SUFFIX=")" # At the very end of the prompt
|
||||
ZSH_THEME_GIT_PROMPT_DIRTY="*" # Text to display if the branch is dirty
|
||||
ZSH_THEME_GIT_PROMPT_CLEAN="" # Text to display if the branch is clean
|
||||
ZSH_THEME_RUBY_PROMPT_PREFIX="("
|
||||
ZSH_THEME_RUBY_PROMPT_SUFFIX=")"
|
||||
unfunction test-ls-args
|
||||
|
|
|
|||
53
lib/vcs_info.zsh
Normal file
53
lib/vcs_info.zsh
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
# Don't skip this file until a Zsh release does the necessary quoting.
|
||||
# This is because even though 5.8.1 undid recursive prompt_subst inside
|
||||
# prompt sequences, % characters in relevant fields will still be rendered
|
||||
# incorrectly in vcs_info, on all Zsh releases up to writing this.
|
||||
#
|
||||
# There is no release yet that does this right, since it requires changing
|
||||
# how what vcs_info hooks expect to receive. Even so, I'd rather be correct
|
||||
# and break custom vcs_info hooks than have a broken prompt.
|
||||
|
||||
# Quote necessary $hook_com[<field>] items just before they are used
|
||||
# in the line "VCS_INFO_hook 'post-backend'" of the VCS_INFO_formats
|
||||
# function, where <field> is:
|
||||
#
|
||||
# base: the full path of the repository's root directory.
|
||||
# base-name: the name of the repository's root directory.
|
||||
# branch: the name of the currently checked out branch.
|
||||
# misc: a string that may contain anything the vcs_info backend wants.
|
||||
# revision: an identifier of the currently checked out revision.
|
||||
# subdir: the path of the current directory relative to the
|
||||
# repository's root directory.
|
||||
#
|
||||
# This patch %-quotes these fields previous to their use in vcs_info hooks and
|
||||
# the zformat call and, eventually, when they get expanded in the prompt.
|
||||
# It's important to quote these here, and not later after hooks have modified the
|
||||
# fields, because then we could be quoting % characters from valid prompt sequences,
|
||||
# like %F{color}, %B, etc.
|
||||
#
|
||||
# 32 │ hook_com[subdir]="$(VCS_INFO_reposub ${hook_com[base]})"
|
||||
# 33 │ hook_com[subdir_orig]="${hook_com[subdir]}"
|
||||
# 34 │
|
||||
# 35 + │ for tmp in base base-name branch misc revision subdir; do
|
||||
# 36 + │ hook_com[$tmp]="${hook_com[$tmp]//\%/%%}"
|
||||
# 37 + │ done
|
||||
# 38 + │
|
||||
# 39 │ VCS_INFO_hook 'post-backend'
|
||||
#
|
||||
# This is especially important so that no command substitution is performed
|
||||
# due to malicious input as a consequence of CVE-2021-45444, which affects
|
||||
# zsh versions from 5.0.3 to 5.8.
|
||||
#
|
||||
autoload -Uz +X regexp-replace VCS_INFO_formats 2>/dev/null || return 0
|
||||
|
||||
# We use $tmp here because it's already a local variable in VCS_INFO_formats
|
||||
typeset PATCH='for tmp (base base-name branch misc revision subdir) hook_com[$tmp]="${hook_com[$tmp]//\%/%%}"'
|
||||
# Unique string to avoid reapplying the patch if this code gets called twice
|
||||
typeset PATCH_ID=vcs_info-patch-9b9840f2-91e5-4471-af84-9e9a0dc68c1b
|
||||
# Only patch the VCS_INFO_formats function if not already patched
|
||||
if [[ "$functions[VCS_INFO_formats]" != *$PATCH_ID* ]]; then
|
||||
regexp-replace 'functions[VCS_INFO_formats]' \
|
||||
"VCS_INFO_hook 'post-backend'" \
|
||||
': ${PATCH_ID}; ${PATCH}; ${MATCH}'
|
||||
fi
|
||||
unset PATCH PATCH_ID
|
||||
199
oh-my-zsh.sh
199
oh-my-zsh.sh
|
|
@ -1,28 +1,82 @@
|
|||
# ANSI formatting function (\033[<code>m)
|
||||
# 0: reset, 1: bold, 4: underline, 22: no bold, 24: no underline, 31: red, 33: yellow
|
||||
omz_f() {
|
||||
[ $# -gt 0 ] || return
|
||||
IFS=";" printf "\033[%sm" $*
|
||||
}
|
||||
# If stdout is not a terminal ignore all formatting
|
||||
[ -t 1 ] || omz_f() { :; }
|
||||
|
||||
# Protect against non-zsh execution of Oh My Zsh (use POSIX syntax here)
|
||||
[ -n "$ZSH_VERSION" ] || {
|
||||
omz_ptree() {
|
||||
# Get process tree of the current process
|
||||
pid=$$; pids="$pid"
|
||||
while [ ${pid-0} -ne 1 ] && ppid=$(ps -e -o pid,ppid | awk "\$1 == $pid { print \$2 }"); do
|
||||
pids="$pids $pid"; pid=$ppid
|
||||
done
|
||||
|
||||
# Show process tree
|
||||
case "$(uname)" in
|
||||
Linux) ps -o ppid,pid,command -f -p $pids 2>/dev/null ;;
|
||||
Darwin|*) ps -o ppid,pid,command -p $pids 2>/dev/null ;;
|
||||
esac
|
||||
|
||||
# If ps command failed, try Busybox ps
|
||||
[ $? -eq 0 ] || ps -o ppid,pid,comm | awk "NR == 1 || index(\"$pids\", \$2) != 0"
|
||||
}
|
||||
|
||||
{
|
||||
shell=$(ps -o pid,comm | awk "\$1 == $$ { print \$2 }")
|
||||
printf "$(omz_f 1 31)Error:$(omz_f 22) Oh My Zsh can't be loaded from: $(omz_f 1)${shell}$(omz_f 22). "
|
||||
printf "You need to run $(omz_f 1)zsh$(omz_f 22) instead.$(omz_f 0)\n"
|
||||
printf "$(omz_f 33)Here's the process tree:$(omz_f 22)\n\n"
|
||||
omz_ptree
|
||||
printf "$(omz_f 0)\n"
|
||||
} >&2
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
# Check if in emulation mode, if so early return
|
||||
# https://github.com/ohmyzsh/ohmyzsh/issues/11686
|
||||
[[ "$(emulate)" = zsh ]] || {
|
||||
printf "$(omz_f 1 31)Error:$(omz_f 22) Oh My Zsh can't be loaded in \`$(emulate)\` emulation mode.$(omz_f 0)\n" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
unset -f omz_f
|
||||
|
||||
# If ZSH is not defined, use the current script's directory.
|
||||
[[ -n "$ZSH" ]] || export ZSH="${${(%):-%x}:a:h}"
|
||||
|
||||
# Set ZSH_CUSTOM to the path where your custom config files
|
||||
# and plugins exists, or else we will use the default custom/
|
||||
[[ -n "$ZSH_CUSTOM" ]] || ZSH_CUSTOM="$ZSH/custom"
|
||||
|
||||
# Set ZSH_CACHE_DIR to the path where cache files should be created
|
||||
# or else we will use the default cache/
|
||||
if [[ -z "$ZSH_CACHE_DIR" ]]; then
|
||||
ZSH_CACHE_DIR="$ZSH/cache"
|
||||
[[ -n "$ZSH_CACHE_DIR" ]] || ZSH_CACHE_DIR="$ZSH/cache"
|
||||
|
||||
# Make sure $ZSH_CACHE_DIR is writable, otherwise use a directory in $HOME
|
||||
if [[ ! -w "$ZSH_CACHE_DIR" ]]; then
|
||||
ZSH_CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/oh-my-zsh"
|
||||
fi
|
||||
|
||||
# Create cache and completions dir and add to $fpath
|
||||
mkdir -p "$ZSH_CACHE_DIR/completions"
|
||||
(( ${fpath[(Ie)"$ZSH_CACHE_DIR/completions"]} )) || fpath=("$ZSH_CACHE_DIR/completions" $fpath)
|
||||
|
||||
# Check for updates on initial load...
|
||||
if [ "$DISABLE_AUTO_UPDATE" != "true" ]; then
|
||||
source $ZSH/tools/check_for_upgrade.sh
|
||||
fi
|
||||
source "$ZSH/tools/check_for_upgrade.sh"
|
||||
|
||||
# Initializes Oh My Zsh
|
||||
|
||||
# add a function path
|
||||
fpath=($ZSH/functions $ZSH/completions $fpath)
|
||||
fpath=($ZSH/{functions,completions} $ZSH_CUSTOM/{functions,completions} $fpath)
|
||||
|
||||
# Load all stock functions (from $fpath files) called below.
|
||||
autoload -U compaudit compinit
|
||||
|
||||
# Set ZSH_CUSTOM to the path where your custom config files
|
||||
# and plugins exists, or else we will use the default custom/
|
||||
if [[ -z "$ZSH_CUSTOM" ]]; then
|
||||
ZSH_CUSTOM="$ZSH/custom"
|
||||
fi
|
||||
|
||||
autoload -U compaudit compinit zrecompile
|
||||
|
||||
is_plugin() {
|
||||
local base_dir=$1
|
||||
|
|
@ -34,10 +88,10 @@ is_plugin() {
|
|||
# Add all defined plugins to fpath. This must be done
|
||||
# before running compinit.
|
||||
for plugin ($plugins); do
|
||||
if is_plugin $ZSH_CUSTOM $plugin; then
|
||||
fpath=($ZSH_CUSTOM/plugins/$plugin $fpath)
|
||||
elif is_plugin $ZSH $plugin; then
|
||||
fpath=($ZSH/plugins/$plugin $fpath)
|
||||
if is_plugin "$ZSH_CUSTOM" "$plugin"; then
|
||||
fpath=("$ZSH_CUSTOM/plugins/$plugin" $fpath)
|
||||
elif is_plugin "$ZSH" "$plugin"; then
|
||||
fpath=("$ZSH/plugins/$plugin" $fpath)
|
||||
else
|
||||
echo "[oh-my-zsh] plugin '$plugin' not found"
|
||||
fi
|
||||
|
|
@ -46,14 +100,14 @@ done
|
|||
# Figure out the SHORT hostname
|
||||
if [[ "$OSTYPE" = darwin* ]]; then
|
||||
# macOS's $HOST changes with dhcp, etc. Use ComputerName if possible.
|
||||
SHORT_HOST=$(scutil --get ComputerName 2>/dev/null) || SHORT_HOST=${HOST/.*/}
|
||||
SHORT_HOST=$(scutil --get ComputerName 2>/dev/null) || SHORT_HOST="${HOST/.*/}"
|
||||
else
|
||||
SHORT_HOST=${HOST/.*/}
|
||||
SHORT_HOST="${HOST/.*/}"
|
||||
fi
|
||||
|
||||
# Save the location of the current completion dump file.
|
||||
if [ -z "$ZSH_COMPDUMP" ]; then
|
||||
ZSH_COMPDUMP="${ZDOTDIR:-${HOME}}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
|
||||
if [[ -z "$ZSH_COMPDUMP" ]]; then
|
||||
ZSH_COMPDUMP="${ZDOTDIR:-$HOME}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
|
||||
fi
|
||||
|
||||
# Construct zcompdump OMZ metadata
|
||||
|
|
@ -67,19 +121,20 @@ if ! command grep -q -Fx "$zcompdump_revision" "$ZSH_COMPDUMP" 2>/dev/null \
|
|||
zcompdump_refresh=1
|
||||
fi
|
||||
|
||||
if [[ $ZSH_DISABLE_COMPFIX != true ]]; then
|
||||
source $ZSH/lib/compfix.zsh
|
||||
# If completion insecurities exist, warn the user
|
||||
handle_completion_insecurities
|
||||
if [[ "$ZSH_DISABLE_COMPFIX" != true ]]; then
|
||||
source "$ZSH/lib/compfix.zsh"
|
||||
# Load only from secure directories
|
||||
compinit -i -C -d "${ZSH_COMPDUMP}"
|
||||
compinit -i -d "$ZSH_COMPDUMP"
|
||||
# If completion insecurities exist, warn the user
|
||||
handle_completion_insecurities &|
|
||||
else
|
||||
# If the user wants it, load from all found directories
|
||||
compinit -u -C -d "${ZSH_COMPDUMP}"
|
||||
compinit -u -d "$ZSH_COMPDUMP"
|
||||
fi
|
||||
|
||||
# Append zcompdump metadata if missing
|
||||
if (( $zcompdump_refresh )); then
|
||||
if (( $zcompdump_refresh )) \
|
||||
|| ! command grep -q -Fx "$zcompdump_revision" "$ZSH_COMPDUMP" 2>/dev/null; then
|
||||
# Use `tee` in case the $ZSH_COMPDUMP filename is invalid, to silence the error
|
||||
# See https://github.com/ohmyzsh/ohmyzsh/commit/dd1a7269#commitcomment-39003489
|
||||
tee -a "$ZSH_COMPDUMP" &>/dev/null <<EOF
|
||||
|
|
@ -88,40 +143,92 @@ $zcompdump_revision
|
|||
$zcompdump_fpath
|
||||
EOF
|
||||
fi
|
||||
|
||||
unset zcompdump_revision zcompdump_fpath zcompdump_refresh
|
||||
|
||||
# zcompile the completion dump file if the .zwc is older or missing.
|
||||
if command mkdir "${ZSH_COMPDUMP}.lock" 2>/dev/null; then
|
||||
zrecompile -q -p "$ZSH_COMPDUMP"
|
||||
command rm -rf "$ZSH_COMPDUMP.zwc.old" "${ZSH_COMPDUMP}.lock"
|
||||
fi
|
||||
|
||||
# Load all of the config files in ~/oh-my-zsh that end in .zsh
|
||||
_omz_source() {
|
||||
local context filepath="$1"
|
||||
|
||||
# Construct zstyle context based on path
|
||||
case "$filepath" in
|
||||
lib/*) context="lib:${filepath:t:r}" ;; # :t = lib_name.zsh, :r = lib_name
|
||||
plugins/*) context="plugins:${filepath:h:t}" ;; # :h = plugins/plugin_name, :t = plugin_name
|
||||
esac
|
||||
|
||||
local disable_aliases=0
|
||||
zstyle -T ":omz:${context}" aliases || disable_aliases=1
|
||||
|
||||
# Back up alias names prior to sourcing
|
||||
local -A aliases_pre galiases_pre
|
||||
if (( disable_aliases )); then
|
||||
aliases_pre=("${(@kv)aliases}")
|
||||
galiases_pre=("${(@kv)galiases}")
|
||||
fi
|
||||
|
||||
# Source file from $ZSH_CUSTOM if it exists, otherwise from $ZSH
|
||||
if [[ -f "$ZSH_CUSTOM/$filepath" ]]; then
|
||||
source "$ZSH_CUSTOM/$filepath"
|
||||
elif [[ -f "$ZSH/$filepath" ]]; then
|
||||
source "$ZSH/$filepath"
|
||||
fi
|
||||
|
||||
# Unset all aliases that don't appear in the backed up list of aliases
|
||||
if (( disable_aliases )); then
|
||||
if (( #aliases_pre )); then
|
||||
aliases=("${(@kv)aliases_pre}")
|
||||
else
|
||||
(( #aliases )) && unalias "${(@k)aliases}"
|
||||
fi
|
||||
if (( #galiases_pre )); then
|
||||
galiases=("${(@kv)galiases_pre}")
|
||||
else
|
||||
(( #galiases )) && unalias "${(@k)galiases}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Load all of the lib files in ~/oh-my-zsh/lib that end in .zsh
|
||||
# TIP: Add files you don't want in git to .gitignore
|
||||
for config_file ($ZSH/lib/*.zsh); do
|
||||
custom_config_file="${ZSH_CUSTOM}/lib/${config_file:t}"
|
||||
[ -f "${custom_config_file}" ] && config_file=${custom_config_file}
|
||||
source $config_file
|
||||
for lib_file ("$ZSH"/lib/*.zsh); do
|
||||
_omz_source "lib/${lib_file:t}"
|
||||
done
|
||||
unset lib_file
|
||||
|
||||
# Load all of the plugins that were defined in ~/.zshrc
|
||||
for plugin ($plugins); do
|
||||
if [ -f $ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh ]; then
|
||||
source $ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh
|
||||
elif [ -f $ZSH/plugins/$plugin/$plugin.plugin.zsh ]; then
|
||||
source $ZSH/plugins/$plugin/$plugin.plugin.zsh
|
||||
fi
|
||||
_omz_source "plugins/$plugin/$plugin.plugin.zsh"
|
||||
done
|
||||
unset plugin
|
||||
|
||||
# Load all of your custom configurations from custom/
|
||||
for config_file ($ZSH_CUSTOM/*.zsh(N)); do
|
||||
source $config_file
|
||||
for config_file ("$ZSH_CUSTOM"/*.zsh(N)); do
|
||||
source "$config_file"
|
||||
done
|
||||
unset config_file
|
||||
|
||||
# Load the theme
|
||||
if [ ! "$ZSH_THEME" = "" ]; then
|
||||
if [ -f "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme" ]; then
|
||||
is_theme() {
|
||||
local base_dir=$1
|
||||
local name=$2
|
||||
builtin test -f $base_dir/$name.zsh-theme
|
||||
}
|
||||
|
||||
if [[ -n "$ZSH_THEME" ]]; then
|
||||
if is_theme "$ZSH_CUSTOM" "$ZSH_THEME"; then
|
||||
source "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme"
|
||||
elif [ -f "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme" ]; then
|
||||
elif is_theme "$ZSH_CUSTOM/themes" "$ZSH_THEME"; then
|
||||
source "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme"
|
||||
else
|
||||
elif is_theme "$ZSH/themes" "$ZSH_THEME"; then
|
||||
source "$ZSH/themes/$ZSH_THEME.zsh-theme"
|
||||
else
|
||||
echo "[oh-my-zsh] theme '$ZSH_THEME' not found"
|
||||
fi
|
||||
fi
|
||||
|
||||
# set completion colors to be the same as `ls`, after theme has been loaded
|
||||
[[ -z "$LS_COLORS" ]] || zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
|
||||
|
|
|
|||
9
plugins/1password/1password.plugin.zsh
Normal file
9
plugins/1password/1password.plugin.zsh
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# Do nothing if op is not installed
|
||||
(( ${+commands[op]} )) || return
|
||||
|
||||
# Load op completion
|
||||
eval "$(op completion zsh)"
|
||||
compdef _op op
|
||||
|
||||
# Load opswd function
|
||||
autoload -Uz opswd
|
||||
40
plugins/1password/README.md
Normal file
40
plugins/1password/README.md
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
# 1Password
|
||||
|
||||
This plugin adds 1Password functionality to oh-my-zsh.
|
||||
|
||||
To use, add `1password` to the list of plugins in your `.zshrc` file:
|
||||
|
||||
```zsh
|
||||
plugins=(... 1password)
|
||||
```
|
||||
|
||||
Then, you can use the command `opswd` to copy passwords for services into your
|
||||
clipboard.
|
||||
|
||||
## `opswd`
|
||||
|
||||
The `opswd` command is a wrapper around the `op` command. It takes a service
|
||||
name as an argument and copies the username, then the password for that service
|
||||
to the clipboard, after confirmation on the user part.
|
||||
|
||||
If the service also contains a TOTP, it is copied to the clipboard after confirmation
|
||||
on the user part. Finally, after 20 seconds, the clipboard is cleared.
|
||||
|
||||
For example, `opswd github.com` will put your GitHub username into your clipboard. Then,
|
||||
it will ask for confirmation to continue, and copy the password to your clipboard. Finally,
|
||||
if a TOTP is available, it will be copied to the clipboard after your confirmation.
|
||||
|
||||
This function has completion support, so you can use tab completion to select which
|
||||
service you want to get.
|
||||
|
||||
> NOTE: you need to be signed in for `opswd` to work. If you are using biometric unlock,
|
||||
> 1Password CLI will automatically prompt you to sign in. See:
|
||||
>
|
||||
> - [Get started with 1Password CLI 2: Sign in](https://developer.1password.com/docs/cli/get-started#sign-in)
|
||||
> - [Sign in to your 1Password account manually](https://developer.1password.com/docs/cli/sign-in-manually)
|
||||
|
||||
## Requirements
|
||||
|
||||
- [1Password CLI 2](https://developer.1password.com/docs/cli/get-started#install)
|
||||
|
||||
> NOTE: if you're using 1Password CLI 1, [see how to upgrade to CLI 2](https://developer.1password.com/docs/cli/upgrade).
|
||||
19
plugins/1password/_opswd
Normal file
19
plugins/1password/_opswd
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#compdef opswd
|
||||
|
||||
function _opswd() {
|
||||
local -a services
|
||||
services=("${(@f)$(op item list --categories Login --cache 2>/dev/null | awk 'NR != 1 { print $2 }')}")
|
||||
[[ -z "$services" ]] || compadd -a -- services
|
||||
}
|
||||
|
||||
# TODO: 2022-03-26: Remove support for op CLI 1
|
||||
autoload -Uz is-at-least
|
||||
is-at-least 2.0.0 $(op --version) || {
|
||||
function _opswd() {
|
||||
local -a services
|
||||
services=("${(@f)$(op list items --categories Login 2>/dev/null | op get item - --fields title 2>/dev/null)}")
|
||||
[[ -z "$services" ]] || compadd -a -- services
|
||||
}
|
||||
}
|
||||
|
||||
_opswd "$@"
|
||||
90
plugins/1password/opswd
Normal file
90
plugins/1password/opswd
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
#autoload
|
||||
|
||||
# opswd puts the password of the named service into the clipboard. If there's a
|
||||
# one time password, it will be copied into the clipboard after 10 seconds. The
|
||||
# clipboard is cleared after another 20 seconds.
|
||||
function opswd() {
|
||||
if [[ $# -lt 1 ]]; then
|
||||
echo "Usage: opswd <service>"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local service=$1
|
||||
|
||||
# If not logged in, print error and return
|
||||
op user list > /dev/null || return
|
||||
|
||||
local username
|
||||
# Copy the username to the clipboard
|
||||
if ! username=$(op item get "$service" --fields username 2>/dev/null); then
|
||||
echo "error: could not obtain username for $service"
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo -n "$username" | clipcopy
|
||||
echo "✔ username for service $service copied to the clipboard. Press Enter to continue"
|
||||
read
|
||||
|
||||
local password
|
||||
# Copy the password to the clipboard
|
||||
if ! password=$(op item get "$service" --fields password 2>/dev/null); then
|
||||
echo "error: could not obtain password for $service"
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo -n "$password" | clipcopy
|
||||
echo "✔ password for $service copied to clipboard. Press Enter to continue"
|
||||
read
|
||||
|
||||
# If there's a one time password, copy it to the clipboard
|
||||
local totp
|
||||
if totp=$(op item get --otp "$service" 2>/dev/null) && [[ -n "$totp" ]]; then
|
||||
echo -n "$totp" | clipcopy
|
||||
echo "✔ TOTP for $service copied to clipboard"
|
||||
fi
|
||||
|
||||
(sleep 20 && clipcopy </dev/null 2>/dev/null) &!
|
||||
}
|
||||
|
||||
# TODO: 2022-03-26: Remove support for op CLI 1
|
||||
autoload -Uz is-at-least
|
||||
is-at-least 2.0.0 $(op --version) || {
|
||||
print -ru2 ${(%):-"%F{yellow}opswd: usage with op version $(op --version) is deprecated. Upgrade to CLI 2 and reload zsh.
|
||||
For instructions, see https://developer.1password.com/docs/cli/upgrade.%f"}
|
||||
|
||||
# opswd puts the password of the named service into the clipboard. If there's a
|
||||
# one time password, it will be copied into the clipboard after 10 seconds. The
|
||||
# clipboard is cleared after another 20 seconds.
|
||||
function opswd() {
|
||||
if [[ $# -lt 1 ]]; then
|
||||
echo "Usage: opswd <service>"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local service=$1
|
||||
|
||||
# If not logged in, print error and return
|
||||
op list users > /dev/null || return
|
||||
|
||||
local password
|
||||
# Copy the password to the clipboard
|
||||
if ! password=$(op get item "$service" --fields password 2>/dev/null); then
|
||||
echo "error: could not obtain password for $service"
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo -n "$password" | clipcopy
|
||||
echo "✔ password for $service copied to clipboard"
|
||||
|
||||
# If there's a one time password, copy it to the clipboard after 5 seconds
|
||||
local totp
|
||||
if totp=$(op get totp "$service" 2>/dev/null) && [[ -n "$totp" ]]; then
|
||||
sleep 10 && echo -n "$totp" | clipcopy
|
||||
echo "✔ TOTP for $service copied to clipboard"
|
||||
fi
|
||||
|
||||
(sleep 20 && clipcopy </dev/null 2>/dev/null) &!
|
||||
}
|
||||
}
|
||||
|
||||
opswd "$@"
|
||||
13
plugins/ag/README.md
Normal file
13
plugins/ag/README.md
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# The Silver Searcher
|
||||
|
||||
This plugin provides completion support for [`ag`](https://github.com/ggreer/the_silver_searcher).
|
||||
|
||||
To use it, add ag to the plugins array in your zshrc file.
|
||||
|
||||
```zsh
|
||||
plugins=(... ag)
|
||||
```
|
||||
|
||||
## INSTALLATION NOTES
|
||||
|
||||
Besides oh-my-zsh, `ag` needs to be installed by following these steps: https://github.com/ggreer/the_silver_searcher#installing.
|
||||
66
plugins/ag/_ag
Normal file
66
plugins/ag/_ag
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
#compdef ag
|
||||
#autoload
|
||||
|
||||
typeset -A opt_args
|
||||
|
||||
# Took the liberty of not listing every option… specially aliases and -D
|
||||
_ag () {
|
||||
local -a _1st_arguments
|
||||
_1st_arguments=(
|
||||
'--ackmate:Print results in AckMate-parseable format'
|
||||
{'-A','--after'}':[LINES] Print lines after match (Default: 2)'
|
||||
{'-B','--before'}':[LINES] Print lines before match (Default: 2)'
|
||||
'--break:Print newlines between matches in different files'
|
||||
'--nobreak:Do not print newlines between matches in different files'
|
||||
{'-c','--count'}':Only print the number of matches in each file'
|
||||
'--color:Print color codes in results (Default: On)'
|
||||
'--nocolor:Do not print color codes in results'
|
||||
'--color-line-number:Color codes for line numbers (Default: 1;33)'
|
||||
'--color-match:Color codes for result match numbers (Default: 30;43)'
|
||||
'--color-path:Color codes for path names (Default: 1;32)'
|
||||
'--column:Print column numbers in results'
|
||||
{'-H','--heading'}':Print file names (On unless searching a single file)'
|
||||
'--noheading:Do not print file names (On unless searching a single file)'
|
||||
'--line-numbers:Print line numbers even for streams'
|
||||
{'-C','--context'}':[LINES] Print lines before and after matches (Default: 2)'
|
||||
'-g:[PATTERN] Print filenames matching PATTERN'
|
||||
{'-l','--files-with-matches'}':Only print filenames that contain matches'
|
||||
{'-L','--files-without-matches'}':Only print filenames that do not contain matches'
|
||||
'--no-numbers:Do not print line numbers'
|
||||
{'-o','--only-matching'}':Prints only the matching part of the lines'
|
||||
'--print-long-lines:Print matches on very long lines (Default: 2k characters)'
|
||||
'--passthrough:When searching a stream, print all lines even if they do not match'
|
||||
'--silent:Suppress all log messages, including errors'
|
||||
'--stats:Print stats (files scanned, time taken, etc.)'
|
||||
'--vimgrep:Print results like vim :vimgrep /pattern/g would'
|
||||
{'-0','--null'}':Separate filenames with null (for "xargs -0")'
|
||||
|
||||
{'-a','--all-types'}':Search all files (does not include hidden files / .gitignore)'
|
||||
'--depth:[NUM] Search up to NUM directories deep (Default: 25)'
|
||||
{'-f','--follow'}':Follow symlinks'
|
||||
{'-G','--file-search-regex'}':[PATTERN] Limit search to filenames matching PATTERN'
|
||||
'--hidden:Search hidden files (obeys .*ignore files)'
|
||||
{'-i','--ignore-case'}':Match case insensitively'
|
||||
'--ignore:[PATTERN] Ignore files/directories matching PATTERN'
|
||||
{'-m','--max-count'}':[NUM] Skip the rest of a file after NUM matches (Default: 10k)'
|
||||
{'-p','--path-to-agignore'}':[PATH] Use .agignore file at PATH'
|
||||
{'-Q','--literal'}':Do not parse PATTERN as a regular expression'
|
||||
{'-s','--case-sensitive'}':Match case'
|
||||
{'-S','--smart-case'}':Insensitive match unless PATTERN has uppercase (Default: On)'
|
||||
'--search-binary:Search binary files for matches'
|
||||
{'-t','--all-text'}':Search all text files (Hidden files not included)'
|
||||
{'-u','--unrestricted'}':Search all files (ignore .agignore and _all_)'
|
||||
{'-U','--skip-vcs-ignores'}':Ignore VCS files (stil obey .agignore)'
|
||||
{'-v','--invert-match'}':Invert match'
|
||||
{'-w','--word-regexp'}':Only match whole words'
|
||||
{'-z','--search-zip'}':Search contents of compressed (e.g., gzip) files'
|
||||
|
||||
'--list-file-types:list of supported file types'
|
||||
)
|
||||
|
||||
if [[ $words[-1] =~ "^-" ]]; then
|
||||
_describe -t commands "ag options" _1st_arguments && ret=0
|
||||
else
|
||||
_files && ret=0
|
||||
fi
|
||||
}
|
||||
9
plugins/alias-finder/.zunit.yml
Normal file
9
plugins/alias-finder/.zunit.yml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
tap: false
|
||||
directories:
|
||||
tests: tests
|
||||
output: tests/_output
|
||||
support: tests/_support
|
||||
time_limit: 0
|
||||
fail_fast: false
|
||||
allow_risky: false
|
||||
verbose: true
|
||||
|
|
@ -2,45 +2,67 @@
|
|||
|
||||
This plugin searches the defined aliases and outputs any that match the command inputted. This makes learning new aliases easier.
|
||||
|
||||
## Setup
|
||||
|
||||
To use it, add `alias-finder` to the `plugins` array of your zshrc file:
|
||||
```
|
||||
plugins=(... alias-finder)
|
||||
```
|
||||
|
||||
To enable it for every single command, set zstyle in your `~/.zshrc`.
|
||||
|
||||
```zsh
|
||||
# ~/.zshrc
|
||||
|
||||
zstyle ':omz:plugins:alias-finder' autoload yes # disabled by default
|
||||
zstyle ':omz:plugins:alias-finder' longer yes # disabled by default
|
||||
zstyle ':omz:plugins:alias-finder' exact yes # disabled by default
|
||||
zstyle ':omz:plugins:alias-finder' cheaper yes # disabled by default
|
||||
```
|
||||
|
||||
As you can see, options are also available with zstyle.
|
||||
|
||||
## Usage
|
||||
To see if there is an alias defined for the command, pass it as an argument to `alias-finder`. This can also run automatically before each command you input - add `ZSH_ALIAS_FINDER_AUTOMATIC=true` to your zshrc if you want this.
|
||||
|
||||
## Options
|
||||
When you execute a command alias finder will look at your defined aliases and suggest shorter aliases you could have used, for example:
|
||||
|
||||
- Use `--longer` or `-l` to allow the aliases to be longer than the input (match aliases if they contain the input).
|
||||
- Use `--exact` or `-e` to avoid matching aliases that are shorter than the input.
|
||||
Running the un-aliased `git status` command:
|
||||
```sh
|
||||
╭─tim@fox ~/repo/gitopolis ‹main›
|
||||
╰─$ git status
|
||||
|
||||
## Examples
|
||||
gst='git status' # <=== shorter suggestion from alias-finder
|
||||
|
||||
On branch main
|
||||
Your branch is up-to-date with 'origin/main'.
|
||||
nothing to commit, working tree clean
|
||||
```
|
||||
$ alias-finder "git pull"
|
||||
gl='git pull'
|
||||
g=git
|
||||
|
||||
Running a shorter `git st` alias from `.gitconfig` that it suggested :
|
||||
```sh
|
||||
╭─tim@fox ~/repo/gitopolis ‹main›
|
||||
╰─$ git st
|
||||
gs='git st' # <=== shorter suggestion from alias-finder
|
||||
## main...origin/main
|
||||
```
|
||||
|
||||
Running the shortest `gs` shell alias that it found:
|
||||
```sh
|
||||
╭─tim@fox ~/repo/gitopolis ‹main›
|
||||
╰─$ gs
|
||||
# <=== no suggestions alias-finder because this is the shortest
|
||||
## main...origin/main
|
||||
```
|
||||
$ alias-finder "web_search google oh my zsh"
|
||||
google='web_search google'
|
||||
```
|
||||
```
|
||||
$ alias-finder "git commit -v"
|
||||
gc="git commit -v"
|
||||
g=git
|
||||
```
|
||||
```
|
||||
$ alias-finder -e "git commit -v"
|
||||
gc='git commit -v'
|
||||
```
|
||||
```
|
||||
$ alias-finder -l "git commit -v"
|
||||
gc='git commit -v'
|
||||
'gc!'='git commit -v --amend'
|
||||
gca='git commit -v -a'
|
||||
'gca!'='git commit -v -a --amend'
|
||||
'gcan!'='git commit -v -a --no-edit --amend'
|
||||
'gcans!'='git commit -v -a -s --no-edit --amend'
|
||||
'gcn!'='git commit -v --no-edit --amend'
|
||||
```
|
||||
|
||||

|
||||
|
||||
|
||||
### Options
|
||||
|
||||
> In order to clarify, let's say `alias a=abc` has source 'abc' and destination 'a'.
|
||||
|
||||
- Use `--longer` or `-l` to include aliases where the source is longer than the input (in other words, the source could contain the whole input).
|
||||
- Use `--exact` or `-e` to avoid aliases where the source is shorter than the input (in other words, the source must be the same with the input).
|
||||
- Use `--cheaper` or `-c` to avoid aliases where the destination is longer than the input (in other words, the destination must be the shorter than the input).
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,44 +1,59 @@
|
|||
alias-finder() {
|
||||
local cmd="" exact="" longer="" wordStart="" wordEnd="" multiWordEnd=""
|
||||
for i in $@; do
|
||||
case $i in
|
||||
local cmd=" " exact="" longer="" cheaper="" wordEnd="'{0,1}$" finder="" filter=""
|
||||
|
||||
# build command and options
|
||||
for c in "$@"; do
|
||||
case $c in
|
||||
# TODO: Remove backward compatibility (other than zstyle form)
|
||||
# set options if exist
|
||||
-e|--exact) exact=true;;
|
||||
-l|--longer) longer=true;;
|
||||
*)
|
||||
if [[ -z $cmd ]]; then
|
||||
cmd=$i
|
||||
else
|
||||
cmd="$cmd $i"
|
||||
fi
|
||||
;;
|
||||
-c|--cheaper) cheaper=true;;
|
||||
# concatenate cmd
|
||||
*) cmd="$cmd$c " ;;
|
||||
esac
|
||||
done
|
||||
cmd=$(sed 's/[].\|$(){}?+*^[]/\\&/g' <<< $cmd) # adds escaping for grep
|
||||
if (( $(wc -l <<< $cmd) == 1 )); then
|
||||
while [[ $cmd != "" ]]; do
|
||||
if [[ $longer = true ]]; then
|
||||
wordStart="'{0,1}"
|
||||
else
|
||||
wordEnd="$"
|
||||
multiWordEnd="'$"
|
||||
fi
|
||||
if [[ $cmd == *" "* ]]; then
|
||||
local finder="'$cmd$multiWordEnd"
|
||||
else
|
||||
local finder=$wordStart$cmd$wordEnd
|
||||
fi
|
||||
alias | grep -E "=$finder"
|
||||
if [[ $exact = true || $longer = true ]]; then
|
||||
break
|
||||
else
|
||||
cmd=$(sed -E 's/ {0,1}[^ ]*$//' <<< $cmd) # removes last word
|
||||
fi
|
||||
done
|
||||
|
||||
zstyle -t ':omz:plugins:alias-finder' longer && longer=true
|
||||
zstyle -t ':omz:plugins:alias-finder' exact && exact=true
|
||||
zstyle -t ':omz:plugins:alias-finder' cheaper && cheaper=true
|
||||
|
||||
# format cmd for grep
|
||||
## - replace newlines with spaces
|
||||
## - trim both ends
|
||||
## - replace multiple spaces with one space
|
||||
## - add escaping character to special characters
|
||||
cmd=$(echo -n "$cmd" | tr '\n' ' ' | xargs | tr -s '[:space:]' | sed 's/[].\|$(){}?+*^[]/\\&/g')
|
||||
|
||||
if [[ $longer == true ]]; then
|
||||
wordEnd="" # remove wordEnd to find longer aliases
|
||||
fi
|
||||
|
||||
# find with alias and grep, removing last word each time until no more words
|
||||
while [[ $cmd != "" ]]; do
|
||||
finder="'{0,1}$cmd$wordEnd"
|
||||
|
||||
# make filter to find only shorter results than current cmd
|
||||
if [[ $cheaper == true ]]; then
|
||||
cmdLen=$(echo -n "$cmd" | wc -c)
|
||||
filter="^'{0,1}.{0,$((cmdLen - 1))}="
|
||||
fi
|
||||
|
||||
alias | grep -E "$filter" | grep -E "=$finder"
|
||||
|
||||
if [[ $exact == true ]]; then
|
||||
break # because exact case is only one
|
||||
elif [[ $longer = true ]]; then
|
||||
break # because above grep command already found every longer aliases during first cycle
|
||||
fi
|
||||
|
||||
cmd=$(sed -E 's/ {0,}[^ ]*$//' <<< "$cmd") # remove last word
|
||||
done
|
||||
}
|
||||
|
||||
preexec_alias-finder() {
|
||||
if [[ $ZSH_ALIAS_FINDER_AUTOMATIC = true ]]; then
|
||||
# TODO: Remove backward compatibility (other than zstyle form)
|
||||
zstyle -t ':omz:plugins:alias-finder' autoload && alias-finder $1 || if [[ $ZSH_ALIAS_FINDER_AUTOMATIC = true ]]; then
|
||||
alias-finder $1
|
||||
fi
|
||||
}
|
||||
|
|
|
|||
0
plugins/alias-finder/tests/_output/.gitkeep
Normal file
0
plugins/alias-finder/tests/_output/.gitkeep
Normal file
0
plugins/alias-finder/tests/_support/.gitkeep
Normal file
0
plugins/alias-finder/tests/_support/.gitkeep
Normal file
2
plugins/alias-finder/tests/_support/bootstrap
Normal file
2
plugins/alias-finder/tests/_support/bootstrap
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#!/usr/bin/env zsh
|
||||
# Write your bootstrap code here
|
||||
107
plugins/alias-finder/tests/test_run.sh
Normal file
107
plugins/alias-finder/tests/test_run.sh
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
#!/usr/bin/env zunit
|
||||
|
||||
@setup {
|
||||
load ../alias-finder.plugin.zsh
|
||||
|
||||
set_git_aliases() {
|
||||
unalias -a # all
|
||||
alias g="git"
|
||||
alias gc="git commit"
|
||||
alias gcv="git commit -v"
|
||||
alias gcvs="git commit -v -S"
|
||||
}
|
||||
}
|
||||
|
||||
@test 'find aliases that contain input' {
|
||||
set_git_aliases
|
||||
|
||||
run alias-finder "git"
|
||||
|
||||
assert "${#lines[@]}" equals 1
|
||||
assert "${lines[1]}" same_as "g=git"
|
||||
}
|
||||
|
||||
@test 'find aliases that contain input with whitespaces at ends' {
|
||||
set_git_aliases
|
||||
|
||||
run alias-finder " git "
|
||||
|
||||
assert "${#lines[@]}" equals 1
|
||||
assert "${lines[1]}" same_as "g=git"
|
||||
}
|
||||
|
||||
@test 'find aliases that contain multiple words' {
|
||||
set_git_aliases
|
||||
|
||||
run alias-finder "git commit -v"
|
||||
|
||||
assert "${#lines[@]}" equals 3
|
||||
assert "${lines[1]}" same_as "gcv='git commit -v'"
|
||||
assert "${lines[2]}" same_as "gc='git commit'"
|
||||
assert "${lines[3]}" same_as "g=git"
|
||||
}
|
||||
|
||||
@test 'find alias that is the same with input when --exact option is set' {
|
||||
set_git_aliases
|
||||
|
||||
run alias-finder -e "git"
|
||||
|
||||
assert "${#lines[@]}" equals 1
|
||||
assert "${lines[1]}" same_as "g=git"
|
||||
}
|
||||
|
||||
@test 'find alias that is the same with multiple words input when --exact option is set' {
|
||||
set_git_aliases
|
||||
|
||||
run alias-finder -e "git commit -v"
|
||||
|
||||
assert "${#lines[@]}" equals 1
|
||||
assert "${lines[1]}" same_as "gcv='git commit -v'"
|
||||
}
|
||||
|
||||
@test 'find alias that is the same with or longer than input when --longer option is set' {
|
||||
set_git_aliases
|
||||
|
||||
run alias-finder -l "git"
|
||||
|
||||
assert "${#lines[@]}" equals 4
|
||||
assert "${lines[1]}" same_as "g=git"
|
||||
assert "${lines[2]}" same_as "gc='git commit'"
|
||||
assert "${lines[3]}" same_as "gcv='git commit -v'"
|
||||
assert "${lines[4]}" same_as "gcvs='git commit -v -S'"
|
||||
}
|
||||
|
||||
@test 'find alias that is the same with or longer than multiple words input when --longer option is set' {
|
||||
set_git_aliases
|
||||
|
||||
run alias-finder -l "git commit -v"
|
||||
|
||||
assert "${#lines[@]}" equals 2
|
||||
assert "${lines[1]}" same_as "gcv='git commit -v'"
|
||||
assert "${lines[2]}" same_as "gcvs='git commit -v -S'"
|
||||
}
|
||||
|
||||
@test 'find aliases including expensive (longer) than input' {
|
||||
set_git_aliases
|
||||
alias expensiveCommands="git commit"
|
||||
|
||||
run alias-finder "git commit -v"
|
||||
|
||||
assert "${#lines[@]}" equals 4
|
||||
assert "${lines[1]}" same_as "gcv='git commit -v'"
|
||||
assert "${lines[2]}" same_as "expensiveCommands='git commit'"
|
||||
assert "${lines[3]}" same_as "gc='git commit'"
|
||||
assert "${lines[4]}" same_as "g=git"
|
||||
}
|
||||
|
||||
@test 'find aliases excluding expensive (longer) than input when --cheap option is set' {
|
||||
set_git_aliases
|
||||
alias expensiveCommands="git commit"
|
||||
|
||||
run alias-finder -c "git commit -v"
|
||||
|
||||
assert "${#lines[@]}" equals 3
|
||||
assert "${lines[1]}" same_as "gcv='git commit -v'"
|
||||
assert "${lines[2]}" same_as "gc='git commit'"
|
||||
assert "${lines[3]}" same_as "g=git"
|
||||
}
|
||||
1
plugins/aliases/.gitignore
vendored
Normal file
1
plugins/aliases/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
__pycache__
|
||||
28
plugins/aliases/README.md
Normal file
28
plugins/aliases/README.md
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
# Aliases cheatsheet
|
||||
|
||||
**Maintainer:** [@hqingyi](https://github.com/hqingyi)
|
||||
|
||||
With lots of 3rd-party amazing aliases installed, this plugin helps list the shortcuts
|
||||
that are currently available based on the plugins you have enabled.
|
||||
|
||||
To use it, add `aliases` to the plugins array in your zshrc file:
|
||||
|
||||
```zsh
|
||||
plugins=(aliases)
|
||||
```
|
||||
|
||||
Requirements: Python needs to be installed.
|
||||
|
||||
## Usage
|
||||
|
||||
- `als`: show all aliases by group
|
||||
|
||||
- `als -h/--help`: print help message
|
||||
|
||||
- `als <keyword(s)>`: filter and highlight aliases by `<keyword>`
|
||||
|
||||
- `als -g <group>/--group <group>`: show only aliases for group `<group>`. Multiple uses of the flag show all groups
|
||||
|
||||
- `als --groups`: show only group names
|
||||
|
||||

|
||||
14
plugins/aliases/aliases.plugin.zsh
Normal file
14
plugins/aliases/aliases.plugin.zsh
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# Handle $0 according to the standard:
|
||||
# https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html
|
||||
0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
|
||||
0="${${(M)0:#/*}:-$PWD/$0}"
|
||||
|
||||
eval '
|
||||
function als(){
|
||||
(( $+commands[python3] )) || {
|
||||
echo "[error] No python executable detected"
|
||||
return
|
||||
}
|
||||
alias | python3 "'"${0:h}"'/cheatsheet.py" "$@"
|
||||
}
|
||||
'
|
||||
69
plugins/aliases/cheatsheet.py
Normal file
69
plugins/aliases/cheatsheet.py
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
#!/usr/bin/env python3
|
||||
import sys
|
||||
import itertools
|
||||
import termcolor
|
||||
import argparse
|
||||
|
||||
def parse(line):
|
||||
left = line[0:line.find('=')].strip()
|
||||
right = line[line.find('=')+1:].strip('\'"\n ')
|
||||
try:
|
||||
cmd = next(part for part in right.split() if len([char for char in '=<>' if char in part])==0)
|
||||
except StopIteration:
|
||||
cmd = right
|
||||
return (left, right, cmd)
|
||||
|
||||
def cheatsheet(lines):
|
||||
exps = [ parse(line) for line in lines ]
|
||||
exps.sort(key=lambda exp:exp[2])
|
||||
cheatsheet = {'_default': []}
|
||||
for key, group in itertools.groupby(exps, lambda exp:exp[2]):
|
||||
group_list = [ item for item in group ]
|
||||
if len(group_list)==1:
|
||||
target_aliases = cheatsheet['_default']
|
||||
else:
|
||||
if key not in cheatsheet:
|
||||
cheatsheet[key] = []
|
||||
target_aliases = cheatsheet[key]
|
||||
target_aliases.extend(group_list)
|
||||
return cheatsheet
|
||||
|
||||
def pretty_print_group(key, aliases, highlight=None, only_groupname=False):
|
||||
if len(aliases) == 0:
|
||||
return
|
||||
group_hl_formatter = lambda g, hl: termcolor.colored(hl, 'yellow').join([termcolor.colored(part, 'red') for part in ('[%s]' % g).split(hl)])
|
||||
alias_hl_formatter = lambda alias, hl: termcolor.colored(hl, 'yellow').join([termcolor.colored(part, 'green') for part in ('\t%s = %s' % alias[0:2]).split(hl)])
|
||||
group_formatter = lambda g: termcolor.colored('[%s]' % g, 'red')
|
||||
alias_formatter = lambda alias: termcolor.colored('\t%s = %s' % alias[0:2], 'green')
|
||||
if highlight and len(highlight)>0:
|
||||
print (group_hl_formatter(key, highlight))
|
||||
if not only_groupname:
|
||||
print ('\n'.join([alias_hl_formatter(alias, highlight) for alias in aliases]))
|
||||
else:
|
||||
print (group_formatter(key))
|
||||
if not only_groupname:
|
||||
print ('\n'.join([alias_formatter(alias) for alias in aliases]))
|
||||
print ('')
|
||||
|
||||
def pretty_print(cheatsheet, wfilter, group_list=None, groups_only=False):
|
||||
sorted_key = sorted(cheatsheet.keys())
|
||||
for key in sorted_key:
|
||||
if group_list and key not in group_list:
|
||||
continue
|
||||
aliases = cheatsheet.get(key)
|
||||
if not wfilter:
|
||||
pretty_print_group(key, aliases, wfilter, groups_only)
|
||||
else:
|
||||
pretty_print_group(key, [ alias for alias in aliases if alias[0].find(wfilter)>-1 or alias[1].find(wfilter)>-1], wfilter)
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description="Pretty print aliases.", prog="als")
|
||||
parser.add_argument('filter', nargs="*", metavar="<keyword>", help="search aliases matching keywords")
|
||||
parser.add_argument('-g', '--group', dest="group_list", action='append', help="only print aliases in given groups")
|
||||
parser.add_argument('--groups', dest='groups_only', action='store_true', help="only print alias groups")
|
||||
args = parser.parse_args()
|
||||
|
||||
lines = sys.stdin.readlines()
|
||||
group_list = args.group_list or None
|
||||
wfilter = " ".join(args.filter) or None
|
||||
pretty_print(cheatsheet(lines), wfilter, group_list, args.groups_only)
|
||||
168
plugins/aliases/termcolor.py
Normal file
168
plugins/aliases/termcolor.py
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
# coding: utf-8
|
||||
# Copyright (c) 2008-2011 Volvox Development Team
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
#
|
||||
# Author: Konstantin Lepa <konstantin.lepa@gmail.com>
|
||||
|
||||
"""ANSI Color formatting for output in terminal."""
|
||||
|
||||
from __future__ import print_function
|
||||
import os
|
||||
|
||||
|
||||
__ALL__ = [ 'colored', 'cprint' ]
|
||||
|
||||
VERSION = (1, 1, 0)
|
||||
|
||||
ATTRIBUTES = dict(
|
||||
list(zip([
|
||||
'bold',
|
||||
'dark',
|
||||
'',
|
||||
'underline',
|
||||
'blink',
|
||||
'',
|
||||
'reverse',
|
||||
'concealed'
|
||||
],
|
||||
list(range(1, 9))
|
||||
))
|
||||
)
|
||||
del ATTRIBUTES['']
|
||||
|
||||
|
||||
HIGHLIGHTS = dict(
|
||||
list(zip([
|
||||
'on_grey',
|
||||
'on_red',
|
||||
'on_green',
|
||||
'on_yellow',
|
||||
'on_blue',
|
||||
'on_magenta',
|
||||
'on_cyan',
|
||||
'on_white'
|
||||
],
|
||||
list(range(40, 48))
|
||||
))
|
||||
)
|
||||
|
||||
|
||||
COLORS = dict(
|
||||
list(zip([
|
||||
'grey',
|
||||
'red',
|
||||
'green',
|
||||
'yellow',
|
||||
'blue',
|
||||
'magenta',
|
||||
'cyan',
|
||||
'white',
|
||||
],
|
||||
list(range(30, 38))
|
||||
))
|
||||
)
|
||||
|
||||
|
||||
RESET = '\033[0m'
|
||||
|
||||
|
||||
def colored(text, color=None, on_color=None, attrs=None):
|
||||
"""Colorize text.
|
||||
|
||||
Available text colors:
|
||||
red, green, yellow, blue, magenta, cyan, white.
|
||||
|
||||
Available text highlights:
|
||||
on_red, on_green, on_yellow, on_blue, on_magenta, on_cyan, on_white.
|
||||
|
||||
Available attributes:
|
||||
bold, dark, underline, blink, reverse, concealed.
|
||||
|
||||
Example:
|
||||
colored('Hello, World!', 'red', 'on_grey', ['blue', 'blink'])
|
||||
colored('Hello, World!', 'green')
|
||||
"""
|
||||
if os.getenv('ANSI_COLORS_DISABLED') is None:
|
||||
fmt_str = '\033[%dm%s'
|
||||
if color is not None:
|
||||
text = fmt_str % (COLORS[color], text)
|
||||
|
||||
if on_color is not None:
|
||||
text = fmt_str % (HIGHLIGHTS[on_color], text)
|
||||
|
||||
if attrs is not None:
|
||||
for attr in attrs:
|
||||
text = fmt_str % (ATTRIBUTES[attr], text)
|
||||
|
||||
text += RESET
|
||||
return text
|
||||
|
||||
|
||||
def cprint(text, color=None, on_color=None, attrs=None, **kwargs):
|
||||
"""Print colorize text.
|
||||
|
||||
It accepts arguments of print function.
|
||||
"""
|
||||
|
||||
print((colored(text, color, on_color, attrs)), **kwargs)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print('Current terminal type: %s' % os.getenv('TERM'))
|
||||
print('Test basic colors:')
|
||||
cprint('Grey color', 'grey')
|
||||
cprint('Red color', 'red')
|
||||
cprint('Green color', 'green')
|
||||
cprint('Yellow color', 'yellow')
|
||||
cprint('Blue color', 'blue')
|
||||
cprint('Magenta color', 'magenta')
|
||||
cprint('Cyan color', 'cyan')
|
||||
cprint('White color', 'white')
|
||||
print(('-' * 78))
|
||||
|
||||
print('Test highlights:')
|
||||
cprint('On grey color', on_color='on_grey')
|
||||
cprint('On red color', on_color='on_red')
|
||||
cprint('On green color', on_color='on_green')
|
||||
cprint('On yellow color', on_color='on_yellow')
|
||||
cprint('On blue color', on_color='on_blue')
|
||||
cprint('On magenta color', on_color='on_magenta')
|
||||
cprint('On cyan color', on_color='on_cyan')
|
||||
cprint('On white color', color='grey', on_color='on_white')
|
||||
print('-' * 78)
|
||||
|
||||
print('Test attributes:')
|
||||
cprint('Bold grey color', 'grey', attrs=['bold'])
|
||||
cprint('Dark red color', 'red', attrs=['dark'])
|
||||
cprint('Underline green color', 'green', attrs=['underline'])
|
||||
cprint('Blink yellow color', 'yellow', attrs=['blink'])
|
||||
cprint('Reversed blue color', 'blue', attrs=['reverse'])
|
||||
cprint('Concealed Magenta color', 'magenta', attrs=['concealed'])
|
||||
cprint('Bold underline reverse cyan color', 'cyan',
|
||||
attrs=['bold', 'underline', 'reverse'])
|
||||
cprint('Dark blink concealed white color', 'white',
|
||||
attrs=['dark', 'blink', 'concealed'])
|
||||
print(('-' * 78))
|
||||
|
||||
print('Test mixing:')
|
||||
cprint('Underline red on grey color', 'red', 'on_grey',
|
||||
['underline'])
|
||||
cprint('Reversed green on red color', 'green', 'on_red', ['reverse'])
|
||||
|
||||
|
|
@ -21,7 +21,6 @@ plugins=(... ansible)
|
|||
| `acon` | command `ansible-console` |
|
||||
| `ainv` | command `ansible-inventory` |
|
||||
| `aplaybook` | command `ansible-playbook` |
|
||||
| `ainv` | command `ansible-inventory` |
|
||||
| `adoc` | command `ansible-doc` |
|
||||
| `agal` | command `ansible-galaxy` |
|
||||
| `apull` | command `ansible-pull` |
|
||||
|
|
@ -29,6 +28,6 @@ plugins=(... ansible)
|
|||
|
||||
## Maintainer
|
||||
|
||||
### [Deepankumar](https://github.com/deepan10)
|
||||
### [Deepankumar](https://github.com/deepan10)
|
||||
|
||||
[https://github.com/deepan10/oh-my-zsh/tree/features/ansible-plugin](https://github.com/deepan10/oh-my-zsh/tree/features/ansible-plugin)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ function ansible-version(){
|
|||
}
|
||||
|
||||
function ansible-role-init(){
|
||||
if ! [ -z $1] ; then
|
||||
if ! [ -z $1 ] ; then
|
||||
echo "Ansible Role : $1 Creating...."
|
||||
ansible-galaxy init $1
|
||||
tree $1
|
||||
|
|
@ -25,4 +25,4 @@ alias ainv='ansible-inventory '
|
|||
alias adoc='ansible-doc '
|
||||
alias agal='ansible-galaxy '
|
||||
alias apull='ansible-pull '
|
||||
alias aval='ansible-vault'
|
||||
alias aval='ansible-vault'
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
This plugin provides completion for [Ant](https://ant.apache.org/).
|
||||
|
||||
To use it add ant to the plugins array in your zshrc file.
|
||||
To use it, add `ant` to the plugins array in your zshrc file:
|
||||
|
||||
```bash
|
||||
```zsh
|
||||
plugins=(... ant)
|
||||
```
|
||||
|
||||
|
|
|
|||
22
plugins/ant/_ant
Normal file
22
plugins/ant/_ant
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#compdef ant
|
||||
|
||||
_ant_does_target_list_need_generating () {
|
||||
[[ ! -f .ant_targets ]] && return 0
|
||||
[[ build.xml -nt .ant_targets ]] && return 0
|
||||
return 1
|
||||
}
|
||||
|
||||
_ant () {
|
||||
if [[ ! -f build.xml ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
if ! _ant_does_target_list_need_generating; then
|
||||
return
|
||||
fi
|
||||
|
||||
ant -p | awk -F " " 'NR > 5 { print lastTarget } { lastTarget = $1 }' >| .ant_targets
|
||||
compadd -- "$(cat .ant_targets)"
|
||||
}
|
||||
|
||||
_ant "$@"
|
||||
|
|
@ -1,16 +1,2 @@
|
|||
_ant_does_target_list_need_generating () {
|
||||
[ ! -f .ant_targets ] && return 0;
|
||||
[ build.xml -nt .ant_targets ] && return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
_ant () {
|
||||
if [ -f build.xml ]; then
|
||||
if _ant_does_target_list_need_generating; then
|
||||
ant -p | awk -F " " 'NR > 5 { print lastTarget }{lastTarget = $1}' > .ant_targets
|
||||
fi
|
||||
compadd -- `cat .ant_targets`
|
||||
fi
|
||||
}
|
||||
|
||||
compdef _ant ant
|
||||
# Default to colored output
|
||||
export ANT_ARGS='-logger org.apache.tools.ant.listener.AnsiColorLogger'
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ plugins=(... arcanist)
|
|||
| ------- | ---------------------------------- |
|
||||
| ara | `arc amend` |
|
||||
| arb | `arc branch` |
|
||||
| arbl | `arc bland` |
|
||||
| arco | `arc cover` |
|
||||
| arci | `arc commit` |
|
||||
| ard | `arc diff` |
|
||||
|
|
@ -24,6 +25,7 @@ plugins=(... arcanist)
|
|||
| ardpc | `arc diff --plan-changes` |
|
||||
| are | `arc export` |
|
||||
| arh | `arc help` |
|
||||
| arho | `arc hotfix` |
|
||||
| arl | `arc land` |
|
||||
| arli | `arc lint` |
|
||||
| arls | `arc list` |
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
alias ara='arc amend'
|
||||
alias arb='arc branch'
|
||||
alias arbl='arc bland'
|
||||
alias arco='arc cover'
|
||||
alias arci='arc commit'
|
||||
|
||||
|
|
@ -17,6 +18,7 @@ alias ardp='arc diff --preview' # creates a new diff in the phab interface
|
|||
|
||||
alias are='arc export'
|
||||
alias arh='arc help'
|
||||
alias arho='arc hotfix'
|
||||
alias arl='arc land'
|
||||
alias arli='arc lint'
|
||||
alias arls='arc list'
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
# Archlinux plugin
|
||||
# Arch Linux plugin
|
||||
|
||||
This plugin adds some aliases and functions to work with Arch Linux.
|
||||
|
||||
|
|
@ -10,145 +10,175 @@ plugins=(... archlinux)
|
|||
|
||||
## Features
|
||||
|
||||
#### YAY
|
||||
### Pacman
|
||||
|
||||
| Alias | Command | Description |
|
||||
|---------|------------------------------------|---------------------------------------------------------------------|
|
||||
| yaconf | yay -Pg | Print current configuration |
|
||||
| yain | yay -S | Install packages from the repositories |
|
||||
| yains | yay -U | Install a package from a local file |
|
||||
| yainsd | yay -S --asdeps | Install packages as dependencies of another package |
|
||||
| yaloc | yay -Qi | Display information about a package in the local database |
|
||||
| yalocs | yay -Qs | Search for packages in the local database |
|
||||
| yalst | yay -Qe | List installed packages including from AUR (tagged as "local") |
|
||||
| yamir | yay -Syy | Force refresh of all package lists after updating mirrorlist |
|
||||
| yaorph | yay -Qtd | Remove orphans using yay |
|
||||
| yare | yay -R | Remove packages, keeping its settings and dependencies |
|
||||
| yarem | yay -Rns | Remove packages, including its settings and unneeded dependencies |
|
||||
| yarep | yay -Si | Display information about a package in the repositories |
|
||||
| yareps | yay -Ss | Search for packages in the repositories |
|
||||
| yaupg | yay -Syu | Sync with repositories before upgrading packages |
|
||||
| yasu | yay -Syu --no-confirm | Same as `yaupg`, but without confirmation |
|
||||
| Alias | Command | Description |
|
||||
|--------------|----------------------------------------|------------------------------------------------------------------|
|
||||
| pacin | `sudo pacman -S` | Install packages from the repositories |
|
||||
| pacins | `sudo pacman -U` | Install a package from a local file |
|
||||
| pacinsd | `sudo pacman -S --asdeps` | Install packages as dependencies of another package |
|
||||
| paclean | `sudo pacman -Sc` | Clean out old and unused caches and packages |
|
||||
| pacloc | `pacman -Qi` | Display information about a package in the local database |
|
||||
| paclocs | `pacman -Qs` | Search for packages in the local database |
|
||||
| paclr | `sudo pacman -Scc` | Remove all files from the cache |
|
||||
| paclsorphans | `sudo pacman -Qdt` | List all orphaned packages |
|
||||
| pacmir | `sudo pacman -Syy` | Force refresh of all package lists after updating mirrorlist |
|
||||
| pacre | `sudo pacman -R` | Remove packages, keeping its settings and dependencies |
|
||||
| pacrem | `sudo pacman -Rns` | Remove packages, including its settings and dependencies |
|
||||
| pacrep | `pacman -Si` | Display information about a package in the repositories |
|
||||
| pacreps | `pacman -Ss` | Search for packages in the repositories |
|
||||
| pacrmorphans | `sudo pacman -Rs $(pacman -Qtdq)` | Delete all orphaned packages |
|
||||
| pacupd | `sudo pacman -Sy` | Update and refresh local package, ABS and AUR databases |
|
||||
| pacupg | `sudo pacman -Syu` | Sync with repositories before upgrading packages |
|
||||
| pacfileupg | `sudo pacman -Fy` | Download fresh package databases from the server |
|
||||
| pacfiles | `pacman -F` | Search package file names for matching strings |
|
||||
| pacls | `pacman -Ql` | List files in a package |
|
||||
| pacown | `pacman -Qo` | Show which package owns a file |
|
||||
| upgrade[¹](#f1) | `sudo pacman -Syu` | Sync with repositories before upgrading packages |
|
||||
|
||||
#### TRIZEN
|
||||
| Function | Description |
|
||||
|----------------|-----------------------------------------------------------|
|
||||
| pacdisowned | List all disowned files in your system |
|
||||
| paclist | List all explicitly installed packages with a description |
|
||||
| pacmanallkeys | Get all keys for developers and trusted users |
|
||||
| pacmansignkeys | Locally trust all keys passed as parameters |
|
||||
| pacweb | Open the website of an ArchLinux package |
|
||||
|
||||
| Alias | Command | Description |
|
||||
|---------|------------------------------------|---------------------------------------------------------------------|
|
||||
| trconf | trizen -C | Fix all configuration files with vimdiff |
|
||||
| trin | trizen -S | Install packages from the repositories |
|
||||
| trins | trizen -U | Install a package from a local file |
|
||||
| trinsd | trizen -S --asdeps | Install packages as dependencies of another package |
|
||||
| trloc | trizen -Qi | Display information about a package in the local database |
|
||||
| trlocs | trizen -Qs | Search for packages in the local database |
|
||||
| trlst | trizen -Qe | List installed packages including from AUR (tagged as "local") |
|
||||
| trmir | trizen -Syy | Force refresh of all package lists after updating mirrorlist |
|
||||
| trorph | trizen -Qtd | Remove orphans using yaourt |
|
||||
| trre | trizen -R | Remove packages, keeping its settings and dependencies |
|
||||
| trrem | trizen -Rns | Remove packages, including its settings and unneeded dependencies |
|
||||
| trrep | trizen -Si | Display information about a package in the repositories |
|
||||
| trreps | trizen -Ss | Search for packages in the repositories |
|
||||
| trupd | trizen -Sy && sudo abs && sudo aur | Update and refresh local package, ABS and AUR databases |
|
||||
| trupd | trizen -Sy && sudo abs | Update and refresh the local package and ABS databases |
|
||||
| trupd | trizen -Sy && sudo aur | Update and refresh the local package and AUR databases |
|
||||
| trupd | trizen -Sy | Update and refresh the local package database |
|
||||
| trupg | trizen -Syua | Sync with repositories before upgrading all packages (from AUR too) |
|
||||
| trsu | trizen -Syua --no-confirm | Same as `trupg`, but without confirmation |
|
||||
| upgrade | trizen -Syu | Sync with repositories before upgrading packages |
|
||||
Note: paclist used to print packages with a description which are (1) explicitly installed
|
||||
and (2) available for upgrade. Due to flawed scripting, it also printed all packages if no
|
||||
upgrades were available. Use `pacman -Que` instead.
|
||||
|
||||
#### YAOURT
|
||||
### AUR helpers
|
||||
|
||||
| Alias | Command | Description |
|
||||
|---------|------------------------------------|---------------------------------------------------------------------|
|
||||
| yaconf | yaourt -C | Fix all configuration files with vimdiff |
|
||||
| yain | yaourt -S | Install packages from the repositories |
|
||||
| yains | yaourt -U | Install a package from a local file |
|
||||
| yainsd | yaourt -S --asdeps | Install packages as dependencies of another package |
|
||||
| yaloc | yaourt -Qi | Display information about a package in the local database |
|
||||
| yalocs | yaourt -Qs | Search for packages in the local database |
|
||||
| yalst | yaourt -Qe | List installed packages including from AUR (tagged as "local") |
|
||||
| yamir | yaourt -Syy | Force refresh of all package lists after updating mirrorlist |
|
||||
| yaorph | yaourt -Qtd | Remove orphans using yaourt |
|
||||
| yare | yaourt -R | Remove packages, keeping its settings and dependencies |
|
||||
| yarem | yaourt -Rns | Remove packages, including its settings and unneeded dependencies |
|
||||
| yarep | yaourt -Si | Display information about a package in the repositories |
|
||||
| yareps | yaourt -Ss | Search for packages in the repositories |
|
||||
| yaupd | yaourt -Sy && sudo abs && sudo aur | Update and refresh local package, ABS and AUR databases |
|
||||
| yaupd | yaourt -Sy && sudo abs | Update and refresh the local package and ABS databases |
|
||||
| yaupd | yaourt -Sy && sudo aur | Update and refresh the local package and AUR databases |
|
||||
| yaupd | yaourt -Sy | Update and refresh the local package database |
|
||||
| yaupg | yaourt -Syua | Sync with repositories before upgrading all packages (from AUR too) |
|
||||
| yasu | yaourt -Syua --no-confirm | Same as `yaupg`, but without confirmation |
|
||||
| upgrade | yaourt -Syu | Sync with repositories before upgrading packages |
|
||||
#### Aura
|
||||
|
||||
#### PACAUR
|
||||
| Alias | Command | Description |
|
||||
|---------|-------------------------------------------------|-------------------------------------------------------------------------|
|
||||
| auclean | `sudo aura -Sc` | Clean out old and unused caches and packages |
|
||||
| auclr | `sudo aura -Scc` | Remove all files from the cache |
|
||||
| auin | `sudo aura -S` | Install packages from the repositories |
|
||||
| aurin | `sudo aura -A` | Install packages from the repositories |
|
||||
| auins | `sudo aura -U` | Install a package from a local file |
|
||||
| auinsd | `sudo aura -S --asdeps` | Install packages as dependencies of another package (repositories only) |
|
||||
| aurinsd | `sudo aura -A --asdeps` | Install packages as dependencies of another package (AUR only) |
|
||||
| auloc | `aura -Qi` | Display information about a package in the local database |
|
||||
| aulocs | `aura -Qs` | Search for packages in the local database |
|
||||
| auls | `aura -Qql` | List all files owned by a given package |
|
||||
| aulst | `aura -Qe` | List installed packages including from AUR (tagged as "local") |
|
||||
| aumir | `sudo aura -Syy` | Force refresh of all package lists after updating mirrorlist |
|
||||
| aurph | `sudo aura -Oj` | Remove orphans using aura |
|
||||
| auown | `aura -Qqo` | Search for packages that own the specified file(s) |
|
||||
| aure | `sudo aura -R` | Remove packages, keeping its settings and dependencies |
|
||||
| aurem | `sudo aura -Rns` | Remove packages, including its settings and unneeded dependencies |
|
||||
| aurep | `aura -Si` | Display information about a package in the repositories |
|
||||
| aurrep | `aura -Ai` | Display information about a package from AUR |
|
||||
| aureps | `aura -As --both` | Search for packages in the repositories and AUR |
|
||||
| auras | `aura -As --both` | Same as above |
|
||||
| auupd | `sudo aura -Sy` | Update and refresh local package, ABS and AUR databases |
|
||||
| auupg | `sudo sh -c "aura -Syu && aura -Au"` | Sync with repositories before upgrading all packages (from AUR too) |
|
||||
| ausu | `sudo sh -c "aura -Syu --no-confirm && aura -Au --no-confirm"` | Same as `auupg`, but without confirmation |
|
||||
| upgrade[¹](#f1) | `sudo aura -Syu` | Sync with repositories before upgrading packages |
|
||||
|
||||
| Alias | Command | Description |
|
||||
|---------|------------------------------------|---------------------------------------------------------------------|
|
||||
| pain | pacaur -S | Install packages from the repositories |
|
||||
| pains | pacaur -U | Install a package from a local file |
|
||||
| painsd | pacaur -S --asdeps | Install packages as dependencies of another package |
|
||||
| paloc | pacaur -Qi | Display information about a package in the local database |
|
||||
| palocs | pacaur -Qs | Search for packages in the local database |
|
||||
| palst | pacaur -Qe | List installed packages including from AUR (tagged as "local") |
|
||||
| pamir | pacaur -Syy | Force refresh of all package lists after updating mirrorlist |
|
||||
| paorph | pacaur -Qtd | Remove orphans using pacaur |
|
||||
| pare | pacaur -R | Remove packages, keeping its settings and dependencies |
|
||||
| parem | pacaur -Rns | Remove packages, including its settings and unneeded dependencies |
|
||||
| parep | pacaur -Si | Display information about a package in the repositories |
|
||||
| pareps | pacaur -Ss | Search for packages in the repositories |
|
||||
| paupd | pacaur -Sy && sudo abs && sudo aur | Update and refresh local package, ABS and AUR databases |
|
||||
| paupd | pacaur -Sy && sudo abs | Update and refresh the local package and ABS databases |
|
||||
| paupd | pacaur -Sy && sudo aur | Update and refresh the local package and AUR databases |
|
||||
| paupd | pacaur -Sy | Update and refresh the local package database |
|
||||
| paupg | pacaur -Syua | Sync with repositories before upgrading all packages (from AUR too) |
|
||||
| pasu | pacaur -Syua --no-confirm | Same as `paupg`, but without confirmation |
|
||||
| upgrade | pacaur -Syu | Sync with repositories before upgrading packages |
|
||||
| Function | Description |
|
||||
|-----------------|---------------------------------------------------------------------|
|
||||
| auownloc _file_ | Display information about a package that owns the specified file(s) |
|
||||
| auownls _file_ | List all files owned by a package that owns the specified file(s) |
|
||||
|
||||
#### PACMAN
|
||||
#### Pacaur
|
||||
|
||||
| Alias | Command | Description |
|
||||
|--------------|-----------------------------------------|--------------------------------------------------------------|
|
||||
| pacin | sudo pacman -S | Install packages from the repositories |
|
||||
| pacins | sudo pacman -U | Install a package from a local file |
|
||||
| pacinsd | sudo pacman -S --asdeps | Install packages as dependencies of another package |
|
||||
| pacloc | pacman -Qi | Display information about a package in the local database |
|
||||
| paclocs | pacman -Qs | Search for packages in the local database |
|
||||
| paclsorphans | sudo pacman -Qdt | List all orphaned packages |
|
||||
| pacmir | sudo pacman -Syy | Force refresh of all package lists after updating mirrorlist |
|
||||
| pacre | sudo pacman -R | Remove packages, keeping its settings and dependencies |
|
||||
| pacrem | sudo pacman -Rns | Remove packages, including its settings and dependencies |
|
||||
| pacrep | pacman -Si | Display information about a package in the repositories |
|
||||
| pacreps | pacman -Ss | Search for packages in the repositories |
|
||||
| pacrmorphans | sudo pacman -Rs $(pacman -Qtdq) | Delete all orphaned packages |
|
||||
| pacupd | sudo pacman -Sy && sudo abs && sudo aur | Update and refresh the local package, ABS and AUR databases |
|
||||
| pacupd | sudo pacman -Sy && sudo abs | Update and refresh the local package and ABS databases |
|
||||
| pacupd | sudo pacman -Sy && sudo aur | Update and refresh the local package and AUR databases |
|
||||
| pacupd | sudo pacman -Sy | Update and refresh the local package database |
|
||||
| pacupg | sudo pacman -Syu | Sync with repositories before upgrading packages |
|
||||
| upgrade | sudo pacman -Syu | Sync with repositories before upgrading packages |
|
||||
| pacfileupg | sudo pacman -Fy | Download fresh package databases from the server |
|
||||
| pacfiles | pacman -F | Search package file names for matching strings |
|
||||
| pacls | pacman -Ql | List files in a package |
|
||||
| pacown | pacman -Qo | Show which package owns a file |
|
||||
| Alias | Command | Description |
|
||||
|---------|-----------------------------------|---------------------------------------------------------------------|
|
||||
| pacclean| `pacaur -Sc` | Clean out old and unused caches and packages |
|
||||
| pacclr | `pacaur -Scc` | Remove all files from the cache |
|
||||
| pain | `pacaur -S` | Install packages from the repositories |
|
||||
| pains | `pacaur -U` | Install a package from a local file |
|
||||
| painsd | `pacaur -S --asdeps` | Install packages as dependencies of another package |
|
||||
| paloc | `pacaur -Qi` | Display information about a package in the local database |
|
||||
| palocs | `pacaur -Qs` | Search for packages in the local database |
|
||||
| palst | `pacaur -Qe` | List installed packages including from AUR (tagged as "local") |
|
||||
| pamir | `pacaur -Syy` | Force refresh of all package lists after updating mirrorlist |
|
||||
| paorph | `pacaur -Qtd` | Remove orphans using pacaur |
|
||||
| pare | `pacaur -R` | Remove packages, keeping its settings and dependencies |
|
||||
| parem | `pacaur -Rns` | Remove packages, including its settings and unneeded dependencies |
|
||||
| parep | `pacaur -Si` | Display information about a package in the repositories |
|
||||
| pareps | `pacaur -Ss` | Search for packages in the repositories |
|
||||
| paupd | `pacaur -Sy` | Update and refresh local package, ABS and AUR databases |
|
||||
| paupg | `pacaur -Syua` | Sync with repositories before upgrading all packages (from AUR too) |
|
||||
| pasu | `pacaur -Syua --no-confirm` | Same as `paupg`, but without confirmation |
|
||||
| upgrade[¹](#f1) | `pacaur -Syu` | Sync with repositories before upgrading packages |
|
||||
|
||||
| Function | Description |
|
||||
|----------------|------------------------------------------------------|
|
||||
| pacdisowned | List all disowned files in your system |
|
||||
| paclist | List all installed packages with a short description |
|
||||
| pacmanallkeys | Get all keys for developers and trusted users |
|
||||
| pacmansignkeys | Locally trust all keys passed as parameters |
|
||||
| pacweb | Open the website of an ArchLinux package |
|
||||
#### Trizen
|
||||
|
||||
| Alias | Command | Description |
|
||||
|---------|-----------------------------------|---------------------------------------------------------------------|
|
||||
| trconf | `trizen -C` | Fix all configuration files with vimdiff |
|
||||
| trclean | `trizen -Sc` | Clean out old and unused caches and packages |
|
||||
| trclr | `trizen -Scc` | Remove all files from the cache |
|
||||
| trin | `trizen -S` | Install packages from the repositories |
|
||||
| trins | `trizen -U` | Install a package from a local file |
|
||||
| trinsd | `trizen -S --asdeps` | Install packages as dependencies of another package |
|
||||
| trloc | `trizen -Qi` | Display information about a package in the local database |
|
||||
| trlocs | `trizen -Qs` | Search for packages in the local database |
|
||||
| trlst | `trizen -Qe` | List installed packages including from AUR (tagged as "local") |
|
||||
| trmir | `trizen -Syy` | Force refresh of all package lists after updating mirrorlist |
|
||||
| trorph | `trizen -Qtd` | Remove orphans using yaourt |
|
||||
| trre | `trizen -R` | Remove packages, keeping its settings and dependencies |
|
||||
| trrem | `trizen -Rns` | Remove packages, including its settings and unneeded dependencies |
|
||||
| trrep | `trizen -Si` | Display information about a package in the repositories |
|
||||
| trreps | `trizen -Ss` | Search for packages in the repositories |
|
||||
| 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) |
|
||||
| trsu | `trizen -Syua --no-confirm` | Same as `trupg`, but without confirmation |
|
||||
| upgrade[¹](#f1) | `trizen -Syu` | Sync with repositories before upgrading packages |
|
||||
|
||||
#### Yay
|
||||
|
||||
| Alias | Command | Description |
|
||||
|---------|--------------------------------|-------------------------------------------------------------------|
|
||||
| yaconf | `yay -Pg` | Print current configuration |
|
||||
| yaclean | `yay -Sc` | Clean out old and unused caches and packages |
|
||||
| yaclr | `yay -Scc` | Remove all files from the cache |
|
||||
| yain | `yay -S` | Install packages from the repositories |
|
||||
| yains | `yay -U` | Install a package from a local file |
|
||||
| yainsd | `yay -S --asdeps` | Install packages as dependencies of another package |
|
||||
| yaloc | `yay -Qi` | Display information about a package in the local database |
|
||||
| yalocs | `yay -Qs` | Search for packages in the local database |
|
||||
| yalst | `yay -Qe` | List installed packages including from AUR (tagged as "local") |
|
||||
| yamir | `yay -Syy` | Force refresh of all package lists after updating mirrorlist |
|
||||
| yaorph | `yay -Qtd` | Remove orphans using yay |
|
||||
| yare | `yay -R` | Remove packages, keeping its settings and dependencies |
|
||||
| yarem | `yay -Rns` | Remove packages, including its settings and unneeded dependencies |
|
||||
| yarep | `yay -Si` | Display information about a package in the repositories |
|
||||
| yareps | `yay -Ss` | Search for packages in the repositories |
|
||||
| yaupd | `yay -Sy` | Update and refresh local package, ABS and AUR databases |
|
||||
| yaupg | `yay -Syu` | Sync with repositories before upgrading packages |
|
||||
| yasu | `yay -Syu --no-confirm` | Same as `yaupg`, but without confirmation |
|
||||
| upgrade[¹](#f1) | `yay -Syu` | Sync with repositories before upgrading packages |
|
||||
|
||||
---
|
||||
|
||||
<span id="f1">¹</span>
|
||||
The `upgrade` alias is set for all package managers. Its value will depend on
|
||||
whether the package manager is installed, checked in the following order:
|
||||
|
||||
1. `yay`
|
||||
2. `trizen`
|
||||
3. `pacaur`
|
||||
4. `aura`
|
||||
5. `pacman`
|
||||
|
||||
## Contributors
|
||||
|
||||
- Benjamin Boudreau - dreurmail@gmail.com
|
||||
- Celso Miranda - contacto@celsomiranda.net
|
||||
- ratijas (ivan tkachenko) - me@ratijas.tk
|
||||
- Juraj Fiala - doctorjellyface@riseup.net
|
||||
- KhasMek - Boushh@gmail.com
|
||||
- Majora320 (Moses Miller) - Majora320@gmail.com
|
||||
- Martin Putniorz - mputniorz@gmail.com
|
||||
- MatthR3D - matthr3d@gmail.com
|
||||
- ornicar - thibault.duplessis@gmail.com
|
||||
- Juraj Fiala - doctorjellyface@riseup.net
|
||||
- Majora320 (Moses Miller) - Majora320@gmail.com
|
||||
- Ybalrid (Arthur Brainville) - ybalrid@ybalrid.info
|
||||
- Jeff M. Hubbard - jeffmhubbard@gmail.com
|
||||
- K. Harishankar(harishnkr) - hari2menon1234@gmail.com
|
||||
- WH-2099 - wh2099@outlook.com
|
||||
|
|
@ -1,143 +1,13 @@
|
|||
if (( $+commands[trizen] )); then
|
||||
alias trconf='trizen -C'
|
||||
alias trupg='trizen -Syua'
|
||||
alias trsu='trizen -Syua --noconfirm'
|
||||
alias trin='trizen -S'
|
||||
alias trins='trizen -U'
|
||||
alias trre='trizen -R'
|
||||
alias trrem='trizen -Rns'
|
||||
alias trrep='trizen -Si'
|
||||
alias trreps='trizen -Ss'
|
||||
alias trloc='trizen -Qi'
|
||||
alias trlocs='trizen -Qs'
|
||||
alias trlst='trizen -Qe'
|
||||
alias trorph='trizen -Qtd'
|
||||
alias trinsd='trizen -S --asdeps'
|
||||
alias trmir='trizen -Syy'
|
||||
|
||||
|
||||
if (( $+commands[abs] && $+commands[aur] )); then
|
||||
alias trupd='trizen -Sy && sudo abs && sudo aur'
|
||||
elif (( $+commands[abs] )); then
|
||||
alias trupd='trizen -Sy && sudo abs'
|
||||
elif (( $+commands[aur] )); then
|
||||
alias trupd='trizen -Sy && sudo aur'
|
||||
else
|
||||
alias trupd='trizen -Sy'
|
||||
fi
|
||||
fi
|
||||
|
||||
if (( $+commands[yaourt] )); then
|
||||
alias yaconf='yaourt -C'
|
||||
alias yaupg='yaourt -Syua'
|
||||
alias yasu='yaourt -Syua --noconfirm'
|
||||
alias yain='yaourt -S'
|
||||
alias yains='yaourt -U'
|
||||
alias yare='yaourt -R'
|
||||
alias yarem='yaourt -Rns'
|
||||
alias yarep='yaourt -Si'
|
||||
alias yareps='yaourt -Ss'
|
||||
alias yaloc='yaourt -Qi'
|
||||
alias yalocs='yaourt -Qs'
|
||||
alias yalst='yaourt -Qe'
|
||||
alias yaorph='yaourt -Qtd'
|
||||
alias yainsd='yaourt -S --asdeps'
|
||||
alias yamir='yaourt -Syy'
|
||||
|
||||
|
||||
if (( $+commands[abs] && $+commands[aur] )); then
|
||||
alias yaupd='yaourt -Sy && sudo abs && sudo aur'
|
||||
elif (( $+commands[abs] )); then
|
||||
alias yaupd='yaourt -Sy && sudo abs'
|
||||
elif (( $+commands[aur] )); then
|
||||
alias yaupd='yaourt -Sy && sudo aur'
|
||||
else
|
||||
alias yaupd='yaourt -Sy'
|
||||
fi
|
||||
fi
|
||||
|
||||
if (( $+commands[yay] )); then
|
||||
alias yaconf='yay -Pg'
|
||||
alias yaupg='yay -Syu'
|
||||
alias yasu='yay -Syu --noconfirm'
|
||||
alias yain='yay -S'
|
||||
alias yains='yay -U'
|
||||
alias yare='yay -R'
|
||||
alias yarem='yay -Rns'
|
||||
alias yarep='yay -Si'
|
||||
alias yareps='yay -Ss'
|
||||
alias yaloc='yay -Qi'
|
||||
alias yalocs='yay -Qs'
|
||||
alias yalst='yay -Qe'
|
||||
alias yaorph='yay -Qtd'
|
||||
alias yainsd='yay -S --asdeps'
|
||||
alias yamir='yay -Syy'
|
||||
|
||||
|
||||
if (( $+commands[abs] && $+commands[aur] )); then
|
||||
alias yaupd='yay -Sy && sudo abs && sudo aur'
|
||||
elif (( $+commands[abs] )); then
|
||||
alias yaupd='yay -Sy && sudo abs'
|
||||
elif (( $+commands[aur] )); then
|
||||
alias yaupd='yay -Sy && sudo aur'
|
||||
else
|
||||
alias yaupd='yay -Sy'
|
||||
fi
|
||||
fi
|
||||
|
||||
if (( $+commands[pacaur] )); then
|
||||
alias paupg='pacaur -Syu'
|
||||
alias pasu='pacaur -Syu --noconfirm'
|
||||
alias pain='pacaur -S'
|
||||
alias pains='pacaur -U'
|
||||
alias pare='pacaur -R'
|
||||
alias parem='pacaur -Rns'
|
||||
alias parep='pacaur -Si'
|
||||
alias pareps='pacaur -Ss'
|
||||
alias paloc='pacaur -Qi'
|
||||
alias palocs='pacaur -Qs'
|
||||
alias palst='pacaur -Qe'
|
||||
alias paorph='pacaur -Qtd'
|
||||
alias painsd='pacaur -S --asdeps'
|
||||
alias pamir='pacaur -Syy'
|
||||
|
||||
if (( $+commands[abs] && $+commands[aur] )); then
|
||||
alias paupd='pacaur -Sy && sudo abs && sudo aur'
|
||||
elif (( $+commands[abs] )); then
|
||||
alias paupd='pacaur -Sy && sudo abs'
|
||||
elif (( $+commands[aur] )); then
|
||||
alias paupd='pacaur -Sy && sudo aur'
|
||||
else
|
||||
alias paupd='pacaur -Sy'
|
||||
fi
|
||||
fi
|
||||
|
||||
if (( $+commands[trizen] )); then
|
||||
function upgrade() {
|
||||
trizen -Syu
|
||||
}
|
||||
elif (( $+commands[pacaur] )); then
|
||||
function upgrade() {
|
||||
pacaur -Syu
|
||||
}
|
||||
elif (( $+commands[yaourt] )); then
|
||||
function upgrade() {
|
||||
yaourt -Syu
|
||||
}
|
||||
elif (( $+commands[yay] )); then
|
||||
function upgrade() {
|
||||
yay -Syu
|
||||
}
|
||||
else
|
||||
function upgrade() {
|
||||
sudo pacman -Syu
|
||||
}
|
||||
fi
|
||||
#######################################
|
||||
# Pacman #
|
||||
#######################################
|
||||
|
||||
# Pacman - https://wiki.archlinux.org/index.php/Pacman_Tips
|
||||
alias pacupg='sudo pacman -Syu'
|
||||
alias pacin='sudo pacman -S'
|
||||
alias paclean='sudo pacman -Sc'
|
||||
alias pacins='sudo pacman -U'
|
||||
alias paclr='sudo pacman -Scc'
|
||||
alias pacre='sudo pacman -R'
|
||||
alias pacrem='sudo pacman -Rns'
|
||||
alias pacrep='pacman -Si'
|
||||
|
|
@ -152,52 +22,35 @@ alias pacfileupg='sudo pacman -Fy'
|
|||
alias pacfiles='pacman -F'
|
||||
alias pacls='pacman -Ql'
|
||||
alias pacown='pacman -Qo'
|
||||
|
||||
|
||||
if (( $+commands[abs] && $+commands[aur] )); then
|
||||
alias pacupd='sudo pacman -Sy && sudo abs && sudo aur'
|
||||
elif (( $+commands[abs] )); then
|
||||
alias pacupd='sudo pacman -Sy && sudo abs'
|
||||
elif (( $+commands[aur] )); then
|
||||
alias pacupd='sudo pacman -Sy && sudo aur'
|
||||
else
|
||||
alias pacupd='sudo pacman -Sy'
|
||||
fi
|
||||
alias pacupd="sudo pacman -Sy"
|
||||
|
||||
function paclist() {
|
||||
# Source: https://bbs.archlinux.org/viewtopic.php?id=93683
|
||||
LC_ALL=C pacman -Qei $(pacman -Qu | cut -d " " -f 1) | \
|
||||
awk 'BEGIN {FS=":"} /^Name/{printf("\033[1;36m%s\033[1;37m", $2)} /^Description/{print $2}'
|
||||
pacman -Qqe | xargs -I{} -P0 --no-run-if-empty pacman -Qs --color=auto "^{}\$"
|
||||
}
|
||||
|
||||
function pacdisowned() {
|
||||
emulate -L zsh
|
||||
local tmp_dir db fs
|
||||
tmp_dir=$(mktemp --directory)
|
||||
db=$tmp_dir/db
|
||||
fs=$tmp_dir/fs
|
||||
|
||||
tmp=${TMPDIR-/tmp}/pacman-disowned-$UID-$$
|
||||
db=$tmp/db
|
||||
fs=$tmp/fs
|
||||
|
||||
mkdir "$tmp"
|
||||
trap 'rm -rf "$tmp"' EXIT
|
||||
trap "rm -rf $tmp_dir" EXIT
|
||||
|
||||
pacman -Qlq | sort -u > "$db"
|
||||
|
||||
find /bin /etc /lib /sbin /usr ! -name lost+found \
|
||||
find /etc /usr ! -name lost+found \
|
||||
\( -type d -printf '%p/\n' -o -print \) | sort > "$fs"
|
||||
|
||||
comm -23 "$fs" "$db"
|
||||
|
||||
rm -rf $tmp_dir
|
||||
}
|
||||
|
||||
function pacmanallkeys() {
|
||||
emulate -L zsh
|
||||
curl -s https://www.archlinux.org/people/{developers,trustedusers}/ | \
|
||||
awk -F\" '(/pgp.mit.edu/) { sub(/.*search=0x/,""); print $1}' | \
|
||||
xargs sudo pacman-key --recv-keys
|
||||
}
|
||||
alias pacmanallkeys='sudo pacman-key --refresh-keys'
|
||||
|
||||
function pacmansignkeys() {
|
||||
emulate -L zsh
|
||||
for key in $*; do
|
||||
local key
|
||||
for key in $@; do
|
||||
sudo pacman-key --recv-keys $key
|
||||
sudo pacman-key --lsign-key $key
|
||||
printf 'trust\n3\n' | sudo gpg --homedir /etc/pacman.d/gnupg \
|
||||
|
|
@ -207,13 +60,144 @@ function pacmansignkeys() {
|
|||
|
||||
if (( $+commands[xdg-open] )); then
|
||||
function pacweb() {
|
||||
pkg="$1"
|
||||
infos="$(LANG=C pacman -Si "$pkg")"
|
||||
if [[ $# = 0 || "$1" =~ '--help|-h' ]]; then
|
||||
local underline_color="\e[${color[underline]}m"
|
||||
echo "$0 - open the website of an ArchLinux package"
|
||||
echo
|
||||
echo "Usage:"
|
||||
echo " $bold_color$0$reset_color ${underline_color}target${reset_color}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local pkg="$1"
|
||||
local infos="$(LANG=C pacman -Si "$pkg")"
|
||||
if [[ -z "$infos" ]]; then
|
||||
return
|
||||
fi
|
||||
repo="$(grep -m 1 '^Repo' <<< "$infos" | grep -oP '[^ ]+$')"
|
||||
arch="$(grep -m 1 '^Arch' <<< "$infos" | grep -oP '[^ ]+$')"
|
||||
local repo="$(grep -m 1 '^Repo' <<< "$infos" | grep -oP '[^ ]+$')"
|
||||
local arch="$(grep -m 1 '^Arch' <<< "$infos" | grep -oP '[^ ]+$')"
|
||||
xdg-open "https://www.archlinux.org/packages/$repo/$arch/$pkg/" &>/dev/null
|
||||
}
|
||||
fi
|
||||
|
||||
#######################################
|
||||
# AUR helpers #
|
||||
#######################################
|
||||
|
||||
if (( $+commands[aura] )); then
|
||||
alias auin='sudo aura -S'
|
||||
alias aurin='sudo aura -A'
|
||||
alias auclean='sudo aura -Sc'
|
||||
alias auclr='sudo aura -Scc'
|
||||
alias auins='sudo aura -U'
|
||||
alias auinsd='sudo aura -S --asdeps'
|
||||
alias aurinsd='sudo aura -A --asdeps'
|
||||
alias auloc='aura -Qi'
|
||||
alias aulocs='aura -Qs'
|
||||
alias aulst='aura -Qe'
|
||||
alias aumir='sudo aura -Syy'
|
||||
alias aurph='sudo aura -Oj'
|
||||
alias aure='sudo aura -R'
|
||||
alias aurem='sudo aura -Rns'
|
||||
alias aurep='aura -Si'
|
||||
alias aurrep='aura -Ai'
|
||||
alias aureps='aura -As --both'
|
||||
alias auras='aura -As --both'
|
||||
alias auupd="sudo aura -Sy"
|
||||
alias auupg='sudo sh -c "aura -Syu && aura -Au"'
|
||||
alias ausu='sudo sh -c "aura -Syu --no-confirm && aura -Au --no-confirm"'
|
||||
|
||||
# extra bonus specially for aura
|
||||
alias auown="aura -Qqo"
|
||||
alias auls="aura -Qql"
|
||||
function auownloc() { aura -Qi $(aura -Qqo $@); }
|
||||
function auownls () { aura -Qql $(aura -Qqo $@); }
|
||||
fi
|
||||
|
||||
if (( $+commands[pacaur] )); then
|
||||
alias pacclean='pacaur -Sc'
|
||||
alias pacclr='pacaur -Scc'
|
||||
alias paupg='pacaur -Syu'
|
||||
alias pasu='pacaur -Syu --noconfirm'
|
||||
alias pain='pacaur -S'
|
||||
alias pains='pacaur -U'
|
||||
alias pare='pacaur -R'
|
||||
alias parem='pacaur -Rns'
|
||||
alias parep='pacaur -Si'
|
||||
alias pareps='pacaur -Ss'
|
||||
alias paloc='pacaur -Qi'
|
||||
alias palocs='pacaur -Qs'
|
||||
alias palst='pacaur -Qe'
|
||||
alias paorph='pacaur -Qtd'
|
||||
alias painsd='pacaur -S --asdeps'
|
||||
alias pamir='pacaur -Syy'
|
||||
alias paupd="pacaur -Sy"
|
||||
fi
|
||||
|
||||
if (( $+commands[trizen] )); then
|
||||
alias trconf='trizen -C'
|
||||
alias trupg='trizen -Syua'
|
||||
alias trsu='trizen -Syua --noconfirm'
|
||||
alias trin='trizen -S'
|
||||
alias trclean='trizen -Sc'
|
||||
alias trclr='trizen -Scc'
|
||||
alias trins='trizen -U'
|
||||
alias trre='trizen -R'
|
||||
alias trrem='trizen -Rns'
|
||||
alias trrep='trizen -Si'
|
||||
alias trreps='trizen -Ss'
|
||||
alias trloc='trizen -Qi'
|
||||
alias trlocs='trizen -Qs'
|
||||
alias trlst='trizen -Qe'
|
||||
alias trorph='trizen -Qtd'
|
||||
alias trinsd='trizen -S --asdeps'
|
||||
alias trmir='trizen -Syy'
|
||||
alias trupd="trizen -Sy"
|
||||
fi
|
||||
|
||||
if (( $+commands[yay] )); then
|
||||
alias yaconf='yay -Pg'
|
||||
alias yaclean='yay -Sc'
|
||||
alias yaclr='yay -Scc'
|
||||
alias yaupg='yay -Syu'
|
||||
alias yasu='yay -Syu --noconfirm'
|
||||
alias yain='yay -S'
|
||||
alias yains='yay -U'
|
||||
alias yare='yay -R'
|
||||
alias yarem='yay -Rns'
|
||||
alias yarep='yay -Si'
|
||||
alias yareps='yay -Ss'
|
||||
alias yaloc='yay -Qi'
|
||||
alias yalocs='yay -Qs'
|
||||
alias yalst='yay -Qe'
|
||||
alias yaorph='yay -Qtd'
|
||||
alias yainsd='yay -S --asdeps'
|
||||
alias yamir='yay -Syy'
|
||||
alias yaupd="yay -Sy"
|
||||
fi
|
||||
|
||||
# Check Arch Linux PGP Keyring before System Upgrade to prevent failure.
|
||||
function upgrade() {
|
||||
echo ":: Checking Arch Linux PGP Keyring..."
|
||||
local installedver="$(LANG= sudo pacman -Qi archlinux-keyring | grep -Po '(?<=Version : ).*')"
|
||||
local currentver="$(LANG= sudo pacman -Si archlinux-keyring | grep -Po '(?<=Version : ).*')"
|
||||
if [ $installedver != $currentver ]; then
|
||||
echo " Arch Linux PGP Keyring is out of date."
|
||||
echo " Updating before full system upgrade."
|
||||
sudo pacman -Sy --needed --noconfirm archlinux-keyring
|
||||
else
|
||||
echo " Arch Linux PGP Keyring is up to date."
|
||||
echo " Proceeding with full system upgrade."
|
||||
fi
|
||||
if (( $+commands[yay] )); then
|
||||
yay -Syu
|
||||
elif (( $+commands[trizen] )); then
|
||||
trizen -Syu
|
||||
elif (( $+commands[pacaur] )); then
|
||||
pacaur -Syu
|
||||
elif (( $+commands[aura] )); then
|
||||
sudo aura -Syu
|
||||
else
|
||||
sudo pacman -Syu
|
||||
fi
|
||||
}
|
||||
|
|
|
|||
20
plugins/argocd/README.md
Normal file
20
plugins/argocd/README.md
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# Argo CD plugin
|
||||
|
||||
This plugin adds completion for the [Argo CD](https://argoproj.github.io/cd/) CLI.
|
||||
|
||||
To use it, add `argocd` to the plugins array in your zshrc file:
|
||||
|
||||
```zsh
|
||||
plugins=(... argocd)
|
||||
```
|
||||
|
||||
This plugin does not add any aliases.
|
||||
|
||||
## Cache
|
||||
|
||||
This plugin caches the completion script and is automatically updated asynchronously when the plugin is
|
||||
loaded, which is usually when you start up a new terminal emulator.
|
||||
|
||||
The cache is stored at:
|
||||
|
||||
- `$ZSH_CACHE/completions/_argocd` completions script
|
||||
14
plugins/argocd/argocd.plugin.zsh
Normal file
14
plugins/argocd/argocd.plugin.zsh
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# Autocompletion for argocd.
|
||||
if (( ! $+commands[argocd] )); then
|
||||
return
|
||||
fi
|
||||
|
||||
# If the completion file doesn't exist yet, we need to autoload it and
|
||||
# bind it to `argocd`. Otherwise, compinit will have already done that.
|
||||
if [[ ! -f "$ZSH_CACHE_DIR/completions/_argocd" ]]; then
|
||||
typeset -g -A _comps
|
||||
autoload -Uz _argocd
|
||||
_comps[argocd]=_argocd
|
||||
fi
|
||||
|
||||
argocd completion zsh >| "$ZSH_CACHE_DIR/completions/_argocd" &|
|
||||
|
|
@ -6,22 +6,25 @@ Adds integration with [asdf](https://github.com/asdf-vm/asdf), the extendable ve
|
|||
|
||||
### Installation
|
||||
|
||||
1. Enable the plugin by adding it to your `plugins` definition in `~/.zshrc`.
|
||||
1. [Download asdf](https://asdf-vm.com/guide/getting-started.html#_2-download-asdf) by running the following:
|
||||
|
||||
```
|
||||
git clone https://github.com/asdf-vm/asdf.git ~/.asdf
|
||||
```
|
||||
|
||||
2. [Enable asdf](https://asdf-vm.com/guide/getting-started.html#_3-install-asdf) by adding it to your `plugins` definition in `~/.zshrc`.
|
||||
|
||||
```
|
||||
plugins=(asdf)
|
||||
```
|
||||
|
||||
2. [Install asdf](https://github.com/asdf-vm/asdf#setup) by running the following:
|
||||
```
|
||||
git clone https://github.com/asdf-vm/asdf.git ~/.asdf
|
||||
```
|
||||
|
||||
### Usage
|
||||
|
||||
See the [asdf usage documentation](https://github.com/asdf-vm/asdf#usage) for information on how to use asdf:
|
||||
See the [asdf documentation](https://asdf-vm.com/guide/getting-started.html#_4-install-a-plugin) for information on how to use asdf:
|
||||
|
||||
```
|
||||
asdf plugin-add nodejs git@github.com:asdf-vm/asdf-nodejs.git
|
||||
asdf install nodejs 5.9.1
|
||||
asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git
|
||||
asdf install nodejs latest
|
||||
asdf global nodejs latest
|
||||
asdf local nodejs latest
|
||||
```
|
||||
|
|
|
|||
|
|
@ -2,18 +2,29 @@
|
|||
ASDF_DIR="${ASDF_DIR:-$HOME/.asdf}"
|
||||
ASDF_COMPLETIONS="$ASDF_DIR/completions"
|
||||
|
||||
# If not found, check for Homebrew package
|
||||
if [[ ! -f "$ASDF_DIR/asdf.sh" || ! -f "$ASDF_COMPLETIONS/asdf.bash" ]] && (( $+commands[brew] )); then
|
||||
ASDF_DIR="$(brew --prefix asdf)"
|
||||
ASDF_COMPLETIONS="$ASDF_DIR/etc/bash_completion.d"
|
||||
if [[ ! -f "$ASDF_DIR/asdf.sh" || ! -f "$ASDF_COMPLETIONS/_asdf" ]]; then
|
||||
# If not found, check for archlinux/AUR package (/opt/asdf-vm/)
|
||||
if [[ -f "/opt/asdf-vm/asdf.sh" ]]; then
|
||||
ASDF_DIR="/opt/asdf-vm"
|
||||
ASDF_COMPLETIONS="$ASDF_DIR"
|
||||
# If not found, check for Homebrew package
|
||||
elif (( $+commands[brew] )); then
|
||||
_ASDF_PREFIX="$(brew --prefix asdf)"
|
||||
ASDF_DIR="${_ASDF_PREFIX}/libexec"
|
||||
ASDF_COMPLETIONS="${_ASDF_PREFIX}/share/zsh/site-functions"
|
||||
unset _ASDF_PREFIX
|
||||
else
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
# Load command
|
||||
if [[ -f "$ASDF_DIR/asdf.sh" ]]; then
|
||||
. "$ASDF_DIR/asdf.sh"
|
||||
|
||||
# Load completions
|
||||
if [[ -f "$ASDF_COMPLETIONS/asdf.bash" ]]; then
|
||||
. "$ASDF_COMPLETIONS/asdf.bash"
|
||||
fi
|
||||
source "$ASDF_DIR/asdf.sh"
|
||||
# Load completions
|
||||
if [[ -f "$ASDF_COMPLETIONS/_asdf" ]]; then
|
||||
fpath+=("$ASDF_COMPLETIONS")
|
||||
autoload -Uz _asdf
|
||||
compdef _asdf asdf # compdef is already loaded before loading plugins
|
||||
fi
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -13,12 +13,17 @@ if ! type autoenv_init >/dev/null; then
|
|||
~/.autoenv
|
||||
~/.local/bin
|
||||
/usr/local/opt/autoenv
|
||||
/opt/homebrew/opt/autoenv
|
||||
/usr/local/bin
|
||||
/usr/share/autoenv-git
|
||||
~/Library/Python/bin
|
||||
.venv/bin
|
||||
venv/bin
|
||||
env/bin
|
||||
.env/bin
|
||||
)
|
||||
for d ( $install_locations ); do
|
||||
if [[ -e $d/activate.sh ]]; then
|
||||
if [[ -e $d/activate || -e $d/activate.sh ]]; then
|
||||
autoenv_dir=$d
|
||||
break
|
||||
fi
|
||||
|
|
@ -28,13 +33,13 @@ if ! type autoenv_init >/dev/null; then
|
|||
# Look for Homebrew path as a last resort
|
||||
if [[ -z "$autoenv_dir" ]] && (( $+commands[brew] )); then
|
||||
d=$(brew --prefix)/opt/autoenv
|
||||
if [[ -e $d/activate.sh ]]; then
|
||||
if [[ -e $d/activate || -e $d/activate.sh ]]; then
|
||||
autoenv_dir=$d
|
||||
fi
|
||||
fi
|
||||
|
||||
# Complain if autoenv is not installed
|
||||
if [[ -z $autoenv_dir ]]; then
|
||||
if [[ -z $autoenv_dir ]]; then
|
||||
cat <<END >&2
|
||||
-------- AUTOENV ---------
|
||||
Could not locate autoenv installation.
|
||||
|
|
@ -45,7 +50,11 @@ END
|
|||
return 1
|
||||
fi
|
||||
# Load autoenv
|
||||
source $autoenv_dir/activate.sh
|
||||
if [[ -e $autoenv_dir/activate ]]; then
|
||||
source $autoenv_dir/activate
|
||||
else
|
||||
source $autoenv_dir/activate.sh
|
||||
fi
|
||||
fi
|
||||
}
|
||||
[[ $? != 0 ]] && return $?
|
||||
|
|
|
|||
|
|
@ -1,15 +1,21 @@
|
|||
declare -a autojump_paths
|
||||
autojump_paths=(
|
||||
$HOME/.autojump/etc/profile.d/autojump.zsh # manual installation
|
||||
$HOME/.autojump/share/autojump/autojump.zsh # manual installation
|
||||
$HOME/.nix-profile/etc/profile.d/autojump.sh # NixOS installation
|
||||
/run/current-system/sw/share/autojump/autojump.zsh # NixOS installation
|
||||
/usr/share/autojump/autojump.zsh # Debian and Ubuntu package
|
||||
/etc/profile.d/autojump.zsh # manual installation
|
||||
/etc/profile.d/autojump.sh # Gentoo installation
|
||||
/usr/local/share/autojump/autojump.zsh # FreeBSD installation
|
||||
/opt/local/etc/profile.d/autojump.sh # macOS with MacPorts
|
||||
/usr/local/etc/profile.d/autojump.sh # macOS with Homebrew (default)
|
||||
$HOME/.autojump/etc/profile.d/autojump.zsh # manual installation
|
||||
$HOME/.autojump/share/autojump/autojump.zsh # manual installation
|
||||
$HOME/.nix-profile/etc/profile.d/autojump.sh # NixOS installation
|
||||
/run/current-system/sw/share/autojump/autojump.zsh # NixOS installation
|
||||
/etc/profiles/per-user/$USER/share/autojump/autojump.zsh # Home Manager, NixOS with user-scoped packages
|
||||
/usr/share/autojump/autojump.zsh # Debian and Ubuntu package
|
||||
/etc/profile.d/autojump.zsh # manual installation
|
||||
/etc/profile.d/autojump.sh # Gentoo installation
|
||||
/usr/local/share/autojump/autojump.zsh # FreeBSD installation
|
||||
/usr/pkg/share/autojump/autojump.zsh # NetBSD installation
|
||||
/opt/local/etc/profile.d/autojump.sh # macOS with MacPorts
|
||||
/usr/local/etc/profile.d/autojump.sh # macOS with Homebrew (default)
|
||||
/opt/homebrew/etc/profile.d/autojump.sh # macOS with Homebrew (default on M1 macs)
|
||||
/opt/pkg/share/autojump/autojump.zsh # macOS with pkgsrc
|
||||
/etc/profiles/per-user/$USER/etc/profile.d/autojump.sh # macOS Nix, Home Manager and flakes
|
||||
/nix/var/nix/gcroots/current-system/sw/share/zsh/site-functions/autojump.zsh # macOS Nix, nix-darwin
|
||||
)
|
||||
|
||||
for file in $autojump_paths; do
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
# aws
|
||||
|
||||
This plugin provides completion support for [awscli](https://docs.aws.amazon.com/cli/latest/reference/index.html)
|
||||
and a few utilities to manage AWS profiles and display them in the prompt.
|
||||
This plugin provides completion support for [awscli v2](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/index.html)
|
||||
and a few utilities to manage AWS profiles/regions and display them in the prompt.
|
||||
[awscli v1](https://docs.aws.amazon.com/cli/latest/userguide/cliv2-migration.html) is no longer supported.
|
||||
|
||||
To use it, add `aws` to the plugins array in your zshrc file.
|
||||
|
||||
|
|
@ -12,27 +13,86 @@ plugins=(... aws)
|
|||
## Plugin commands
|
||||
|
||||
* `asp [<profile>]`: sets `$AWS_PROFILE` and `$AWS_DEFAULT_PROFILE` (legacy) to `<profile>`.
|
||||
It also sets `$AWS_EB_PROFILE` to `<profile>` for the Elastic Beanstalk CLI.
|
||||
It also sets `$AWS_EB_PROFILE` to `<profile>` for the Elastic Beanstalk CLI. It sets `$AWS_PROFILE_REGION` for display in `aws_prompt_info`.
|
||||
Run `asp` without arguments to clear the profile.
|
||||
* `asp [<profile>] login`: If AWS SSO has been configured in your aws profile, it will run the `aws sso login` command following profile selection.
|
||||
* `asp [<profile>] login [<sso_session>]`: In addition to `asp [<profile>] login`, if SSO session has been configured in your aws profile, it will run the `aws sso login --sso-session <sso_session>` command following profile selection.
|
||||
* `asp [<profile>] logout`: If AWS SSO has been configured in your aws profile, it will run the `aws sso logout` command following profile selection.
|
||||
|
||||
* `asr [<region>]`: sets `$AWS_REGION` and `$AWS_DEFAULT_REGION` (legacy) to `<region>`.
|
||||
Run `asr` without arguments to clear the profile.
|
||||
|
||||
* `acp [<profile>] [<mfa_token>]`: in addition to `asp` functionality, it actually changes
|
||||
the profile by assuming the role specified in the `<profile>` configuration. It supports
|
||||
MFA and sets `$AWS_ACCESS_KEY_ID`, `$AWS_SECRET_ACCESS_KEY` and `$AWS_SESSION_TOKEN`, if
|
||||
obtained. It requires the roles to be configured as per the
|
||||
[official guide](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-role.html).
|
||||
Run `acp` without arguments to clear the profile.
|
||||
|
||||
* `agp`: gets the current value of `$AWS_PROFILE`.
|
||||
|
||||
* `agr`: gets the current value of `$AWS_REGION`.
|
||||
|
||||
* `aws_change_access_key`: changes the AWS access key of a profile.
|
||||
|
||||
* `aws_profiles`: lists the available profiles in the `$AWS_CONFIG_FILE` (default: `~/.aws/config`).
|
||||
Used to provide completion for the `asp` function.
|
||||
|
||||
* `aws_regions`: lists the available regions.
|
||||
Used to provide completion for the `asr` function.
|
||||
|
||||
## Plugin options
|
||||
|
||||
* Set `SHOW_AWS_PROMPT=false` in your zshrc file if you want to prevent the plugin from modifying your RPROMPT.
|
||||
Some themes might overwrite the value of RPROMPT instead of appending to it, so they'll need to be fixed to
|
||||
see the AWS profile prompt.
|
||||
see the AWS profile/region prompt.
|
||||
|
||||
* Set `AWS_PROFILE_STATE_ENABLED=true` in your zshrc file if you want the aws profile to persist between shell sessions.
|
||||
This option might slow down your shell startup time.
|
||||
By default the state file path is `/tmp/.aws_current_profile`. This means that the state won't survive a reboot or otherwise GC.
|
||||
You can control the state file path using the `AWS_STATE_FILE` environment variable.
|
||||
|
||||
## Theme
|
||||
|
||||
The plugin creates an `aws_prompt_info` function that you can use in your theme, which displays
|
||||
the current `$AWS_PROFILE`. It uses two variables to control how that is shown:
|
||||
the current `$AWS_PROFILE` and `$AWS_REGION`. It uses four variables to control how that is shown:
|
||||
|
||||
- ZSH_THEME_AWS_PREFIX: sets the prefix of the AWS_PROFILE. Defaults to `<aws:`.
|
||||
* ZSH_THEME_AWS_PROFILE_PREFIX: sets the prefix of the AWS_PROFILE. Defaults to `<aws:`.
|
||||
|
||||
- ZSH_THEME_AWS_SUFFIX: sets the suffix of the AWS_PROFILE. Defaults to `>`.
|
||||
* ZSH_THEME_AWS_PROFILE_SUFFIX: sets the suffix of the AWS_PROFILE. Defaults to `>`.
|
||||
|
||||
* ZSH_THEME_AWS_REGION_PREFIX: sets the prefix of the AWS_REGION. Defaults to `<region:`.
|
||||
|
||||
* ZSH_THEME_AWS_REGION_SUFFIX: sets the suffix of the AWS_REGION. Defaults to `>`.
|
||||
|
||||
* ZSH_THEME_AWS_DIVIDER: sets the divider between ZSH_THEME_AWS_PROFILE_SUFFIX and ZSH_THEME_AWS_REGION_PREFIX. Defaults to ` ` (single space).
|
||||
|
||||
## Configuration
|
||||
|
||||
[Configuration and credential file settings](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) by AWS
|
||||
|
||||
### Scenario: IAM roles with a source profile and MFA authentication
|
||||
|
||||
Source profile credentials in `~/.aws/credentials`:
|
||||
|
||||
```ini
|
||||
[source-profile-name]
|
||||
aws_access_key_id = ...
|
||||
aws_secret_access_key = ...
|
||||
```
|
||||
|
||||
Role configuration in `~/.aws/config`:
|
||||
|
||||
```ini
|
||||
[profile source-profile-name]
|
||||
mfa_serial = arn:aws:iam::111111111111:mfa/myuser
|
||||
region = us-east-1
|
||||
output = json
|
||||
|
||||
[profile profile-with-role]
|
||||
role_arn = arn:aws:iam::9999999999999:role/myrole
|
||||
mfa_serial = arn:aws:iam::111111111111:mfa/myuser
|
||||
source_profile = source-profile-name
|
||||
region = us-east-1
|
||||
output = json
|
||||
```
|
||||
|
|
|
|||
|
|
@ -2,10 +2,30 @@ function agp() {
|
|||
echo $AWS_PROFILE
|
||||
}
|
||||
|
||||
function agr() {
|
||||
echo $AWS_REGION
|
||||
}
|
||||
|
||||
# Update state file if enabled
|
||||
function _aws_update_state() {
|
||||
if [[ "$AWS_PROFILE_STATE_ENABLED" == true ]]; then
|
||||
test -d $(dirname ${AWS_STATE_FILE}) || exit 1
|
||||
echo "${AWS_PROFILE} ${AWS_REGION}" > "${AWS_STATE_FILE}"
|
||||
fi
|
||||
}
|
||||
|
||||
function _aws_clear_state() {
|
||||
if [[ "$AWS_PROFILE_STATE_ENABLED" == true ]]; then
|
||||
test -d $(dirname ${AWS_STATE_FILE}) || exit 1
|
||||
echo -n > "${AWS_STATE_FILE}"
|
||||
fi
|
||||
}
|
||||
|
||||
# AWS profile selection
|
||||
function asp() {
|
||||
if [[ -z "$1" ]]; then
|
||||
unset AWS_DEFAULT_PROFILE AWS_PROFILE AWS_EB_PROFILE
|
||||
unset AWS_DEFAULT_PROFILE AWS_PROFILE AWS_EB_PROFILE AWS_PROFILE_REGION
|
||||
_aws_clear_state
|
||||
echo AWS profile cleared.
|
||||
return
|
||||
fi
|
||||
|
|
@ -21,6 +41,143 @@ function asp() {
|
|||
export AWS_DEFAULT_PROFILE=$1
|
||||
export AWS_PROFILE=$1
|
||||
export AWS_EB_PROFILE=$1
|
||||
|
||||
export AWS_PROFILE_REGION=$(aws configure get region)
|
||||
|
||||
_aws_update_state
|
||||
|
||||
if [[ "$2" == "login" ]]; then
|
||||
if [[ -n "$3" ]]; then
|
||||
aws sso login --sso-session $3
|
||||
else
|
||||
aws sso login
|
||||
fi
|
||||
elif [[ "$2" == "logout" ]]; then
|
||||
aws sso logout
|
||||
fi
|
||||
}
|
||||
|
||||
# AWS region selection
|
||||
function asr() {
|
||||
if [[ -z "$1" ]]; then
|
||||
unset AWS_DEFAULT_REGION AWS_REGION
|
||||
_aws_update_state
|
||||
echo AWS region cleared.
|
||||
return
|
||||
fi
|
||||
|
||||
local -a available_regions
|
||||
available_regions=($(aws_regions))
|
||||
if [[ -z "${available_regions[(r)$1]}" ]]; then
|
||||
echo "${fg[red]}Available regions: \n$(aws_regions)"
|
||||
return 1
|
||||
fi
|
||||
|
||||
export AWS_REGION=$1
|
||||
export AWS_DEFAULT_REGION=$1
|
||||
_aws_update_state
|
||||
}
|
||||
|
||||
# AWS profile switch
|
||||
function acp() {
|
||||
if [[ -z "$1" ]]; then
|
||||
unset AWS_DEFAULT_PROFILE AWS_PROFILE AWS_EB_PROFILE
|
||||
unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN
|
||||
echo AWS profile cleared.
|
||||
return
|
||||
fi
|
||||
|
||||
local -a available_profiles
|
||||
available_profiles=($(aws_profiles))
|
||||
if [[ -z "${available_profiles[(r)$1]}" ]]; then
|
||||
echo "${fg[red]}Profile '$1' not found in '${AWS_CONFIG_FILE:-$HOME/.aws/config}'" >&2
|
||||
echo "Available profiles: ${(j:, :)available_profiles:-no profiles found}${reset_color}" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
local profile="$1"
|
||||
local mfa_token="$2"
|
||||
|
||||
# Get fallback credentials for if the aws command fails or no command is run
|
||||
local aws_access_key_id="$(aws configure get aws_access_key_id --profile $profile)"
|
||||
local aws_secret_access_key="$(aws configure get aws_secret_access_key --profile $profile)"
|
||||
local aws_session_token="$(aws configure get aws_session_token --profile $profile)"
|
||||
|
||||
|
||||
# First, if the profile has MFA configured, lets get the token and session duration
|
||||
local mfa_serial="$(aws configure get mfa_serial --profile $profile)"
|
||||
local sess_duration="$(aws configure get duration_seconds --profile $profile)"
|
||||
|
||||
if [[ -n "$mfa_serial" ]]; then
|
||||
local -a mfa_opt
|
||||
if [[ -z "$mfa_token" ]]; then
|
||||
echo -n "Please enter your MFA token for $mfa_serial: "
|
||||
read -r mfa_token
|
||||
fi
|
||||
if [[ -z "$sess_duration" ]]; then
|
||||
echo -n "Please enter the session duration in seconds (900-43200; default: 3600, which is the default maximum for a role): "
|
||||
read -r sess_duration
|
||||
fi
|
||||
mfa_opt=(--serial-number "$mfa_serial" --token-code "$mfa_token" --duration-seconds "${sess_duration:-3600}")
|
||||
fi
|
||||
|
||||
# Now see whether we need to just MFA for the current role, or assume a different one
|
||||
local role_arn="$(aws configure get role_arn --profile $profile)"
|
||||
local sess_name="$(aws configure get role_session_name --profile $profile)"
|
||||
|
||||
if [[ -n "$role_arn" ]]; then
|
||||
# Means we need to assume a specified role
|
||||
aws_command=(aws sts assume-role --role-arn "$role_arn" "${mfa_opt[@]}")
|
||||
|
||||
# Check whether external_id is configured to use while assuming the role
|
||||
local external_id="$(aws configure get external_id --profile $profile)"
|
||||
if [[ -n "$external_id" ]]; then
|
||||
aws_command+=(--external-id "$external_id")
|
||||
fi
|
||||
|
||||
# Get source profile to use to assume role
|
||||
local source_profile="$(aws configure get source_profile --profile $profile)"
|
||||
if [[ -z "$sess_name" ]]; then
|
||||
sess_name="${source_profile:-profile}"
|
||||
fi
|
||||
aws_command+=(--profile="${source_profile:-profile}" --role-session-name "${sess_name}")
|
||||
|
||||
echo "Assuming role $role_arn using profile ${source_profile:-profile}"
|
||||
else
|
||||
# Means we only need to do MFA
|
||||
aws_command=(aws sts get-session-token --profile="$profile" "${mfa_opt[@]}")
|
||||
echo "Obtaining session token for profile $profile"
|
||||
fi
|
||||
|
||||
# Format output of aws command for easier processing
|
||||
aws_command+=(--query '[Credentials.AccessKeyId,Credentials.SecretAccessKey,Credentials.SessionToken]' --output text)
|
||||
|
||||
# Run the aws command to obtain credentials
|
||||
local -a credentials
|
||||
credentials=(${(ps:\t:)"$(${aws_command[@]})"})
|
||||
|
||||
if [[ -n "$credentials" ]]; then
|
||||
aws_access_key_id="${credentials[1]}"
|
||||
aws_secret_access_key="${credentials[2]}"
|
||||
aws_session_token="${credentials[3]}"
|
||||
fi
|
||||
|
||||
# Switch to AWS profile
|
||||
if [[ -n "${aws_access_key_id}" && -n "$aws_secret_access_key" ]]; then
|
||||
export AWS_DEFAULT_PROFILE="$profile"
|
||||
export AWS_PROFILE="$profile"
|
||||
export AWS_EB_PROFILE="$profile"
|
||||
export AWS_ACCESS_KEY_ID="$aws_access_key_id"
|
||||
export AWS_SECRET_ACCESS_KEY="$aws_secret_access_key"
|
||||
|
||||
if [[ -n "$aws_session_token" ]]; then
|
||||
export AWS_SESSION_TOKEN="$aws_session_token"
|
||||
else
|
||||
unset AWS_SESSION_TOKEN
|
||||
fi
|
||||
|
||||
echo "Switched to AWS Profile: $profile"
|
||||
fi
|
||||
}
|
||||
|
||||
function aws_change_access_key() {
|
||||
|
|
@ -29,36 +186,110 @@ function aws_change_access_key() {
|
|||
return 1
|
||||
fi
|
||||
|
||||
echo Insert the credentials when asked.
|
||||
asp "$1" || return 1
|
||||
AWS_PAGER="" aws iam create-access-key
|
||||
AWS_PAGER="" aws configure --profile "$1"
|
||||
local profile="$1"
|
||||
# Get current access key
|
||||
local original_aws_access_key_id="$(aws configure get aws_access_key_id --profile $profile)"
|
||||
|
||||
echo You can now safely delete the old access key running \`aws iam delete-access-key --access-key-id ID\`
|
||||
echo Your current keys are:
|
||||
AWS_PAGER="" aws iam list-access-keys
|
||||
asp "$profile" || return 1
|
||||
echo "Generating a new access key pair for you now."
|
||||
if aws --no-cli-pager iam create-access-key; then
|
||||
echo "Insert the newly generated credentials when asked."
|
||||
aws --no-cli-pager configure --profile $profile
|
||||
else
|
||||
echo "Current access keys:"
|
||||
aws --no-cli-pager iam list-access-keys
|
||||
echo "Profile \"${profile}\" is currently using the $original_aws_access_key_id key. You can delete an old access key by running \`aws --profile $profile iam delete-access-key --access-key-id AccessKeyId\`"
|
||||
return 1
|
||||
fi
|
||||
|
||||
read -q "yn?Would you like to disable your previous access key (${original_aws_access_key_id}) now? "
|
||||
case $yn in
|
||||
[Yy]*)
|
||||
echo -n "\nDisabling access key ${original_aws_access_key_id}..."
|
||||
if aws --no-cli-pager iam update-access-key --access-key-id ${original_aws_access_key_id} --status Inactive; then
|
||||
echo "done."
|
||||
else
|
||||
echo "\nFailed to disable ${original_aws_access_key_id} key."
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo ""
|
||||
;;
|
||||
esac
|
||||
echo "You can now safely delete the old access key by running \`aws --profile $profile iam delete-access-key --access-key-id ${original_aws_access_key_id}\`"
|
||||
echo "Your current keys are:"
|
||||
aws --no-cli-pager iam list-access-keys
|
||||
}
|
||||
|
||||
function aws_regions() {
|
||||
local region
|
||||
if [[ $AWS_DEFAULT_REGION ]];then
|
||||
region="$AWS_DEFAULT_REGION"
|
||||
elif [[ $AWS_REGION ]];then
|
||||
region="$AWS_REGION"
|
||||
else
|
||||
region="us-west-1"
|
||||
fi
|
||||
|
||||
if [[ $AWS_DEFAULT_PROFILE || $AWS_PROFILE ]];then
|
||||
aws ec2 describe-regions --region $region |grep RegionName | awk -F ':' '{gsub(/"/, "", $2);gsub(/,/, "", $2);gsub(/ /, "", $2); print $2}'
|
||||
else
|
||||
echo "You must specify a AWS profile."
|
||||
fi
|
||||
}
|
||||
|
||||
function aws_profiles() {
|
||||
aws --no-cli-pager configure list-profiles 2> /dev/null && return
|
||||
[[ -r "${AWS_CONFIG_FILE:-$HOME/.aws/config}" ]] || return 1
|
||||
grep '\[profile' "${AWS_CONFIG_FILE:-$HOME/.aws/config}"|sed -e 's/.*profile \([a-zA-Z0-9@_\.-]*\).*/\1/'
|
||||
grep --color=never -Eo '\[.*\]' "${AWS_CONFIG_FILE:-$HOME/.aws/config}" | sed -E 's/^[[:space:]]*\[(profile)?[[:space:]]*([^[:space:]]+)\][[:space:]]*$/\2/g'
|
||||
}
|
||||
|
||||
function _aws_regions() {
|
||||
reply=($(aws_regions))
|
||||
}
|
||||
compctl -K _aws_regions asr
|
||||
|
||||
function _aws_profiles() {
|
||||
reply=($(aws_profiles))
|
||||
}
|
||||
compctl -K _aws_profiles asp aws_change_access_key
|
||||
compctl -K _aws_profiles asp acp aws_change_access_key
|
||||
|
||||
# AWS prompt
|
||||
function aws_prompt_info() {
|
||||
[[ -z $AWS_PROFILE ]] && return
|
||||
echo "${ZSH_THEME_AWS_PREFIX:=<aws:}${AWS_PROFILE}${ZSH_THEME_AWS_SUFFIX:=>}"
|
||||
local _aws_to_show
|
||||
local region="${AWS_REGION:-${AWS_DEFAULT_REGION:-$AWS_PROFILE_REGION}}"
|
||||
|
||||
if [[ -n "$AWS_PROFILE" ]];then
|
||||
_aws_to_show+="${ZSH_THEME_AWS_PROFILE_PREFIX="<aws:"}${AWS_PROFILE}${ZSH_THEME_AWS_PROFILE_SUFFIX=">"}"
|
||||
fi
|
||||
|
||||
if [[ -n "$region" ]]; then
|
||||
[[ -n "$_aws_to_show" ]] && _aws_to_show+="${ZSH_THEME_AWS_DIVIDER=" "}"
|
||||
_aws_to_show+="${ZSH_THEME_AWS_REGION_PREFIX="<region:"}${region}${ZSH_THEME_AWS_REGION_SUFFIX=">"}"
|
||||
fi
|
||||
|
||||
echo "$_aws_to_show"
|
||||
}
|
||||
|
||||
if [ "$SHOW_AWS_PROMPT" != false ]; then
|
||||
if [[ "$SHOW_AWS_PROMPT" != false && "$RPROMPT" != *'$(aws_prompt_info)'* ]]; then
|
||||
RPROMPT='$(aws_prompt_info)'"$RPROMPT"
|
||||
fi
|
||||
|
||||
if [[ "$AWS_PROFILE_STATE_ENABLED" == true ]]; then
|
||||
AWS_STATE_FILE="${AWS_STATE_FILE:-/tmp/.aws_current_profile}"
|
||||
test -s "${AWS_STATE_FILE}" || return
|
||||
|
||||
aws_state=($(cat $AWS_STATE_FILE))
|
||||
|
||||
export AWS_DEFAULT_PROFILE="${aws_state[1]}"
|
||||
export AWS_PROFILE="$AWS_DEFAULT_PROFILE"
|
||||
export AWS_EB_PROFILE="$AWS_DEFAULT_PROFILE"
|
||||
|
||||
test -z "${aws_state[2]}" && AWS_REGION=$(aws configure get region)
|
||||
|
||||
export AWS_REGION=${AWS_REGION:-$aws_state[2]}
|
||||
export AWS_DEFAULT_REGION="$AWS_REGION"
|
||||
fi
|
||||
|
||||
# Load awscli completions
|
||||
|
||||
|
|
@ -104,3 +335,4 @@ else
|
|||
[[ -r $_aws_zsh_completer_path ]] && source $_aws_zsh_completer_path
|
||||
unset _aws_zsh_completer_path _brew_prefix
|
||||
fi
|
||||
|
||||
|
|
|
|||
49
plugins/azure/README.md
Normal file
49
plugins/azure/README.md
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
# azure
|
||||
|
||||
This plugin provides completion support for [azure cli](https://docs.microsoft.com/en-us/cli/azure/)
|
||||
and a few utilities to manage azure subscriptions and display them in the prompt.
|
||||
|
||||
To use it, add `azure` to the plugins array in your zshrc file.
|
||||
|
||||
```zsh
|
||||
plugins=(... azure)
|
||||
```
|
||||
|
||||
## Plugin commands
|
||||
|
||||
|
||||
* `az_subscriptions`: lists the available subscriptions in the `AZURE_CONFIG_DIR` (default: `~/.azure/`).
|
||||
Used to provide completion for the `azss` function.
|
||||
|
||||
* `azgs`: gets the current value of `$azure_subscription`.
|
||||
|
||||
* `azss [<subscription>]`: sets the `$azure_subscription`.
|
||||
|
||||
|
||||
NOTE : because azure keeps the state of active subscription in ${AZURE_CONFIG_DIR:-$HOME/.azure/azureProfile.json}, the prompt command requires `jq` to be enabled to parse the file. If jq is not in the path the prompt will show nothing
|
||||
|
||||
## Theme
|
||||
|
||||
The plugin creates an `azure_prompt_info` function that you can use in your theme, which displays
|
||||
the current `$azure_subscription`. It uses two variables to control how that is shown:
|
||||
|
||||
- ZSH_THEME_AZURE_PREFIX: sets the prefix of the azure_subscription. Defaults to `<az:`.
|
||||
|
||||
- ZSH_THEME_azure_SUFFIX: sets the suffix of the azure_subscription. Defaults to `>`.
|
||||
|
||||
|
||||
```
|
||||
RPROMPT='$(azure_prompt_info)'
|
||||
```
|
||||
|
||||
## Develop
|
||||
|
||||
On ubuntu get a working environment with :
|
||||
|
||||
` docker run -it -v $(pwd):/mnt -w /mnt ubuntu bash`
|
||||
|
||||
```
|
||||
apt install -y curl jq zsh git vim
|
||||
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
|
||||
curl -sL https://aka.ms/InstallAzureCLIDeb | bash
|
||||
```
|
||||
60
plugins/azure/azure.plugin.zsh
Normal file
60
plugins/azure/azure.plugin.zsh
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
# AZ Get Subscriptions
|
||||
function azgs() {
|
||||
az account show --output tsv --query 'name' 2>/dev/null
|
||||
}
|
||||
|
||||
# AZ Subscription Selection
|
||||
alias azss="az account set --subscription"
|
||||
|
||||
|
||||
function az_subscriptions() {
|
||||
az account list --all --output tsv --query '[*].name' 2> /dev/null
|
||||
}
|
||||
|
||||
function _az_subscriptions() {
|
||||
reply=($(az_subscriptions))
|
||||
}
|
||||
compctl -K _az_subscriptions azss
|
||||
|
||||
# Azure prompt
|
||||
function azure_prompt_info() {
|
||||
[[ ! -f "${AZURE_CONFIG_DIR:-$HOME/.azure}/azureProfile.json" ]] && return
|
||||
# azgs is too expensive, if we have jq, we enable the prompt
|
||||
(( $+commands[jq] )) || return 1
|
||||
azgs=$(jq -r '.subscriptions[] | select(.isDefault==true) .name' "${AZURE_CONFIG_DIR:-$HOME/.azure}/azureProfile.json")
|
||||
echo "${ZSH_THEME_AZURE_PREFIX:=<az:}${azgs}${ZSH_THEME_AZURE_SUFFIX:=>}"
|
||||
}
|
||||
|
||||
|
||||
# Load az completions
|
||||
function _az-homebrew-installed() {
|
||||
# check if Homebrew is installed
|
||||
(( $+commands[brew] )) || return 1
|
||||
|
||||
# if so, we assume it's default way to install brew
|
||||
if [[ ${commands[brew]:t2} == bin/brew ]]; then
|
||||
_brew_prefix="${commands[brew]:h:h}" # remove trailing /bin/brew
|
||||
else
|
||||
# ok, it is not in the default prefix
|
||||
# this call to brew is expensive (about 400 ms), so at least let's make it only once
|
||||
_brew_prefix=$(brew --prefix)
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# get az.completion.sh location from $PATH
|
||||
_az_zsh_completer_path="$commands[az_zsh_completer.sh]"
|
||||
|
||||
# otherwise check common locations
|
||||
if [[ -z $_az_zsh_completer_path ]]; then
|
||||
# Homebrew
|
||||
if _az-homebrew-installed; then
|
||||
_az_zsh_completer_path=$_brew_prefix/etc/bash_completion.d/az
|
||||
# Linux
|
||||
else
|
||||
_az_zsh_completer_path=/etc/bash_completion.d/azure-cli
|
||||
fi
|
||||
fi
|
||||
|
||||
[[ -r $_az_zsh_completer_path ]] && autoload -U +X bashcompinit && bashcompinit && source $_az_zsh_completer_path
|
||||
unset _az_zsh_completer_path _brew_prefix
|
||||
|
|
@ -8,15 +8,29 @@ To use, add `battery` to the list of plugins in your `.zshrc` file:
|
|||
|
||||
Then, add the `battery_pct_prompt` function to your custom theme. For example:
|
||||
|
||||
```
|
||||
```zsh
|
||||
RPROMPT='$(battery_pct_prompt) ...'
|
||||
```
|
||||
|
||||
Also, you set the `BATTERY_CHARGING` variable to your favor.
|
||||
For example:
|
||||
|
||||
```zsh
|
||||
BATTERY_CHARGING="⚡️"
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
On Linux, you must have the `acpi` tool installed on your operating system.
|
||||
- On Linux, you must have the `acpi` or `acpitool` commands installed on your operating system.
|
||||
On Debian/Ubuntu, you can do that with `sudo apt install acpi` or `sudo apt install acpitool`.
|
||||
|
||||
Here's an example of how to install with apt:
|
||||
```
|
||||
sudo apt-get install acpi
|
||||
```
|
||||
- On Android (via [Termux](https://play.google.com/store/apps/details?id=com.termux)), you must have:
|
||||
|
||||
1. The `Termux:API` addon app installed:
|
||||
[Google Play](https://play.google.com/store/apps/details?id=com.termux.api) | [F-Droid](https://f-droid.org/packages/com.termux.api/)
|
||||
|
||||
2. The `termux-api` package installed within termux:
|
||||
|
||||
```sh
|
||||
pkg install termux-api
|
||||
```
|
||||
|
|
|
|||
|
|
@ -10,20 +10,21 @@
|
|||
# Author: J (927589452) #
|
||||
# Modified to add support for FreeBSD #
|
||||
###########################################
|
||||
# Author: Avneet Singh (kalsi-avneet) #
|
||||
# Modified to add support for Android #
|
||||
###########################################
|
||||
# Author: Not Pua (im-notpua) #
|
||||
# Modified to add support for OpenBSD #
|
||||
###########################################
|
||||
|
||||
|
||||
if [[ "$OSTYPE" = darwin* ]]; then
|
||||
|
||||
function battery_is_charging() {
|
||||
ioreg -rc AppleSmartBattery | command grep -q '^.*"ExternalConnected"\ =\ Yes'
|
||||
}
|
||||
|
||||
function battery_pct() {
|
||||
local battery_status="$(ioreg -rc AppleSmartBattery)"
|
||||
local -i capacity=$(sed -n -e '/MaxCapacity/s/^.*"MaxCapacity"\ =\ //p' <<< $battery_status)
|
||||
local -i current=$(sed -n -e '/CurrentCapacity/s/^.*"CurrentCapacity"\ =\ //p' <<< $battery_status)
|
||||
echo $(( current * 100 / capacity ))
|
||||
pmset -g batt | grep -Eo "\d+%" | cut -d% -f1
|
||||
}
|
||||
|
||||
function battery_pct_remaining() {
|
||||
if battery_is_charging; then
|
||||
echo "External Power"
|
||||
|
|
@ -31,7 +32,6 @@ if [[ "$OSTYPE" = darwin* ]]; then
|
|||
battery_pct
|
||||
fi
|
||||
}
|
||||
|
||||
function battery_time_remaining() {
|
||||
local smart_battery_status="$(ioreg -rc "AppleSmartBattery")"
|
||||
if [[ $(echo $smart_battery_status | command grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]]; then
|
||||
|
|
@ -45,7 +45,6 @@ if [[ "$OSTYPE" = darwin* ]]; then
|
|||
echo "∞"
|
||||
fi
|
||||
}
|
||||
|
||||
function battery_pct_prompt () {
|
||||
local battery_pct color
|
||||
if ioreg -rc AppleSmartBattery | command grep -q '^.*"ExternalConnected"\ =\ No'; then
|
||||
|
|
@ -59,22 +58,19 @@ if [[ "$OSTYPE" = darwin* ]]; then
|
|||
fi
|
||||
echo "%{$fg[$color]%}[${battery_pct}%%]%{$reset_color%}"
|
||||
else
|
||||
echo "∞"
|
||||
echo "${BATTERY_CHARGING-⚡️}"
|
||||
fi
|
||||
}
|
||||
|
||||
elif [[ "$OSTYPE" = freebsd* ]]; then
|
||||
|
||||
function battery_is_charging() {
|
||||
[[ $(sysctl -n hw.acpi.battery.state) -eq 2 ]]
|
||||
}
|
||||
|
||||
function battery_pct() {
|
||||
if (( $+commands[sysctl] )); then
|
||||
sysctl -n hw.acpi.battery.life
|
||||
fi
|
||||
}
|
||||
|
||||
function battery_pct_remaining() {
|
||||
if ! battery_is_charging; then
|
||||
battery_pct
|
||||
|
|
@ -82,7 +78,6 @@ elif [[ "$OSTYPE" = freebsd* ]]; then
|
|||
echo "External Power"
|
||||
fi
|
||||
}
|
||||
|
||||
function battery_time_remaining() {
|
||||
local remaining_time
|
||||
remaining_time=$(sysctl -n hw.acpi.battery.time)
|
||||
|
|
@ -92,7 +87,85 @@ elif [[ "$OSTYPE" = freebsd* ]]; then
|
|||
printf %02d:%02d $hour $minute
|
||||
fi
|
||||
}
|
||||
|
||||
function battery_pct_prompt() {
|
||||
local battery_pct color
|
||||
battery_pct=$(battery_pct_remaining)
|
||||
if battery_is_charging; then
|
||||
echo "∞"
|
||||
else
|
||||
if [[ $battery_pct -gt 50 ]]; then
|
||||
color='green'
|
||||
elif [[ $battery_pct -gt 20 ]]; then
|
||||
color='yellow'
|
||||
else
|
||||
color='red'
|
||||
fi
|
||||
echo "%{$fg[$color]%}${battery_pct}%%%{$reset_color%}"
|
||||
fi
|
||||
}
|
||||
elif [[ "$OSTYPE" = linux-android ]] && (( ${+commands[termux-battery-status]} )); then
|
||||
function battery_is_charging() {
|
||||
termux-battery-status 2>/dev/null | command awk '/status/ { exit ($0 ~ /DISCHARGING/) }'
|
||||
}
|
||||
function battery_pct() {
|
||||
# Sample output:
|
||||
# {
|
||||
# "health": "GOOD",
|
||||
# "percentage": 93,
|
||||
# "plugged": "UNPLUGGED",
|
||||
# "status": "DISCHARGING",
|
||||
# "temperature": 29.0,
|
||||
# "current": 361816
|
||||
# }
|
||||
termux-battery-status 2>/dev/null | command awk '/percentage/ { gsub(/[,]/,""); print $2}'
|
||||
}
|
||||
function battery_pct_remaining() {
|
||||
if ! battery_is_charging; then
|
||||
battery_pct
|
||||
else
|
||||
echo "External Power"
|
||||
fi
|
||||
}
|
||||
function battery_time_remaining() { } # Not available on android
|
||||
function battery_pct_prompt() {
|
||||
local battery_pct color
|
||||
battery_pct=$(battery_pct_remaining)
|
||||
if battery_is_charging; then
|
||||
echo "∞"
|
||||
else
|
||||
if [[ $battery_pct -gt 50 ]]; then
|
||||
color='green'
|
||||
elif [[ $battery_pct -gt 20 ]]; then
|
||||
color='yellow'
|
||||
else
|
||||
color='red'
|
||||
fi
|
||||
echo "%{$fg[$color]%}${battery_pct}%%%{$reset_color%}"
|
||||
fi
|
||||
}
|
||||
elif [[ "$OSTYPE" = openbsd* ]]; then
|
||||
function battery_is_charging() {
|
||||
[[ $(apm -b) -eq 3 ]]
|
||||
}
|
||||
function battery_pct() {
|
||||
apm -l
|
||||
}
|
||||
function battery_pct_remaining() {
|
||||
if ! battery_is_charging; then
|
||||
battery_pct
|
||||
else
|
||||
echo "External Power"
|
||||
fi
|
||||
}
|
||||
function battery_time_remaining() {
|
||||
local remaining_time
|
||||
remaining_time=$(apm -m)
|
||||
if [[ $remaining_time -ge 0 ]]; then
|
||||
((hour = $remaining_time / 60 ))
|
||||
((minute = $remaining_time % 60 ))
|
||||
printf %02d:%02d $hour $minute
|
||||
fi
|
||||
}
|
||||
function battery_pct_prompt() {
|
||||
local battery_pct color
|
||||
battery_pct=$(battery_pct_remaining)
|
||||
|
|
@ -111,17 +184,42 @@ elif [[ "$OSTYPE" = freebsd* ]]; then
|
|||
}
|
||||
|
||||
elif [[ "$OSTYPE" = linux* ]]; then
|
||||
|
||||
function battery_is_charging() {
|
||||
! acpi 2>/dev/null | command grep -v "rate information unavailable" | command grep -q '^Battery.*Discharging'
|
||||
}
|
||||
|
||||
function battery_pct() {
|
||||
if (( $+commands[acpi] )); then
|
||||
acpi 2>/dev/null | command grep -v "rate information unavailable" | command grep -E '^Battery.*(Full|(Disc|C)harging)' | cut -f2 -d ',' | tr -cd '[:digit:]'
|
||||
if (( $+commands[acpitool] )); then
|
||||
! acpitool 2>/dev/null | command grep -qE '^\s+Battery.*Discharging'
|
||||
elif (( $+commands[acpi] )); then
|
||||
! acpi 2>/dev/null | command grep -v "rate information unavailable" | command grep -q '^Battery.*Discharging'
|
||||
fi
|
||||
}
|
||||
function battery_pct() {
|
||||
if (( $+commands[acpitool] )); then
|
||||
# Sample output:
|
||||
# Battery #1 : Unknown, 99.55%
|
||||
# Battery #2 : Discharging, 49.58%, 01:12:05
|
||||
# All batteries : 62.60%, 02:03:03
|
||||
local -i pct=$(acpitool 2>/dev/null | command awk -F, '
|
||||
/^\s+All batteries/ {
|
||||
gsub(/[^0-9.]/, "", $1)
|
||||
pct=$1
|
||||
exit
|
||||
}
|
||||
!pct && /^\s+Battery/ {
|
||||
gsub(/[^0-9.]/, "", $2)
|
||||
pct=$2
|
||||
}
|
||||
END { print pct }
|
||||
')
|
||||
echo $pct
|
||||
elif (( $+commands[acpi] )); then
|
||||
# Sample output:
|
||||
# Battery 0: Discharging, 0%, rate information unavailable
|
||||
# Battery 1: Full, 100%
|
||||
acpi 2>/dev/null | command awk -F, '
|
||||
/rate information unavailable/ { next }
|
||||
/^Battery.*: /{ gsub(/[^0-9]/, "", $2); print $2; exit }
|
||||
'
|
||||
fi
|
||||
}
|
||||
|
||||
function battery_pct_remaining() {
|
||||
if ! battery_is_charging; then
|
||||
battery_pct
|
||||
|
|
@ -129,13 +227,11 @@ elif [[ "$OSTYPE" = linux* ]]; then
|
|||
echo "External Power"
|
||||
fi
|
||||
}
|
||||
|
||||
function battery_time_remaining() {
|
||||
if ! battery_is_charging; then
|
||||
acpi 2>/dev/null | command grep -v "rate information unavailable" | cut -f3 -d ','
|
||||
fi
|
||||
}
|
||||
|
||||
function battery_pct_prompt() {
|
||||
local battery_pct color
|
||||
battery_pct=$(battery_pct_remaining)
|
||||
|
|
@ -152,7 +248,6 @@ elif [[ "$OSTYPE" = linux* ]]; then
|
|||
echo "%{$fg[$color]%}${battery_pct}%%%{$reset_color%}"
|
||||
fi
|
||||
}
|
||||
|
||||
else
|
||||
# Empty functions so we don't cause errors in prompts
|
||||
function battery_is_charging { false }
|
||||
|
|
@ -177,7 +272,7 @@ function battery_level_gauge() {
|
|||
local charging_color=${BATTERY_CHARGING_COLOR:-$color_yellow}
|
||||
local charging_symbol=${BATTERY_CHARGING_SYMBOL:-'⚡'}
|
||||
|
||||
local battery_remaining_percentage=$(battery_pct)
|
||||
local -i battery_remaining_percentage=$(battery_pct)
|
||||
local filled empty gauge_color
|
||||
|
||||
if [[ $battery_remaining_percentage =~ [0-9]+ ]]; then
|
||||
|
|
|
|||
|
|
@ -1,5 +1,22 @@
|
|||
## Bazel autocomplete plugin
|
||||
# Bazel plugin
|
||||
|
||||
A copy of the completion script from the
|
||||
[bazelbuild/bazel](https://github.com/bazelbuild/bazel/master/scripts/zsh_completion/_bazel)
|
||||
git repo.
|
||||
This plugin adds completion and aliases for [bazel](https://bazel.build), an open-source build and test tool that scalably supports multi-language and multi-platform projects.
|
||||
|
||||
To use it, add `bazel` to the plugins array in your zshrc file:
|
||||
|
||||
```zsh
|
||||
plugins=(... bazel)
|
||||
```
|
||||
|
||||
The plugin has a copy of [the completion script from the git repository][1].
|
||||
|
||||
[1]: https://github.com/bazelbuild/bazel/blob/master/scripts/zsh_completion/_bazel
|
||||
|
||||
## Aliases
|
||||
|
||||
| Alias | Command | Description |
|
||||
| ------- | -------------------------------------- | ------------------------------------------------------ |
|
||||
| bzb | `bazel build` | The `bazel build` command |
|
||||
| bzt | `bazel test` | The `bazel test` command |
|
||||
| bzr | `bazel run` | The `bazel run` command |
|
||||
| bzq | `bazel query` | The `bazel query` command |
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#compdef bazel
|
||||
#compdef bazel bazelisk
|
||||
|
||||
# Copyright 2015 The Bazel Authors. All rights reserved.
|
||||
#
|
||||
|
|
@ -164,7 +164,7 @@ _get_build_targets() {
|
|||
;;
|
||||
esac
|
||||
completions=(${$(_bazel_b query "kind(\"${rule_re}\", ${pkg}:all)" 2>/dev/null)##*:})
|
||||
if ( (( ${#completions} > 0 )) && [[ $target_type != run ]] ); then
|
||||
if ( (( ${#completions} > 0 )) && [[ $target_type != bin ]] ); then
|
||||
completions+=(all)
|
||||
fi
|
||||
echo ${completions[*]}
|
||||
|
|
|
|||
5
plugins/bazel/bazel.plugin.zsh
Normal file
5
plugins/bazel/bazel.plugin.zsh
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# Aliases for bazel
|
||||
alias bzb='bazel build'
|
||||
alias bzt='bazel test'
|
||||
alias bzr='bazel run'
|
||||
alias bzq='bazel query'
|
||||
5
plugins/bedtools/README.md
Normal file
5
plugins/bedtools/README.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# Bedtools plugin
|
||||
|
||||
This plugin adds support for the [bedtools suite](http://bedtools.readthedocs.org/en/latest/):
|
||||
|
||||
* Adds autocomplete options for all bedtools sub commands.
|
||||
64
plugins/bedtools/_bedtools
Normal file
64
plugins/bedtools/_bedtools
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#compdef bedtools
|
||||
#autoload
|
||||
|
||||
local curcontext="$curcontext" state line ret=1
|
||||
local -a _files
|
||||
|
||||
_arguments -C \
|
||||
'1: :->cmds' \
|
||||
'2:: :->args' && ret=0
|
||||
|
||||
case $state in
|
||||
cmds)
|
||||
_values "bedtools command" \
|
||||
"--contact[Feature requests, bugs, mailing lists, etc.]" \
|
||||
"--help[Print this help menu.]" \
|
||||
"--version[What version of bedtools are you using?.]" \
|
||||
"annotate[Annotate coverage of features from multiple files.]" \
|
||||
"bamtobed[Convert BAM alignments to BED (& other) formats.]" \
|
||||
"bamtofastq[Convert BAM records to FASTQ records.]" \
|
||||
"bed12tobed6[Breaks BED12 intervals into discrete BED6 intervals.]" \
|
||||
"bedpetobam[Convert BEDPE intervals to BAM records.]" \
|
||||
"bedtobam[Convert intervals to BAM records.]" \
|
||||
"closest[Find the closest, potentially non-overlapping interval.]" \
|
||||
"cluster[Cluster (but don't merge) overlapping/nearby intervals.]" \
|
||||
"complement[Extract intervals _not_ represented by an interval file.]" \
|
||||
"coverage[Compute the coverage over defined intervals.]" \
|
||||
"expand[Replicate lines based on lists of values in columns.]" \
|
||||
"fisher[Calculate Fisher statistic b/w two feature files.]" \
|
||||
"flank[Create new intervals from the flanks of existing intervals.]" \
|
||||
"genomecov[Compute the coverage over an entire genome.]" \
|
||||
"getfasta[Use intervals to extract sequences from a FASTA file.]" \
|
||||
"groupby[Group by common cols. & summarize oth. cols. (~ SQL "groupBy")]" \
|
||||
"igv[Create an IGV snapshot batch script.]" \
|
||||
"intersect[Find overlapping intervals in various ways.]" \
|
||||
"jaccard[Calculate the Jaccard statistic b/w two sets of intervals.]" \
|
||||
"links[Create a HTML page of links to UCSC locations.]" \
|
||||
"makewindows[Make interval "windows" across a genome.]" \
|
||||
"map[Apply a function to a column for each overlapping interval.]" \
|
||||
"maskfasta[Use intervals to mask sequences from a FASTA file.]" \
|
||||
"merge[Combine overlapping/nearby intervals into a single interval.]" \
|
||||
"multicov[Counts coverage from multiple BAMs at specific intervals.]" \
|
||||
"multiinter[Identifies common intervals among multiple interval files.]" \
|
||||
"nuc[Profile the nucleotide content of intervals in a FASTA file.]" \
|
||||
"overlap[Computes the amount of overlap from two intervals.]" \
|
||||
"pairtobed[Find pairs that overlap intervals in various ways.]" \
|
||||
"pairtopair[Find pairs that overlap other pairs in various ways.]" \
|
||||
"random[Generate random intervals in a genome.]" \
|
||||
"reldist[Calculate the distribution of relative distances b/w two files.]" \
|
||||
"sample[Sample random records from file using reservoir sampling.]" \
|
||||
"shuffle[Randomly redistrubute intervals in a genome.]" \
|
||||
"slop[Adjust the size of intervals.]" \
|
||||
"sort[Order the intervals in a file.]" \
|
||||
"subtract[Remove intervals based on overlaps b/w two files.]" \
|
||||
"tag[Tag BAM alignments based on overlaps with interval files.]" \
|
||||
"unionbedg[Combines coverage intervals from multiple BEDGRAPH files.]" \
|
||||
"window[Find overlapping intervals within a window around an interval.]" \
|
||||
ret=0
|
||||
;;
|
||||
*)
|
||||
_files
|
||||
;;
|
||||
esac
|
||||
|
||||
return ret
|
||||
|
|
@ -1,19 +1,19 @@
|
|||
# bgnotify zsh plugin
|
||||
|
||||
cross-platform background notifications for long running commands! Supports OSX and Ubuntu linux.
|
||||
cross-platform background notifications for long running commands! Supports OSX and Linux.
|
||||
|
||||
Standalone homepage: [t413/zsh-background-notify](https://github.com/t413/zsh-background-notify)
|
||||
|
||||
----------------------------------
|
||||
---
|
||||
|
||||
## How to use!
|
||||
## How to use
|
||||
|
||||
Just add bgnotify to your plugins list in your `.zshrc`
|
||||
|
||||
- On OS X you'll need [terminal-notifier](https://github.com/alloy/terminal-notifier)
|
||||
* `brew install terminal-notifier` (or `gem install terminal-notifier`)
|
||||
- On ubuntu you're already all set!
|
||||
- On windows you can use [notifu](https://www.paralint.com/projects/notifu/) or the Cygwin Ports libnotify package
|
||||
- On Linux, make sure you have `notify-send` or `kdialog` installed. If you're using Ubuntu you should already be all set!
|
||||
- On Windows you can use [notifu](https://www.paralint.com/projects/notifu/) or the Cygwin Ports libnotify package
|
||||
|
||||
|
||||
## Screenshots
|
||||
|
|
@ -35,20 +35,29 @@ Just add bgnotify to your plugins list in your `.zshrc`
|
|||
|
||||
One can configure a few things:
|
||||
|
||||
- `bgnotify_bell` enabled or disables the terminal bell (default true)
|
||||
- `bgnotify_threshold` sets the notification threshold time (default 6 seconds)
|
||||
- `function bgnotify_formatted` lets you change the notification
|
||||
- `function bgnotify_formatted` lets you change the notification. You can for instance customize the message and pass in an icon.
|
||||
|
||||
Use these by adding a function definition before the your call to source. Example:
|
||||
|
||||
~~~ sh
|
||||
```sh
|
||||
bgnotify_bell=false ## disable terminal bell
|
||||
bgnotify_threshold=4 ## set your own notification threshold
|
||||
|
||||
function bgnotify_formatted {
|
||||
## $1=exit_status, $2=command, $3=elapsed_time
|
||||
[ $1 -eq 0 ] && title="Holy Smokes Batman!" || title="Holy Graf Zeppelin!"
|
||||
bgnotify "$title -- after $3 s" "$2";
|
||||
|
||||
# Humanly readable elapsed time
|
||||
local elapsed="$(( $3 % 60 ))s"
|
||||
(( $3 < 60 )) || elapsed="$((( $3 % 3600) / 60 ))m $elapsed"
|
||||
(( $3 < 3600 )) || elapsed="$(( $3 / 3600 ))h $elapsed"
|
||||
|
||||
[ $1 -eq 0 ] && title="Holy Smokes Batman" || title="Holy Graf Zeppelin"
|
||||
[ $1 -eq 0 ] && icon="$HOME/icons/success.png" || icon="$HOME/icons/fail.png"
|
||||
bgnotify "$title - took ${elapsed}" "$2" "$icon"
|
||||
}
|
||||
|
||||
plugins=(git bgnotify) ## add to plugins list
|
||||
source $ZSH/oh-my-zsh.sh ## existing source call
|
||||
~~~
|
||||
```
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue