Advertisements

Archive

Archive for February, 2017

Sorting connection profiles in the Secure Shell Chrome extension

February 4, 2017 Leave a comment

I have been using the Secure Shell Chrome extension for a while now when I’m in a non-Linux OS for one reason or another.  It isn’t very well documented, and it doesn’t have a lot of directly configurable options, but it works fairly well without installing anything other than a Chrome extension, and it allows me to stay in the browser with tabs and all that, so its handy.  One of the irritants is that you can’t easily sort the list of saved connections.  You can set the order in the javascript console, but the methods I found mentioned on the Internet to do this are multi-step processes, so I wrote a little function that does this for me as needed.  I can just paste this function into my javascript console and my connections are sorted for me.  I wanted them sorted by the label/description field.  Its just as easy to sort them by any other field in the profile.

This is using undocumented features of the extension, which might change at any time.  It then calls the set method to save the sorted list back to the settings.  You should backup your preferences before doing this, and use it at your own risk.  Please don’t blame me if you melt your preferences.

(function(){
    var list = nassh_.prefs_.get('profile-ids');
    list = list.slice(0);
    var out = [];

    var doprofile = function(){
        var id = list.pop();
        console.log(id);

        if(id){
            var p = nassh_.prefs_.getProfile(id);
            out.push({k: id, v: p.prefRecords_.description.currentValue});
            doprofile();
        } else {
            out.sort(function(a,b){
                    if (a.v < b.v) return -1;
                    if (a.v > b.v) return 1;
                    return 0;
            });
            for(var i=0;i<out.length;i++){
                out[i] = out[i].k;
            }
            if(out.length){
                nassh_.prefs_.set('profile-ids', out);
                console.log('done');
            } else {
                console.log('result set empty, please refresh the page and try again.');
            }
        }
    };
    doprofile();
})();
Advertisements
Categories: Uncategorized