Skip to content

timbertson/bash-cached-completions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

An easy way to generate a set of bash completion words. Word sets are cached, and generated in the background (so your terminal doesn't hang).

The config is all written in python, because python is ace. Every set of words is tied to the cache_key you generate - if you return the same cache_key, the completion will re-use the same set of words. If completion depends on existing arguments, you will need to factor that into your cache_key generation. Cache_keys need to be valid filenames, so b32encode can be useful.

Example setup: To enable completions for "my-command":


~/.config/bashcomplete/my-command.py:

max_age = 5 * 60 # 5 minutes

def cache_key(command, args):
	import os
	import base64
	return base64.b32encode(os.getcwd())

def get_words(command, args):
	import time
	time.sleep(2) # won't lock bash
	return ['aaa','bbbb','cccc', 'ccdd']

~/.bashrc:

export PATH="$PATH:/path/to/bashcomplete"
. /path/to/bashcomplete/init

(Or, if you're using 0install) :


~/.bashrc:

. $(0launch -c http://gfxmonk.net/dist/0install/bashcomplete.xml __init)

About

a configurable mecahnism for generating (and caching) bash completion words for arbitrary commands

Resources

Stars

Watchers

Forks

Packages

No packages published