Skip to content

madlambda/nashcomplete

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nashcomplete

The name says everything.

Installation

First clone the repository:

λ> mkdir -p $NASHPATH+"/lib"
λ> cd $NASHPATH+"/lib"
λ> git clone git@github.com:madlambda/nashcomplete.git

To setup the auto complete you only need to add an import line into your init script.

# ~/.nash/init

import nashcomplete/all

Done.

Adding your own completions

There's a way to add your own completion to some command: Nashcomplete looks for a list of completion callbacks, that you can extend with your own completions.

The example below adds a simple completion for docker subcommands.

# my completes
# ~/.nash/conf/complete

import "nashcomplete/all"

# The `parts` argument hold the line splited by space.
fn docker_complete(parts, line, pos) {
	var ret    = ()

	var partsz <= len($parts)

	if $partsz != "1" {
		# only autocomplete the subcommand
		return $ret
	}

	var choice, status <= (
		echo "attach build commit cp create diff events exec export history images import info inspect kill load login logout logs network node pause port ps pull push rename restart rm rmi run save search service start stats stop swarm tag top unpause update version volume wait" |
		tr " " "\n" |
		fzf --header "Docker subcommands: "
						--reverse
						 |
		tr -d "\n"
	)

	if $status != "0" {
		return $ret
	}

	ret = ($choice+" " "0")

	return $ret
}

dockercomplete = ("docker" $docker_complete)

NASHCOMPLETE_CMD <= append($NASHCOMPLETE_CMD, $dockercomplete)