From f633778b9e1bd253cf0eb4a77413527a72b96f78 Mon Sep 17 00:00:00 2001 From: susurri Date: Mon, 14 Aug 2017 22:18:30 +0900 Subject: [PATCH 1/4] build: move gems for development to the development section gems for unit tests are not required for users --- Gemfile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index ca8508d..5ed87ec 100644 --- a/Gemfile +++ b/Gemfile @@ -3,5 +3,8 @@ source 'https://rubygems.org' gem 'rake' -gem 'rantly' -gem 'rspec' + +group :development do + gem 'rantly' + gem 'rspec' +end From 47138c6cb61316ffbb2c108d2340b97b562b8c74 Mon Sep 17 00:00:00 2001 From: susurri Date: Thu, 17 Aug 2017 01:39:30 +0900 Subject: [PATCH 2/4] perf: improve performance of selecting uri it is not necessary to type all filename when selecting uri. this commit improves performance scanning the shortest unique string which matches the uri. --- scripts/GetURIs | 48 ++++++++++++++++++++++++++++++++++++++++++--- scripts/RestoreTabs | 27 ++++++++++++++++++++++--- scripts/SaveTabs.rb | 4 +++- 3 files changed, 72 insertions(+), 7 deletions(-) diff --git a/scripts/GetURIs b/scripts/GetURIs index c264abe..d89435b 100755 --- a/scripts/GetURIs +++ b/scripts/GetURIs @@ -2,6 +2,14 @@ require 'socket' require 'yaml' +require 'nkf' + +# string +class String + def halfwidth + NKF.nkf('-m0Z1 -W -w', self) + end +end module Nautilus # configurations @@ -23,11 +31,45 @@ module Nautilus class GetURIs def initialize @config = Config.new - uri = ENV['NAUTILUS_SCRIPT_CURRENT_URI'] - selected_uris = ENV['NAUTILUS_SCRIPT_SELECTED_URIS'] + @uri = ENV['NAUTILUS_SCRIPT_CURRENT_URI'] + @selected_uris = ENV['NAUTILUS_SCRIPT_SELECTED_URIS'] + socket + end + + def lower_bound(min, max, f) + while (max - min) > 1 + mean = (max + min) / 2 + if f.call(mean) + max = mean + else + min = mean + end + end + max + end + + def minimum_matched(str, strs) + f = proc { |n| + matched = strs.select do |s| + s.encode(invalid: :replace).halfwidth + .downcase.start_with?(str.halfwidth + .downcase[0, n]) + end + matched.size <= 1 + } + str[0, lower_bound(0, str.size, f)].halfwidth + end + def socket UNIXSocket.open(@config.config['socket_path']) do |sock| - sock.write(YAML.dump([uri, selected_uris])) + sock.set_encoding 'UTF-8' + filename = sock.gets.chomp + case filename + when '' + sock.write(YAML.dump([@uri, @selected_uris])) + else + sock.write(YAML.dump(minimum_matched(filename, Dir.entries('.')))) + end end end end diff --git a/scripts/RestoreTabs b/scripts/RestoreTabs index 29bf074..41fba2b 100755 --- a/scripts/RestoreTabs +++ b/scripts/RestoreTabs @@ -3,6 +3,7 @@ require 'yaml' require 'uri' require 'cgi' +require 'socket' # nautilus module module Nautilus @@ -14,6 +15,7 @@ module Nautilus 'sleep_time_restore' => 0.3, 'select_uri_delay' => 100, 'save_tabs_path' => ENV['HOME'] + '/.local/share/nautilus/tabs', + 'shortcut_geturis' => 'control+g', 'socket_path' => '/tmp/nautilus_' + ENV['USER'] + '.socket' } end @@ -46,11 +48,30 @@ module Nautilus YAML.load_file(@config.config['save_tabs_path']) end + def read_socket(filename) + Thread.start do + Socket + .unix_server_loop(@config.config['socket_path']) do |sock, _addr| + sock.puts(filename) + @uris = YAML.safe_load(sock.read) + break + end + end + end + + def get_uris(filename) + thread = read_socket(filename) + key(@config.config['shortcut_geturis']) + thread.join + @uris + end + def select_uri(uri) return if uri.last.empty? - type(File.basename(CGI.unescape(URI.parse(uri.last.split("\n") - .first).path)), - @config.config['select_uri_delay']) + filename = File.basename(CGI.unescape(URI.parse(uri.last.split("\n") + .first).path)) + uri = get_uris(filename) + type(uri, @config.config['select_uri_delay']) key('Escape') end diff --git a/scripts/SaveTabs.rb b/scripts/SaveTabs.rb index 4d85a27..0cd8c34 100755 --- a/scripts/SaveTabs.rb +++ b/scripts/SaveTabs.rb @@ -57,6 +57,7 @@ def read_socket Thread.start do Socket .unix_server_loop(@config.config['socket_path']) do |sock, _addr| + sock.puts('') @uris = YAML.safe_load(sock.read) break end @@ -160,7 +161,8 @@ def uris_to_s(uris) str1 = if u[1].empty? Shellwords.escape('-') else - Shellwords.escape(CGI.unescape(u[1].chomp.tr("\n", ','))) + Shellwords.escape(CGI.unescape(u[1].chomp.tr("\n", ',')) + .encode(invalid: :replace)) end str += (Shellwords.escape(CGI.unescape(u[0])) + ' ' + str1 + ' ') end From 04e41b18f9da028315f30481f101714a70e46232 Mon Sep 17 00:00:00 2001 From: susurri Date: Sun, 20 Aug 2017 04:49:38 +0900 Subject: [PATCH 3/4] chore: add package.json which is required by tool chains for angular convention tool chains to follow angular convention is introduced for automated changelog and release. --- package.json | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 package.json diff --git a/package.json b/package.json new file mode 100644 index 0000000..aa57fb7 --- /dev/null +++ b/package.json @@ -0,0 +1,24 @@ +{ + "name": "nautilus_save_tabs", + "version": "1.0.0", + "description": "Nautilus scripts to save/restore tabs", + "main": "index.js", + "dependencies": {}, + "devDependencies": {}, + "scripts": { + "test": "bundle exec rake spec" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/susurri/nautilus_save_tabs.git" + }, + "keywords": [ + "nautilus" + ], + "author": "susurri", + "license": "MIT", + "bugs": { + "url": "https://github.com/susurri/nautilus_save_tabs/issues" + }, + "homepage": "https://github.com/susurri/nautilus_save_tabs#readme" +} From f497a711f6d2fbd93c79d0c6b4faada262560f51 Mon Sep 17 00:00:00 2001 From: susurri Date: Sun, 20 Aug 2017 05:52:02 +0900 Subject: [PATCH 4/4] chore(release): 1.0.1 --- CHANGELOG.md | 16 ++++++++++++++++ package.json | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..5b6edb0 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,16 @@ +# Change Log + +All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. + + +## [1.0.1](https://github.com/susurri/nautilus_save_tabs/compare/v1.0.0...v1.0.1) (2017-08-19) + + +### Performance Improvements + +* improve performance of selecting uri ([47138c6](https://github.com/susurri/nautilus_save_tabs/commit/47138c6)) + + + + +# 1.0.0 (2017-07-31) diff --git a/package.json b/package.json index aa57fb7..96eb7a9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nautilus_save_tabs", - "version": "1.0.0", + "version": "1.0.1", "description": "Nautilus scripts to save/restore tabs", "main": "index.js", "dependencies": {},