4cadbcd23503e3aa1f29008b6748c82bd308dce6

Author
Alan <alan@gangleri.net>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

Add plugin for pipenv (#6698)

- Add completion for pipenv
- Auto activate and deactivate for pipenv shell
- Add aliases for the most common pipenv commands

Diff

 1diff --git a/plugins/pipenv/README.md b/plugins/pipenv/README.md
 2new file mode 100644
 3index 0000000000000000000000000000000000000000..ab1c1e442b0b6d190977938246d9bb59926ff7af
 4--- /dev/null
 5+++ b/plugins/pipenv/README.md
 6@@ -0,0 +1,28 @@
 7+# Pipenv
 8+
 9+## Installation
10+In your `.zshrc` file, add `pipenv` to the plugins section
11+
12+```
13+plugins=(... pipenv ...)
14+```
15+
16+## Features
17+This plugin provides some features to simplify the use of Pipenv while working on ZSH. 
18+- Adds completion for pipenv
19+- Auto activates and deactivates pipenv shell
20+- Adds short aliases for common pipenv commands
21+  - `pch` is aliased to `pipenv check`
22+  - `pcl` is aliased to `pipenv clean`
23+  - `pgr` is aliased to `pipenv graph`
24+  - `pi` is aliased to `pipenv install`
25+  - `pidev` is aliased to `pipenv install --dev`
26+  - `pl` is aliased to `pipenv lock`
27+  - `po` is aliased to `pipenv open`
28+  - `prun` is aliased to `pipenv run`
29+  - `psh` is aliased to `pipenv shell`
30+  - `psy` is aliased to `pipenv sync`
31+  - `pu` is aliased to `pipenv uninstall`
32+  - `pwh` is aliased to `pipenv --where`
33+  - `pvenv` is aliased to `pipenv --venv`
34+  - `ppy` is aliased to `pipenv --py`
35diff --git a/plugins/pipenv/pipenv.plugin.zsh b/plugins/pipenv/pipenv.plugin.zsh
36new file mode 100644
37index 0000000000000000000000000000000000000000..0a5dc56a42b5424ba1b4b52f75cdc7d0a903cd37
38--- /dev/null
39+++ b/plugins/pipenv/pipenv.plugin.zsh
40@@ -0,0 +1,42 @@
41+# Pipenv completion
42+_pipenv() {
43+  eval $(env COMMANDLINE="${words[1,$CURRENT]}" _PIPENV_COMPLETE=complete-zsh  pipenv)
44+}
45+compdef _pipenv pipenv
46+
47+# Automatic pipenv shell activation/deactivation
48+_togglePipenvShell() {
49+  # deactivate shell if Pipfile doesn't exist and not in a subdir
50+  if [[ ! -a "$PWD/Pipfile" ]]; then
51+    if [[ "$PIPENV_ACTIVE" == 1 ]]; then
52+      if [[ "$PWD" != "$pipfile_dir"* ]]; then
53+        exit
54+      fi
55+    fi
56+  fi
57+
58+  # activate the shell if Pipfile exists
59+  if [[ "$PIPENV_ACTIVE" != 1 ]]; then
60+    if [[ -a "$PWD/Pipfile" ]]; then
61+      export pipfile_dir="$PWD"
62+      pipenv shell
63+    fi
64+  fi
65+}
66+chpwd_functions+=(_togglePipenvShell)
67+
68+# Aliases
69+alias pch="pipenv check"
70+alias pcl="pipenv clean"
71+alias pgr="pipenv graph"
72+alias pi="pipenv install"
73+alias pidev="pipenv install --dev"
74+alias pl="pipenv lock"
75+alias po="pipenv open"
76+alias prun="pipenv run"
77+alias psh="pipenv shell"
78+alias psy="pipenv sync"
79+alias pu="pipenv uninstall"
80+alias pwh="pipenv --where"
81+alias pvenv="pipenv --venv"
82+alias ppy="pipenv --py"