Skip to content

Commit

Permalink
Merge branch 'release/v1.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
susurri committed Aug 19, 2017
2 parents fc2c95b + f497a71 commit ee871ea
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 9 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

<a name="1.0.1"></a>
## [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))



<a name="1.0.0"></a>
# 1.0.0 (2017-07-31)
7 changes: 5 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
source 'https://rubygems.org'

gem 'rake'
gem 'rantly'
gem 'rspec'

group :development do
gem 'rantly'
gem 'rspec'
end
24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "nautilus_save_tabs",
"version": "1.0.1",
"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"
}
48 changes: 45 additions & 3 deletions scripts/GetURIs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
27 changes: 24 additions & 3 deletions scripts/RestoreTabs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'yaml'
require 'uri'
require 'cgi'
require 'socket'

# nautilus module
module Nautilus
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion scripts/SaveTabs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ee871ea

Please sign in to comment.