mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-25 12:23:09 +00:00
web_config: add support for viewing abbreviations
Add a new tab which lists the current abbreviations defined, by wrapping the `abbr` command. Work on #731.
This commit is contained in:
parent
980bf6e2f4
commit
7764a1a6f8
6 changed files with 56 additions and 1 deletions
|
@ -24,6 +24,7 @@
|
||||||
<div ng-class="{'tab': true, 'selected_tab': currentTab == 'variables'}" id="tab_variables" ng-click="changeView('variables')">variables</div>
|
<div ng-class="{'tab': true, 'selected_tab': currentTab == 'variables'}" id="tab_variables" ng-click="changeView('variables')">variables</div>
|
||||||
<div ng-class="{'tab': true, 'selected_tab': currentTab == 'history'}" id="tab_history" ng-click="changeView('history')">history</div>
|
<div ng-class="{'tab': true, 'selected_tab': currentTab == 'history'}" id="tab_history" ng-click="changeView('history')">history</div>
|
||||||
<div ng-class="{'tab': true, 'selected_tab': currentTab == 'bindings'}" id="tab_bindings" ng-click="changeView('bindings')">bindings</div>
|
<div ng-class="{'tab': true, 'selected_tab': currentTab == 'bindings'}" id="tab_bindings" ng-click="changeView('bindings')">bindings</div>
|
||||||
|
<div ng-class="{'tab': true, 'selected_tab': currentTab == 'abbreviations'}" id="tab_abbreviations" ng-click="changeView('abbreviations')">abbreviations</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="tab_contents">
|
<div id="tab_contents">
|
||||||
<ng-view></ng-view>
|
<ng-view></ng-view>
|
||||||
|
|
|
@ -27,6 +27,10 @@ fishconfig.config(
|
||||||
controller: "bindingsController",
|
controller: "bindingsController",
|
||||||
templateUrl: "partials/bindings.html"
|
templateUrl: "partials/bindings.html"
|
||||||
})
|
})
|
||||||
|
.when("/abbreviations", {
|
||||||
|
controller: "abbreviationsController",
|
||||||
|
templateUrl: "partials/abbreviations.html"
|
||||||
|
})
|
||||||
.otherwise({
|
.otherwise({
|
||||||
redirectTo: "/colors"
|
redirectTo: "/colors"
|
||||||
})
|
})
|
||||||
|
|
|
@ -284,3 +284,13 @@ controllers.controller("bindingsController", function($scope, $http) {
|
||||||
|
|
||||||
$scope.fetchBindings();
|
$scope.fetchBindings();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
controllers.controller("abbreviationsController", function($scope, $http) {
|
||||||
|
$scope.abbreviations = [];
|
||||||
|
$scope.fetchAbbreviations = function() {
|
||||||
|
$http.get("abbreviations/").success(function(data, status, headers, config) {
|
||||||
|
$scope.abbreviations = data;
|
||||||
|
})};
|
||||||
|
|
||||||
|
$scope.fetchAbbreviations();
|
||||||
|
});
|
|
@ -33,3 +33,20 @@ filters.filter("filterBinding", function() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
filters.filter("filterAbbreviations", function() {
|
||||||
|
return function(abbreviations, query) {
|
||||||
|
var result = []
|
||||||
|
if (abbreviations == undefined) return result;
|
||||||
|
if (query == null) { return abbreviations};
|
||||||
|
|
||||||
|
for(i=0; i<abbreviations.length; ++i) {
|
||||||
|
abbr = abbreviations[i];
|
||||||
|
if (abbr.word.toLowerCase().indexOf(query) != -1 || abbr.phrase.toLowerCase().indexOf(query.toLowerCase()) != -1) {
|
||||||
|
result.push(abbr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
12
share/tools/web_config/partials/abbreviations.html
Normal file
12
share/tools/web_config/partials/abbreviations.html
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<div id="table_filter_container" style="display: block;">
|
||||||
|
<input id="table_filter_text_box" class="filter_text_box text_box_transient" placeholder="Filter" ng-model="query">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<table class="data_table">
|
||||||
|
<tbody>
|
||||||
|
<tr class="data_table_row" ng-repeat="abbreviation in abbreviations | filterAbbreviations:query">
|
||||||
|
<td ng-class="{ data_table_cell: true}" style="text-align: right; padding-right: 30px;" ng-click="abbreviation._is_selected = !abbreviation._is_selected">{{ abbreviation.word }}</td>
|
||||||
|
<td ng-class="{ data_table_cell: true}" style="text-align: left; padding-right: 30px;" ng-click="abbreviation._is_selected = !abbreviation._is_selected">{{ abbreviation.phrase }}</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
|
@ -682,6 +682,15 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||||
result.extend([r for r in sample_results if r])
|
result.extend([r for r in sample_results if r])
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def do_get_abbreviations(self):
|
||||||
|
out, err = run_fish_cmd('abbr -s')
|
||||||
|
lines = (x for x in out.rstrip().split('\n'))
|
||||||
|
# Turn the output into something we can use
|
||||||
|
abbrout = (line[len('abbr -a '):].strip('\'') for line in lines)
|
||||||
|
abbrs = (x.split('=') for x in abbrout)
|
||||||
|
result = [{'word': x, 'phrase': y} for x, y in abbrs]
|
||||||
|
return result
|
||||||
|
|
||||||
def secure_startswith(self, haystack, needle):
|
def secure_startswith(self, haystack, needle):
|
||||||
if len(haystack) < len(needle):
|
if len(haystack) < len(needle):
|
||||||
return False
|
return False
|
||||||
|
@ -731,6 +740,8 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||||
output = self.do_get_color_for_variable(name)
|
output = self.do_get_color_for_variable(name)
|
||||||
elif p == '/bindings/':
|
elif p == '/bindings/':
|
||||||
output = self.do_get_bindings()
|
output = self.do_get_bindings()
|
||||||
|
elif p == '/abbreviations/':
|
||||||
|
output = self.do_get_abbreviations()
|
||||||
else:
|
else:
|
||||||
return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
|
return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
|
||||||
|
|
||||||
|
@ -887,7 +898,7 @@ if PORT > 9000:
|
||||||
# Just look at the first letter
|
# Just look at the first letter
|
||||||
initial_tab = ''
|
initial_tab = ''
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
for tab in ['functions', 'prompt', 'colors', 'variables', 'history', 'bindings']:
|
for tab in ['functions', 'prompt', 'colors', 'variables', 'history', 'bindings', 'abbreviations']:
|
||||||
if tab.startswith(sys.argv[1]):
|
if tab.startswith(sys.argv[1]):
|
||||||
initial_tab = '#' + tab
|
initial_tab = '#' + tab
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in a new issue