Commits (3)
# tako-plugins
This repository contains a collection of plugins for the tako shell (https://takoshell.org)
* [Bookmark](#Bookmark) (mark and quickly move between directories)
* [Frecency](#Frecency) (better suggestions for misspelled commands, and a clone of `z`)
* [Van](#Van) (virtual environment management)
## Bookmark
Adds the `bmark` and `bgo` aliases. `bmark` can be used to quickly mark a
location, and `bgo` can be used to return to that location:
~ $ cd some/very/deeply/nested/structure
~/s/v/d/n/structure $ # oh shoot i forgot i wanted to go someplace else
~/s/v/d/n/structure $ bmark # remember this location
~/s/v/d/n/structure $ cd ~/someplace/else/entirely
~/s/e/entirely $ touch foo # do some work
~/s/e/entirely $ bgo # quickly jump back to the marked location
~/s/v/d/n/structure $ # i didn't have to navigate here by hand! hooray!
`bmark NAME` associates the current directory with a name, and then `bgo NAME`
can be used to jump back to it.
Currently, bookmarks do not persist across sessions.
## Frecency
Overrides the built-in suggestions for misspelled commands with new ones based
on frecency (prioritizing commands that you use often, and ones you've used
Also adds the `tj` ("takojump") command, which is a clone of `z`, for moving
between directories based on frecency.
## Van
Adds the `van` alias for activating/deactivating virtual environments.
......@@ -9,6 +9,7 @@ import time
import builtins
import takoshell.tools
import takoshell.dirstack
from collections import OrderedDict
from argparse import ArgumentParser, REMAINDER
......@@ -149,7 +150,7 @@ def takojump(args, stdin=None):
elif args.echo:
return the_entry[1]
return None, None, 0
from os import scandir
from os.path import isdir, join, sep, abspath, basename, expanduser
def _virtualenv_activate(args, stdin=None):
Activates an environment.
Requires the environment name as single argument,
will look into $HOME/.virtualenvs .
# if we are already in a venv, we need to undo that.
if PLUGIN_SETTINGS._venv is not None:
_virtualenv_deactivate([], stdin)
This needs to handle arguments in a smarter way,
1. default virtualenvs PATH (possibly from environment)
1. named directory in cwd
1. relative path names starting with dot
The distinction is between paths and generic names.
Paths are split into absolute paths, matched as they are, and relative
paths that are only matched in cwd.
Names are matched in virtualenvs first, then in cwd as relative paths.
# Try the default virtualenv PATH, ~/.virtualenvs
env = join(expanduser('~'), '.virtualenvs', args[0])
if not isdir(env):
return '', 'Not a valid virtualenv\n', 1
if env.endswith(sep):
env = env[:-1]
# store the things we need to be able to restore
PLUGIN_SETTINGS._venv_old_prompt = $TAKO_SETTINGS.prompt
PLUGIN_SETTINGS._venv_old_path = list($PATH)
PLUGIN_SETTINGS._venv = abspath(env)
# mangle the prompt
$TAKO_SETTINGS.prompt = '{BOLD_YELLOW}(%s){NO_COLOR} %s' % (basename(env),
# set up the path
$PATH.insert(0, join(abspath(env), 'bin'))
if 'PYTHONHOME' in ${...}:
PLUGIN_SETTINGS._venv_old_pythonhome = $PYTHONHOME
PLUGIN_SETTINGS._venv_old_pythonhome = None
def _virtualenv_deactivate(args, stdin=None):
Deactivates the active environment.
if PLUGIN_SETTINGS._venv is None:
$TAKO_SETTINGS.prompt = PLUGIN_SETTINGS._venv_old_prompt
$PATH = PLUGIN_SETTINGS._venv_old_path
if PLUGIN_SETTINGS._venv_old_pythonhome is not None:
$PYTHONHOME = PLUGIN_SETTINGS._venv_old_pythonhome
def _virtualenv_list():
List available environments
print("Available environments:")
for entry in scandir(join(expanduser('~'), '.virtualenvs/')):
if entry.is_dir():
print(" %s" % entry.name)
def _van(args, stdin=None):
Very simple single command implementation.
A food van will:
open activating an existing virtualenv
close deactivating the active one
menu list available stuff
command = args[0]
if command == 'open':
_virtualenv_activate(args[1:], stdin)
elif command == 'close':
_virtualenv_deactivate([], stdin)
elif command == 'menu':
except IndexError:
print("""Usage:\n\tvan [open {virtualenv name}| close | menu]""")
# We are not initially in a venv
PLUGIN_SETTINGS.aliases['van'] = _van