Add support for ~ expansion

This commit is contained in:
Stuart Quin 2016-08-03 21:34:49 +01:00
parent 7e1e03284a
commit 6f03cd8bc7

View file

@ -1,5 +1,6 @@
fs = require 'fs' fs = require 'fs'
path = require 'path' path = require 'path'
os = require 'os'
Ex = require './ex' Ex = require './ex'
module.exports = module.exports =
@ -13,6 +14,12 @@ class AutoComplete
@autoCompleteText = null @autoCompleteText = null
@completions = [] @completions = []
expandTilde: (filePath) ->
if filePath.charAt(0) == '~'
return os.homedir() + filePath.slice(1)
else
return filePath
getAutocomplete: (text) -> getAutocomplete: (text) ->
if !@autoCompleteText if !@autoCompleteText
@autoCompleteText = text @autoCompleteText = text
@ -48,6 +55,8 @@ class AutoComplete
return @filterByPrefix(@commands, command) return @filterByPrefix(@commands, command)
getFilePathCompletion: (command, filePath) -> getFilePathCompletion: (command, filePath) ->
filePath = @expandTilde(filePath)
if filePath.endsWith(path.sep) if filePath.endsWith(path.sep)
basePath = path.dirname(filePath + '.') basePath = path.dirname(filePath + '.')
baseName = '' baseName = ''