mirror of https://github.com/ohmyzsh/ohmyzsh.git
Compare commits
7 Commits
52b0da9c30
...
08cb9393a7
Author | SHA1 | Date |
---|---|---|
Siddharth Agrawal | 08cb9393a7 | |
Keith Bennett | bd0a5b2598 | |
jamesrtnz | 9a0e22c184 | |
Marc Cornellà | 501f29f90c | |
Marc Cornellà | cca4043238 | |
Siddharth Agrawal | c99a1c5fb5 | |
Siddharth Agrawal | a86e5876eb |
|
@ -36,3 +36,10 @@ Last login: Fri Jan 30 23:12:26 on ttys001
|
|||
- `cowsay` if using `chuck_cow`
|
||||
|
||||
Available via homebrew, apt, ...
|
||||
|
||||
> [!NOTE]
|
||||
> In addition to installing `fortune`, it may be necessary to run:
|
||||
>
|
||||
> `strfile $ZSH/plugins/chucknorris/fortunes/chucknorris\n`
|
||||
>
|
||||
> (include the "\n" literally) to write the fortune data to the proper directory.
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
# CircleCi Plugin
|
||||
|
||||
This plugin provides easy to use cli commands to query circle ci job statuses
|
||||
|
||||
To use it, add `circleci` to the plugins array in your zshrc file:
|
||||
|
||||
```zsh
|
||||
plugins=(... circleci)
|
||||
```
|
||||
|
||||
## Prerequisites
|
||||
You need to have the `CIRCLECI_API_TOKEN` and `CIRCLECI_ORG_SLUG` as environment
|
||||
variables before calling the `circleci_status` function <br>
|
||||
You can learn how to add a circleci api token [here](https://circleci.com/docs/managing-api-tokens/) <br>
|
||||
The org slug takes the format of `{vcs}/{org_name}`
|
||||
|
||||
## Usage
|
||||
```shell
|
||||
> circleci_status
|
||||
```
|
||||
The above command would list down all the jobs (with their run status) on the
|
||||
repository and branch that you are currently on <br>
|
||||
You can also use the `cis` alias to run the above function
|
|
@ -0,0 +1,12 @@
|
|||
# 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}"
|
||||
__CI_ZSH_DIR="${0:h:A}"
|
||||
|
||||
alias cis='circleci_status'
|
||||
|
||||
|
||||
function circleci_status() {
|
||||
python3 "$__CI_ZSH_DIR"/circleci_status.py "$(git_current_branch)" "$(git_repo_name)" | less
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import requests
|
||||
import os
|
||||
import sys
|
||||
|
||||
CIRCLECI_API = "https://circleci.com/api/v2"
|
||||
org_slug = os.environ.get("CIRCLECI_ORG_SLUG")
|
||||
args = sys.argv
|
||||
|
||||
|
||||
class COLORS:
|
||||
reset = '\033[0m'
|
||||
|
||||
class FG:
|
||||
red = '\033[31m'
|
||||
green = '\033[32m'
|
||||
yellow = '\033[93m'
|
||||
|
||||
|
||||
def get_resp_items(resp):
|
||||
if resp.status_code != 200:
|
||||
sys.exit(0)
|
||||
items = resp.json()["items"]
|
||||
if len(items) == 0:
|
||||
sys.exit(0)
|
||||
return items
|
||||
|
||||
|
||||
def get_status_text(status):
|
||||
if status == "success":
|
||||
return COLORS.FG.green + "✓" + COLORS.reset
|
||||
elif status in ("running", "not_run", "retried"):
|
||||
return COLORS.FG.yellow + "•" + COLORS.reset
|
||||
else:
|
||||
return COLORS.FG.red + "✗" + COLORS.reset
|
||||
|
||||
|
||||
if not org_slug or len(args) != 3:
|
||||
sys.exit(0)
|
||||
|
||||
branch_name = args[1]
|
||||
repo_name = args[2]
|
||||
|
||||
# Here we query for all the pipelines belonging to the current branch in the current repo
|
||||
headers = {"Circle-token": os.environ.get("CIRCLECI_API_TOKEN")}
|
||||
url = f"{CIRCLECI_API}/project/{org_slug}/{repo_name}/pipeline"
|
||||
params = {"branch": branch_name}
|
||||
response = requests.get(url, headers=headers, params=params)
|
||||
pipelines = get_resp_items(response)
|
||||
# use the latest pipeline
|
||||
pipeline_id = pipelines[0]["id"]
|
||||
|
||||
# Now fetch the workflows for the selected pipeline
|
||||
url = f"{CIRCLECI_API}/pipeline/{pipeline_id}/workflow"
|
||||
response = requests.get(url, headers=headers)
|
||||
workflows = get_resp_items(response)
|
||||
# use the latest workflow
|
||||
workflow_id = workflows[0]["id"]
|
||||
|
||||
url = f"{CIRCLECI_API}/workflow/{workflow_id}/job"
|
||||
response = requests.get(url, headers=headers)
|
||||
jobs = get_resp_items(response)
|
||||
|
||||
for job in jobs:
|
||||
status = job["status"]
|
||||
if status in ("success", "running", "failed", "retried", "timedout",
|
||||
"on_hold", "canceled", "terminated_unknown"):
|
||||
name = job["name"]
|
||||
project_slug = job["project_slug"]
|
||||
job_number = job["job_number"]
|
||||
url = f"https://circleci.com/{project_slug}/{job_number}"
|
||||
print("{} {:<50} {}".format(get_status_text(status), name, url))
|
|
@ -8,10 +8,16 @@ To use it, add `perl` to the plugins array in your zshrc file:
|
|||
plugins=(... perl)
|
||||
```
|
||||
|
||||
## Perlbrew activation
|
||||
|
||||
If the plugin detects that `perlbrew` hasn't been activated, yet there is an installation of it in
|
||||
`$PERLBREW_ROOT`, it'll initialize by default. To avoid this behaviour, set `ZSH_PERLBREW_ACTIVATE=false`
|
||||
before `source oh-my-zsh.sh` in your zshrc.
|
||||
|
||||
## Aliases
|
||||
|
||||
| Aliases | Command | Description |
|
||||
| :------------ | :----------------- | :------------------------------------- |
|
||||
| :---------- | :----------------- | :------------------------------------- |
|
||||
| pbi | `perlbrew install` | Install specific perl version |
|
||||
| pbl | `perlbrew list` | List all perl version installed |
|
||||
| pbo | `perlbrew off` | Go back to the system perl |
|
||||
|
@ -23,15 +29,15 @@ plugins=(... perl)
|
|||
|
||||
## Functions
|
||||
|
||||
* `newpl`: creates a basic Perl script file and opens it with $EDITOR.
|
||||
- `newpl`: creates a basic Perl script file and opens it with $EDITOR.
|
||||
|
||||
* `pgs`: Perl Global Substitution: `pgs <find_pattern> <replace_pattern> <filename>`
|
||||
Looks for `<find_pattern>` and replaces it with `<replace_pattern>` in `<filename>`.
|
||||
- `pgs`: Perl Global Substitution: `pgs <find_pattern> <replace_pattern> <filename>` Looks for
|
||||
`<find_pattern>` and replaces it with `<replace_pattern>` in `<filename>`.
|
||||
|
||||
* `prep`: Perl grep, because 'grep -P' is terrible: `prep <pattern> [<filename>]`
|
||||
Lets you work with pipes or files (if no `<filename>` provided, use stdin).
|
||||
- `prep`: Perl grep, because 'grep -P' is terrible: `prep <pattern> [<filename>]` Lets you work with pipes or
|
||||
files (if no `<filename>` provided, use stdin).
|
||||
|
||||
## Requirements
|
||||
|
||||
In order to make this work, you will need to have perl installed.
|
||||
More info on the usage and install: https://www.perl.org/get.html
|
||||
In order to make this work, you will need to have perl installed. More info on the usage and install:
|
||||
https://www.perl.org/get.html
|
||||
|
|
|
@ -54,3 +54,12 @@ pgs() { # [find] [replace] [filename]
|
|||
prep() { # [pattern] [filename unless STDOUT]
|
||||
perl -nle 'print if /'"$1"'/;' $2
|
||||
}
|
||||
|
||||
# If the 'perlbrew' function isn't defined, perlbrew isn't setup.
|
||||
if [[ $ZSH_PERLBREW_ACTIVATE != false ]] && (( ! $+functions[perlbrew] )); then
|
||||
local _perlbrew="${PERLBREW_ROOT:-${HOME}/perl5/perlbrew}"
|
||||
if [[ -f "${_perlbrew}/etc/bashrc" ]]; then
|
||||
source "${_perlbrew}/etc/bashrc"
|
||||
fi
|
||||
unset _perlbrew
|
||||
fi
|
||||
|
|
|
@ -24,16 +24,45 @@ plugins=(... python)
|
|||
The plugin provides three utilities to manage Python 3.3+ [venv](https://docs.python.org/3/library/venv.html)
|
||||
virtual environments:
|
||||
|
||||
- `mkv [name]`: make a new virtual environment called `name` (default: if set `$PYTHON_VENV_NAME`, else
|
||||
`venv`) in the current directory.
|
||||
- `mkv [name]`: make a new virtual environment called `name` in the current directory.
|
||||
**Default**: `$PYTHON_VENV_NAME` if set, otherwise `venv`.
|
||||
|
||||
- `vrun [name]`: Activate the virtual environment called `name` (default: if set `$PYTHON_VENV_NAME`, else
|
||||
`venv`) in the current directory.
|
||||
- `vrun [name]`: activate the virtual environment called `name` in the current directory.
|
||||
**Default**: the first existing in `$PYTHON_VENV_NAMES`.
|
||||
|
||||
- `auto_vrun`: Automatically activate the venv virtual environment when entering a directory containing
|
||||
- `auto_vrun`: automatically activate the venv virtual environment when entering a directory containing
|
||||
`<venv-name>/bin/activate`, and automatically deactivate it when navigating out of it (keeps venv activated
|
||||
in subdirectories).
|
||||
- To enable the feature, set `export PYTHON_AUTO_VRUN=true` before sourcing oh-my-zsh.
|
||||
- Plugin activates first virtual environment in lexicographic order whose name begins with `<venv-name>`.
|
||||
- To enable the feature, set `PYTHON_AUTO_VRUN=true` before sourcing oh-my-zsh.
|
||||
- The plugin activates the first existing virtual environment, in order, appearing in `$PYTON_VENV_NAMES`.
|
||||
The default virtual environment name is `venv`. To use a different name, set
|
||||
`export PYTHON_VENV_NAME=<venv-name>`. For example: `export PYTHON_VENV_NAME=".venv"`
|
||||
`PYTHON_VENV_NAME=<venv-name>`. For example: `PYTHON_VENV_NAME=".venv"`
|
||||
|
||||
### Settings
|
||||
|
||||
You can set these variables in your `.zshrc` file, before Oh My Zsh is sourced.
|
||||
For example:
|
||||
|
||||
```sh
|
||||
PYTHON_VENV_NAME=".venv"
|
||||
PYTHON_VENV_NAMES=($PYTHON_VENV_NAME venv)
|
||||
...
|
||||
plugins=(... python)
|
||||
source "$ZSH/oh-my-zsh.sh"
|
||||
```
|
||||
|
||||
|
||||
## `$PYTHON_VENV_NAME`
|
||||
|
||||
**Default**: `venv`.
|
||||
|
||||
Preferred name for virtual environments, for example when creating via `mkv`.
|
||||
|
||||
## `$PYTHON_VENV_NAMES`
|
||||
|
||||
**Default**: `$PYTHON_VENV_NAME venv .venv`.
|
||||
|
||||
Array of virtual environment names to be checked, in order, by `vrun` and `auto_vrun`.
|
||||
This means these functions will load the first existing virtual environment in this list.
|
||||
Duplicate names are ignored.
|
||||
|
||||
|
|
|
@ -47,12 +47,29 @@ alias pygrep='grep -nr --include="*.py"'
|
|||
alias pyserver="python3 -m http.server"
|
||||
|
||||
|
||||
## venv utilities
|
||||
## venv settings
|
||||
: ${PYTHON_VENV_NAME:=venv}
|
||||
|
||||
# Array of possible virtual environment names to look for, in order
|
||||
# -U for removing duplicates
|
||||
typeset -gaU PYTHON_VENV_NAMES
|
||||
[[ -n "$PYTHON_VENV_NAMES" ]] || PYTHON_VENV_NAMES=($PYTHON_VENV_NAME venv .venv)
|
||||
|
||||
# Activate a the python virtual environment specified.
|
||||
# If none specified, use $PYTHON_VENV_NAME, else 'venv'.
|
||||
# If none specified, use the first existing in $PYTHON_VENV_NAMES.
|
||||
function vrun() {
|
||||
if [[ -z "$1" ]]; then
|
||||
local name
|
||||
for name in $PYTHON_VENV_NAMES; do
|
||||
local venvpath="${name:P}"
|
||||
if [[ -d "$venvpath" ]]; then
|
||||
vrun "$name"
|
||||
return $?
|
||||
fi
|
||||
done
|
||||
echo >&2 "Error: no virtual environment found in current directory"
|
||||
fi
|
||||
|
||||
local name="${1:-$PYTHON_VENV_NAME}"
|
||||
local venvpath="${name:P}"
|
||||
|
||||
|
@ -91,10 +108,11 @@ if [[ "$PYTHON_AUTO_VRUN" == "true" ]]; then
|
|||
fi
|
||||
|
||||
if [[ $PWD != ${VIRTUAL_ENV:h} ]]; then
|
||||
for _file in "${PYTHON_VENV_NAME}"*/bin/activate(N.); do
|
||||
local file
|
||||
for file in "${^PYTHON_VENV_NAMES[@]}"/bin/activate(N.); do
|
||||
# make sure we're not in a venv already
|
||||
(( $+functions[deactivate] )) && deactivate > /dev/null 2>&1
|
||||
source $_file > /dev/null 2>&1
|
||||
source $file > /dev/null 2>&1
|
||||
break
|
||||
done
|
||||
fi
|
||||
|
|
|
@ -15,4 +15,11 @@ if [[ ! -f "$ZSH_CACHE_DIR/completions/_tailscale" ]]; then
|
|||
fi
|
||||
fi
|
||||
|
||||
# If using the alias, let's make sure that the aliased executable is also bound
|
||||
# in case the alias points to "Tailscale" instead of "tailscale".
|
||||
# See https://github.com/ohmyzsh/ohmyzsh/discussions/12928
|
||||
if (( $+aliases[tailscale] )); then
|
||||
_comps[${aliases[tailscale]:t}]=_tailscale
|
||||
fi
|
||||
|
||||
tailscale completion zsh >| "$ZSH_CACHE_DIR/completions/_tailscale" &|
|
||||
|
|
Loading…
Reference in New Issue