let drivelist = require('drivelist');
let separator = isWin ? '\\' : '/';
let drivesNames = '';
const splitRegexp =  /[\\/]\s*/;
const noMultiStarRegExp = /[*][*]+/;

function init(callback){
    drivelist.list(function(error, disks){
        if(error){
            throw error;
        }

        drivesNames = disks.map((disk) => disk.name + separator);
        callback();
    });
}

// Split the autocomplete eval with chars \ / or < >
function split( val ) {
    return val.split(splitRegexp);
}

function last( val ){
    let arr = split(val);

    return (val.endsWith('/'))  ? arr[arr.length - 2] : arr[arr.length -1];
}

function getSubDirs(levels, current){
    let root = levels.join('/');
    let pattern = '/' + current + '*/'.replace(noMultiStarRegExp, '*');

    return glob.sync(pattern, {root: root, nocase: true})
        .map(path => split(path).join(separator));
}

function getDrivesNames(current){
    return $.grep(drivesNames, dn => dn.toLowerCase().startsWith(current.toLowerCase()));
}

exports.init = init;
exports.split = split;
exports.last = last;
exports.getSubDirs = getSubDirs;
exports.getDrivesNames = getDrivesNames;
exports.separator = separator;
@@ -361,17 +361,605 @@
     
-callback(
+setTimeout(checkDriveListChanges, 5000);%0A        callback();%0A    %7D);%0A%7D%0A%0Afunction checkDriveListChanges()%7B%0A    drivelist.list((error, disks) =%3E %7B%0A        if(error)%7B%0A            throw error;%0A        %7D%0A%0A        currentdrivesNames = disks.map((disk) =%3E disk.name + separator);%0A%0A        if(JSON.stringify(drivesNames) !== JSON.stringify(currentdrivesNames))%7B%0A            console.log(%7Bevent: 'Drives changed', currentdrivesNames, drivesNames%7D);%0A            drivesNames = currentdrivesNames;%0A            field.autocomplete('search', field.val());%0A        %7D%0A%0A        setTimeout(checkDriveListChanges, 5000
 );%0A 

add detection of pluggable drives device