Skip to content

Commit

Permalink
Merge pull request #21 from real-digital/improve-autocompletion-init
Browse files Browse the repository at this point in the history
Adds automatic autocompletion installation
  • Loading branch information
hfjn committed Jul 5, 2019
2 parents 3553e71 + 22373da commit 5b194d9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 13 deletions.
10 changes: 1 addition & 9 deletions .pre-commit-config.yaml
Expand Up @@ -12,12 +12,4 @@ repos:
- id: check-merge-conflict
- id: check-yaml
- id: trailing-whitespace
exclude: .*\.md$
- repo: local
hooks:
- id: shell-lint
name: Shell Syntax Check
description: Check Shell Syntax on ALL staged files with user friendly messages and colors
entry: .pre-commit-hooks/shell-lint.sh
language: script
types: [shell]
exclude: .*\.md$
11 changes: 7 additions & 4 deletions README.md
Expand Up @@ -29,20 +29,23 @@ This is partly (but not only) due to a fragmented and unclear definition of tool

`esque` is available at pypi.org and can be installed with `pip install esque`. `esque` requires Python 3.6+ to run.

### Enable Autocompletion
### Autocompletion

`esque` uses Magic Environment Variables to provide autocompletion to you. You can enable autocompletion by adding the one of the following snippets to your `.bashrc`/`.zshrc`
Autocompletion is automatically installed via a post-install hook in the setup.py.
If it doesn't work for some reason you can still install it yourself:

#### Bash

```
eval "$(_ESQUE_COMPLETE=source esque)"
echo 'eval "$(_ESQUE_COMPLETE=source esque)"' >> ~/.esque/autocompletion.sh
echo "source ~/.esque/autocompletion.sh" >> ~/.bashrc
```

#### ZSH

```
eval "$(_ESQUE_COMPLETE=source_zsh esque)"
echo 'eval "$(_ESQUE_COMPLETE=source_zsh esque)"' >> ~/.esque/autocompletion.zsh
echo "source ~/.esque/autocompletion.zsh" >> ~/.zshrc
```

### Usage
Expand Down
32 changes: 32 additions & 0 deletions auto_completion.sh
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
# Inspired by: https://qone.io/python/bash/zsh/2016/04/24/python-click-auto-complete-bash-zsh.html

mkdir -p "~/.esque"

if [[ $(basename $SHELL) = 'bash' ]];
then
if [[ -f ~/.bashrc ]];
then
echo "Installing bash autocompletion..."
grep -q 'esque-autocompletion' ~/.bashrc
if [[ $? -ne 0 ]]; then
echo "" >> ~/.bashrc
echo "Added by esque" >> ~/.bashrc
echo 'eval "$(_ESQUE_COMPLETE=source esque)"' >> ~/.esque/autocompletion.sh
echo "source ~/.esque/autocompletion.sh" >> ~/.bashrc
fi
fi
elif [[ $(basename $SHELL) = 'zsh' ]];
then
if [[ -f ~/.zshrc ]];
then
echo "Installing zsh autocompletion..."
grep -q 'esque-autocompletion' ~/.zshrc
if [[ $? -ne 0 ]]; then
echo "" >> ~/.zshrc
echo "# Added by esque" >> ~/.zshrc
echo 'eval "$(_ESQUE_COMPLETE=source_zsh esque)"' >> ~/.esque/autocompletion.zsh
echo "source ~/.esque/autocompletion.zsh" >> ~/.zshrc
fi
fi
fi
13 changes: 13 additions & 0 deletions setup.py
Expand Up @@ -3,8 +3,10 @@
import codecs
import os
import sys
from subprocess import call

from setuptools import find_packages, setup
from setuptools.command.install import install

here = os.path.abspath(os.path.dirname(__file__))

Expand All @@ -31,6 +33,16 @@
"pyyaml",
]


class InstallWithPostCommand(install):
"""Post-installation for installation mode."""

def run(self):
install.run(self)
print("installing auto completion")
call(["./auto_completion.sh"])


setup(
name="esque",
version=about["__version__"],
Expand Down Expand Up @@ -61,4 +73,5 @@
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
],
cmdclass={"install": InstallWithPostCommand},
)

0 comments on commit 5b194d9

Please sign in to comment.