import Debug from 'debug' ; import { Tab , CommandLine , registerTabCompletionEnumerator , TabCompletionSpec } from '@kui-shell/core' ; const debug = Debug ( 'plugins/bash-like/tab-completion/git' ) ; /**
 * Tab completion handler for git branch names
 *
 */ async function completeGitBranches ( tab , commandLine , spec ) { const args = commandLine . argvNoOptions ; const { toBeCompleted } = spec ; if ( args [ 0 ] === 'git' && ( args [ 1 ] === 'checkout' || args [ 1 ] === 'branch' ) ) { try { const completions = await tab . REPL . qexec < string > ( `! git branch --list '${ toBeCompleted ? toBeCompleted + '*' : '' }' --sort=refname --sort=committerdate` , undefined , undefined , { raw : true } ) ; return completions . split ( /[\n\r]/ ) . filter ( _ => _ ) . map ( _ => _ . replace ( /^\s*\*?\s*/ , '' ) . substring ( toBeCompleted . length ) ) ; } catch ( err ) { debug ( 'squashing error from attempted git tab completion' , err ) ; return [ ] ; } } } /**
 * Entry point to register tab completion handlers
 *
 */ export default ( ) => { registerTabCompletionEnumerator ( completeGitBranches ) ; } ;