[v1.0.0] Big release! :)
This commit is contained in:
parent
c6ddebe301
commit
a9f2fe51ad
29
.env.zsh
Normal file
29
.env.zsh
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#####################################################################
|
||||||
|
# code-activator artifact #
|
||||||
|
#####################################################################
|
||||||
|
# #
|
||||||
|
# Variables and functions set in this file will be sourced when #
|
||||||
|
# this project is activated #
|
||||||
|
# #
|
||||||
|
# #
|
||||||
|
# Using the following syntax: #
|
||||||
|
# ``` #
|
||||||
|
# __RESTORE__ENV_VAR='new-value' #
|
||||||
|
# ``` #
|
||||||
|
# will save the current value of $ENV_VAR then assign ENV_VAR to #
|
||||||
|
# the 'new-value'. When code-activator calls deactivate, ENV_VAR #
|
||||||
|
# will be reset to its original value. #
|
||||||
|
# #
|
||||||
|
# this only works with VARIABLES (not functions) #
|
||||||
|
# #
|
||||||
|
# #
|
||||||
|
# #
|
||||||
|
# all other variables / functions will simply be unset whenever: #
|
||||||
|
# - deactivate is called #
|
||||||
|
# - another project is activated #
|
||||||
|
# #
|
||||||
|
#####################################################################
|
||||||
|
|
||||||
|
export __RESTORE__PATH="$PATH"
|
||||||
|
|
||||||
|
export MY_EXAMPLE_VARIABLE=69
|
69
README.md
69
README.md
@ -1,65 +1,44 @@
|
|||||||
# Code Activator
|
# Code Activator
|
||||||
##### *A `zsh` utility for terminal-based project navigation*
|
##### *A `zsh` utility for terminal-based project navigation*
|
||||||
[![Generic badge](https://img.shields.io/badge/junegunn-fzf-blueviolet.svg)](https://github.com/junegunn/fzf)
|
[![Generic badge](https://img.shields.io/badge/junegunn-fzf-blueviolet.svg)](https://github.com/junegunn/fzf)
|
||||||
|
[![Generic badge](https://img.shields.io/badge/stedolan-jq-blueviolet.svg)](https://github.com/jq/)
|
||||||
|
|
||||||
The `CODE_ACTIVATOR` function facilitates terminal-based project navigation by providing an interactive, fuzzy-search CLI.
|
Code Activator provides fast project navigation in the terminal through both an API and CLI.
|
||||||
|
|
||||||
Generally, the CLI will activate a project's virtual environment then step into the project root.
|
|
||||||
Once inside a project, the CLI gives the option to deactivate and return to the user's home directory.
|
|
||||||
|
|
||||||
Projects can also be quickly cloned or created from scratch by using the `clone` and `new` operations respectively.
|
|
||||||
|
|
||||||
Use the plugin one of three ways:
|
|
||||||
1. Use the shortcut combination (`CTRL+SPACE` by default)
|
|
||||||
1. Use the alias (`lkj` by default)
|
|
||||||
1. Call `CODE_ACTIVATOR` directly (meant for use as an API)
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
See our [contributing guide](./docs/CONTRIBUTING.md) and [code of conduct](./docs/CODE_OF_CONDUCT.md).
|
See our [contributing guide](./docs/CONTRIBUTING.md) and [code of conduct](./docs/CODE_OF_CONDUCT.md).
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
1. install [junegunn/fzf](https://github.com/junegunn/fzf)
|
1. install dependencies [junegunn/fzf](https://github.com/junegunn/fzf) and [stedolan/jq](https://github.com/stedolan/jq)
|
||||||
1. clone this repo, and source the `*.plugin.zsh` in your `zshrc`:
|
1. clone this repo, and source the `activator.plugin.zsh` in your `zshrc`:
|
||||||
```shell
|
```shell
|
||||||
# replace <path-to>/code-activator with the appropriate path
|
# replace <path-to>/code-activator with the appropriate path
|
||||||
git clone https://github.com/w0ryn/code-activator-zsh.git <path-to>/code-activator
|
git clone https://github.com/w0ryn/code-activator-zsh.git <path-to>/code-activator
|
||||||
echo 'source <path-to>/code-activator' >> $HOME/.zshrc
|
echo 'source <path-to>/code-activator' >> $HOME/.zshrc
|
||||||
```
|
```
|
||||||
|
|
||||||
## Configuration
|
By default, Code Activator looks for projects in `~/Projects/GitHub` and `~/Projects/BitBucket`, but you can configure\* this in your `~/.config/code-activator-zsh/settings.zsh`.
|
||||||
All configuration options are determined by their respective environment variables.
|
It is highly recommended that, if nothing else, you configure `CA__DIRS` to group your projects as you please.
|
||||||
|
|
||||||
### Basic Configuration
|
<sup>\**the configuration file is created the first time Code Activator is sourced*</sup>
|
||||||
Environment Variable | Default | Description
|
|
||||||
---------------------------------- | ------------------------------- | -----------
|
|
||||||
`CODE_ACTIVATOR__SHORTCUT` | `^@` (a.k.a. CTRL+SPACE) | shortcut for running `CODE_ACTIVATOR` as a plugin
|
|
||||||
`CODE_ACTIVATOR__DISABLE_SHORTCUT` | `0` (a.k.a. false) | whether (or not) the shortcut runner is disabled
|
|
||||||
`CODE_ACTIVATOR__ALIAS` | `lkj` | easy-to-type alias for running `CODE_ACTIVATOR`
|
|
||||||
`CODE_ACTIVATOR__DISABLE_ALIAS` | `0` (a.k.a. false) | whether (or not) the alias runner is disabled
|
|
||||||
|
|
||||||
### Project Directories
|
|
||||||
- `CODE_ACTIVATOR__DIRS` (list) environment variable
|
|
||||||
|
|
||||||
A list of fully-qualified paths to project parent directories.
|
## Usage
|
||||||
Provides `($HOME/Code)` as a generic default, but allows for meaningful project grouping:
|
Code Activator commands can be invoked one of three ways:
|
||||||
```shell
|
1. directly (`code-activator`; intended for use as an API)
|
||||||
export CODE_ACTIVATOR__DIRS=(
|
2. through an alias (`lkj` by default)
|
||||||
"$HOME/Company/Team1"
|
3. through a shortcut (`CTRL+SPACE` by default; creates a zsh-plugin)
|
||||||
"$HOME/Company/Team2"
|
|
||||||
"$HOME/Miscellaneous"
|
|
||||||
"$HOME/Personal"
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
### Known Targets
|
With no argument, Code Activator provides a list of all available projects.
|
||||||
- `CODE_ACTIVATOR__KNOWN_TARGETS` (list) environment variable
|
Select one to activate it's environment and jump to the project's root.
|
||||||
- expects targets to end in `:` or `/` character
|
|
||||||
- *appends environment variable list to the default list*
|
If your first argument to Code Activator is a project name, the specified project will be activated.
|
||||||
|
|
||||||
|
You can also `deactivate` an activated project, `clone` an existing project, or create a `new` project (with the appropriate command).
|
||||||
|
|
||||||
|
|
||||||
|
## Custom Environment
|
||||||
|
Although not exactly a virtual environment, Code Activator creates a `custom-env` for projects where you can set project-specific environment variables or shell functions.
|
||||||
|
It also provides a `__RESTORE__` syntax to allow safe manipulation of `PATH` or other variables when activating a project.
|
||||||
|
See [the custom-env template](./.env.zsh) for more details.
|
||||||
|
|
||||||
A list of default completion targets for setting up or cloning new repositories.
|
|
||||||
Includes HTTP and GIT protocol targets for GitHub and BitBucket by default, but you may want to add your user to the list:
|
|
||||||
```shell
|
|
||||||
export CODE_ACTIVATOR__KNOWN_TARGETS=(
|
|
||||||
'git@github.com:<your-username>/'
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
23
activator.bindings.zsh
Normal file
23
activator.bindings.zsh
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#####################################################################
|
||||||
|
|
||||||
|
[[ $CA__DISABLE_ALIAS -eq 0 ]] && {
|
||||||
|
alias $CA__ALIAS='code-activator'
|
||||||
|
}
|
||||||
|
|
||||||
|
#####################################################################
|
||||||
|
|
||||||
|
[[ $CA__DISABLE_SHORTCUT -eq 0 ]] && command -v zle >/dev/null 2>&1 \
|
||||||
|
|| return 0
|
||||||
|
|
||||||
|
_CA__ZSH_SHORTCUT_PLUGIN() {
|
||||||
|
local OPTIONS=(clone new $(_CA_LIST))
|
||||||
|
[ $_CA_ENV ] && OPTIONS=(deactivate $OPTIONS)
|
||||||
|
|
||||||
|
local SELECTION=$(echo $OPTIONS | _CA_MULTILINE | _CA_FZF 'select a project')
|
||||||
|
[[ $SELECTION =~ . ]] && code-activator $SELECTION
|
||||||
|
echo
|
||||||
|
zle reset-prompt
|
||||||
|
}
|
||||||
|
|
||||||
|
zle -N codeactivator _CA__ZSH_SHORTCUT_PLUGIN
|
||||||
|
bindkey $CA__SHORTCUT codeactivator
|
40
activator.completion.zsh
Normal file
40
activator.completion.zsh
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#####################################################################
|
||||||
|
command -v compdef >/dev/null 2>&1 || return 0
|
||||||
|
#####################################################################
|
||||||
|
|
||||||
|
_CA__PROJECT_COMPADD() {
|
||||||
|
local DESCRIPTIONS=()
|
||||||
|
|
||||||
|
[ $_CA_ENV ] && DESCRIPTIONS+='deactivate:deactivate env and jump to $HOME'
|
||||||
|
DESCRIPTIONS+='clone:clone a project from a known target'
|
||||||
|
DESCRIPTIONS+='new:create a new project'
|
||||||
|
|
||||||
|
_describe 'commands' DESCRIPTIONS
|
||||||
|
|
||||||
|
compadd -- $(_CA_LIST)
|
||||||
|
}
|
||||||
|
|
||||||
|
#####################################################################
|
||||||
|
|
||||||
|
_code-activator() {
|
||||||
|
local state
|
||||||
|
|
||||||
|
_arguments \
|
||||||
|
'1: :->project' \
|
||||||
|
'2: :->arg1' \
|
||||||
|
;
|
||||||
|
|
||||||
|
case $state in
|
||||||
|
project ) _CA__PROJECT_COMPADD ;;
|
||||||
|
arg1 )
|
||||||
|
case $words[2] in
|
||||||
|
clone )
|
||||||
|
echo; echo 'where should I clone this?'
|
||||||
|
compadd -- $CA__DIRS
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
compdef _code-activator code-activator
|
@ -1,131 +1,40 @@
|
|||||||
#!/bin/zsh
|
#!/bin/zsh
|
||||||
#####################################################################
|
###################################################################
|
||||||
# #
|
# #
|
||||||
# CODE_ACTIVATOR : a terminal-based navigation utility #
|
# code-activator() : a terminal-based navigation utility #
|
||||||
# #
|
# #
|
||||||
#####################################################################
|
###################################################################
|
||||||
|
|
||||||
DEPENDENCIES=(
|
_CA__VERSION=1.0.0
|
||||||
fzf
|
_CA__DEPENDENCIES=(code-activator fzf jq git)
|
||||||
)
|
|
||||||
|
|
||||||
IMPORTS=(
|
|
||||||
"${0:a:h}/zsh/settings.zsh"
|
|
||||||
"${0:a:h}/zsh/helpers.zsh"
|
|
||||||
"${0:a:h}/zsh/clone.zsh"
|
|
||||||
"${0:a:h}/zsh/activate.zsh"
|
|
||||||
)
|
|
||||||
|
|
||||||
#####################################################################
|
#####################################################################
|
||||||
|
|
||||||
for DEPENDENCY in $DEPENDENCIES
|
export _CA=${0:a:h}
|
||||||
do
|
|
||||||
command -v $DEPENDENCY >/dev/null 2>&1 || {
|
source $_CA/global.zsh || return 1
|
||||||
echo "I require '$DEPENDENCY' but it's not installed :c"
|
source $_CA/config.zsh || return 1
|
||||||
ERROR_CODE=1
|
|
||||||
}
|
for Z in $(ls $_CA/zsh/*); do source $Z || return 1; done
|
||||||
done
|
|
||||||
|
|
||||||
#####################################################################
|
#####################################################################
|
||||||
|
|
||||||
for IMPORT in $IMPORTS; do source $IMPORT; done
|
code-activator() {
|
||||||
|
_CA__CHECK_DEPENDENCIES $_CA__DEPENDENCIES || return 1
|
||||||
|
|
||||||
[ ! $_CA__ACTIVATE_LOADED ] && ERROR_CODE=2
|
local COMMAND ARGS
|
||||||
[ ! $_CA__CLONE_LOADED ] && ERROR_CODE=2
|
|
||||||
|
|
||||||
#####################################################################
|
|
||||||
|
|
||||||
[ $ERROR_CODE ] && return $ERROR_CODE
|
|
||||||
|
|
||||||
#####################################################################
|
|
||||||
#####################################################################
|
|
||||||
|
|
||||||
CODE_ACTIVATOR() {
|
|
||||||
local ERROR=0
|
|
||||||
|
|
||||||
case $1 in
|
case $1 in
|
||||||
deactivate ) _CA__RESTORE_ENVIRONMENT && cd || ERROR=1 ;;
|
deactivate ) COMMAND=DEACTIVATE ;;
|
||||||
|
|
||||||
clone ) _CA__CLONE ${@:2} || ERROR=1 ;;
|
clone ) COMMAND=CLONE; ARGS=(${@:2}) ;;
|
||||||
new ) IS_NEW_PROJECT=1 _CA__CLONE ${@:2} || ERROR=1 ;;
|
new ) COMMAND=NEW; ARGS=(${@:2}) ;;
|
||||||
* ) _CA__ACTIVATE ${@:1} || ERROR=42 ;;
|
|
||||||
|
* ) COMMAND=ACTIVATE; ARGS=(${@:1}) ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
[[ $ERROR -ne 0 ]] && _CA__ERROR_CLEANUP $ERROR
|
_CA_$COMMAND $ARGS
|
||||||
|
|
||||||
return $ERROR
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_CODE_ACTIVATOR() {
|
source $_CA/activator.completion.zsh
|
||||||
local state
|
source $_CA/activator.bindings.zsh
|
||||||
|
|
||||||
_arguments \
|
|
||||||
'1: :->project' \
|
|
||||||
':: :->arguments' \
|
|
||||||
;
|
|
||||||
|
|
||||||
case $state in
|
|
||||||
project )
|
|
||||||
compadd $(_CA__GET_COMMANDS_AND_PROJECTS | sed 's/deactivate//')
|
|
||||||
;;
|
|
||||||
arguments )
|
|
||||||
case $words[2] in
|
|
||||||
clone ) __CA__CLONE ;;
|
|
||||||
esac
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
compdef _CODE_ACTIVATOR CODE_ACTIVATOR
|
|
||||||
|
|
||||||
#####################################################################
|
|
||||||
|
|
||||||
_CA__GET_COMMANDS_AND_PROJECTS() {
|
|
||||||
local COMMANDS=(deactivate clone new)
|
|
||||||
local PROJECTS=()
|
|
||||||
|
|
||||||
for base_dir in $CODE_ACTIVATOR__DIRS
|
|
||||||
do
|
|
||||||
for project_dir in $(ls -d -- $base_dir/*)
|
|
||||||
do
|
|
||||||
PROJECTS+=("$(basename $base_dir)/$(basename $project_dir)")
|
|
||||||
done
|
|
||||||
done
|
|
||||||
|
|
||||||
echo $COMMANDS $PROJECTS
|
|
||||||
}
|
|
||||||
|
|
||||||
_CA__ERROR_CLEANUP() {
|
|
||||||
local ERROR="$1"
|
|
||||||
[ $_CA__SUPPRESS_ERROR ] && return
|
|
||||||
case $ERROR in
|
|
||||||
42 )
|
|
||||||
echo 'failed to activate environment; aborting' >&2
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
#####################################################################
|
|
||||||
|
|
||||||
[[ $CODE_ACTIVATOR__DISABLE_SHORTCUT -eq 0 ]] && {
|
|
||||||
_CA__ZSH_SHORTCUT_PLUGIN() {
|
|
||||||
local OPTIONS=$(_CA__GET_COMMANDS_AND_PROJECTS | _CA__SED_MULTILINE)
|
|
||||||
[ ! $__CUSTOM_ENV_ACTIVE ] && OPTIONS=$(echo $OPTIONS | grep -v 'deactivate')
|
|
||||||
|
|
||||||
local ARGUMENT=$(\
|
|
||||||
echo $OPTIONS \
|
|
||||||
| _CA__SED_MULTILINE \
|
|
||||||
| $_CA__FZF --prompt 'select a project: ' \
|
|
||||||
)
|
|
||||||
|
|
||||||
_CA__IN_ZSH_PLUGIN=1 CODE_ACTIVATOR $ARGUMENT
|
|
||||||
|
|
||||||
echo
|
|
||||||
zle reset-prompt
|
|
||||||
}
|
|
||||||
zle -N codeactivator _CA__ZSH_SHORTCUT_PLUGIN
|
|
||||||
bindkey $CODE_ACTIVATOR__SHORTCUT codeactivator
|
|
||||||
}
|
|
||||||
|
|
||||||
[[ $CODE_ACTIVATOR__DISABLE_ALIAS -eq 0 ]] && {
|
|
||||||
alias $CODE_ACTIVATOR__ALIAS='CODE_ACTIVATOR'
|
|
||||||
}
|
|
||||||
|
67
config.zsh
Normal file
67
config.zsh
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
# cloned projects will be nested under the specified directories,
|
||||||
|
# allowing for meaningful project grouping. A friendly name is
|
||||||
|
# derived from the path
|
||||||
|
#
|
||||||
|
# e.g. "$HOME/Projects/GitHub" will be called "GitHub" in the CLI
|
||||||
|
#
|
||||||
|
# directories must be fully-qualified
|
||||||
|
CA__DIRS=(
|
||||||
|
"$HOME/Projects/GitHub"
|
||||||
|
"$HOME/Projects/BitBucket"
|
||||||
|
)
|
||||||
|
|
||||||
|
# additional cloning targets; MUST END IN ':' or '/'
|
||||||
|
# e.g. 'git@my.githost.com:' or 'git@github.com:w0ryn/'
|
||||||
|
CA__KNOWN_TARGETS=(
|
||||||
|
'https://github.com/'
|
||||||
|
'https://bitbucket.org/'
|
||||||
|
'git@github.com:'
|
||||||
|
'git@bitbucket.org:'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# run from the specified hot-key
|
||||||
|
CA__SHORTCUT=' |