terutil 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/_c +44 -0
- data/bin/remember +26 -0
- data/lib/remember.rb +59 -0
- data/lib/terutil.rb +5 -0
- metadata +49 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: cc0633656decf1e1a994475e76cd7f57ca6087c586f88ccbd3ede01c2273573e
|
|
4
|
+
data.tar.gz: 8d9226b37f74dcddaff0c373652fd56e535f81b53ae89f0f4e2cb19232fccde3
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 1c7e15bdbda18e76b33034d83c3403a6beac650945549c8aca9c5ef0b99e97d59b079f6c8830df4ef65ec980f9bf412b534e037cfcc37082956d9da33c0aeaa8
|
|
7
|
+
data.tar.gz: 3aa99706db105e031c3daea20c887c64951530dd8ecaf93bf60e3dce29b805eb68957638665757ff345261fd3bdab8f4a14d4c9a600f8ff53da7eb1084d7060e
|
data/bin/_c
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#! /usr/bin/ruby
|
|
2
|
+
require 'terutil'
|
|
3
|
+
include TerUtil
|
|
4
|
+
|
|
5
|
+
def main
|
|
6
|
+
if ARGV.length == 0
|
|
7
|
+
x = Remember.read("c/.")
|
|
8
|
+
if x then output 0, x
|
|
9
|
+
else output 1, "No shortcut directory set." end
|
|
10
|
+
elsif ARGV.length == 1
|
|
11
|
+
if ARGV[0] == '-'
|
|
12
|
+
Remember.write "c/.", Dir.pwd
|
|
13
|
+
output 0, '.'
|
|
14
|
+
else
|
|
15
|
+
x = Remember.read("c/" + ARGV[0])
|
|
16
|
+
if x then output 0, x
|
|
17
|
+
else output 1, "No saved directory '#{ARGV[0]}'." end
|
|
18
|
+
end
|
|
19
|
+
else
|
|
20
|
+
usage
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
rescue Errno::ENOENT
|
|
24
|
+
puts "No such directory '#{Remember.read ARGV[0]}'"
|
|
25
|
+
rescue Interrupt
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def output(status, message)
|
|
29
|
+
print message
|
|
30
|
+
exit status
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def usage
|
|
34
|
+
puts <<~END
|
|
35
|
+
Usage:
|
|
36
|
+
Jump to shortcut directory: c
|
|
37
|
+
Jump to stored directory: c <name>
|
|
38
|
+
|
|
39
|
+
To set the shortcut directory, use `c -``
|
|
40
|
+
To store a directory, use `remember "c/<name>" <directory>`
|
|
41
|
+
END
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
main
|
data/bin/remember
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#! /usr/bin/ruby
|
|
2
|
+
require 'terutil'
|
|
3
|
+
include TerUtil
|
|
4
|
+
|
|
5
|
+
def main
|
|
6
|
+
if ARGV.length == 1
|
|
7
|
+
puts Remember.read ARGV[0] || "Key '#{key}' was not found."
|
|
8
|
+
elsif ARGV.length == 2
|
|
9
|
+
Remember.write ARGV[0], ARGV[1], false
|
|
10
|
+
else
|
|
11
|
+
usage
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
rescue Interrupt
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def usage
|
|
18
|
+
puts <<~END
|
|
19
|
+
Usage:
|
|
20
|
+
Retrieve value: remember <key>
|
|
21
|
+
Store value: remember <key> <value>
|
|
22
|
+
Delete value: remember <key> ''
|
|
23
|
+
END
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
main
|
data/lib/remember.rb
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
require 'fileutils'
|
|
2
|
+
require 'json'
|
|
3
|
+
|
|
4
|
+
module TerUtil::Remember
|
|
5
|
+
FPATH = File.expand_path("terutil", ENV['XDG_CONFIG_HOME'] || "~/.config")
|
|
6
|
+
FNAME = FPATH + '/remember.json'
|
|
7
|
+
|
|
8
|
+
def self.reset_file
|
|
9
|
+
File.open(FNAME, 'w') { |f| f.write "{}" }
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.load_file
|
|
13
|
+
if !File.exists? FNAME
|
|
14
|
+
FileUtils.mkdir_p FPATH
|
|
15
|
+
reset_file
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
File.read(FNAME)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.load_data
|
|
22
|
+
ret = JSON.parse load_file
|
|
23
|
+
raise JSON::ParserError if ret.class != Hash
|
|
24
|
+
ret
|
|
25
|
+
|
|
26
|
+
rescue JSON::ParserError
|
|
27
|
+
puts "The remember data file (#{FNAME}) is corrupted."
|
|
28
|
+
puts "Please fix it manually or reset it."
|
|
29
|
+
print "Reset (ALL DATA WILL BE LOST!)? (y/n): "
|
|
30
|
+
if ['y', 'yes'].include? gets.chomp
|
|
31
|
+
reset_file
|
|
32
|
+
puts "File reset."
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def self.write_data(data)
|
|
39
|
+
File.open(FNAME, 'w') { |f| f.write JSON.generate(data) }
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def self.read(key)
|
|
43
|
+
load_data[key]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def self.write(key, val, silent=true)
|
|
47
|
+
if val == ''
|
|
48
|
+
delete key
|
|
49
|
+
puts "Deleted #{key}." if !silent
|
|
50
|
+
else
|
|
51
|
+
write_data load_data.tap { |d| d[key] = val }
|
|
52
|
+
puts "Set #{key} to #{val}." if !silent
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def self.delete(key)
|
|
57
|
+
write_data load_data.reject { |k| k == key }
|
|
58
|
+
end
|
|
59
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: terutil
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- vypxl
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-05-20 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description:
|
|
14
|
+
email:
|
|
15
|
+
executables:
|
|
16
|
+
- remember
|
|
17
|
+
- _c
|
|
18
|
+
extensions: []
|
|
19
|
+
extra_rdoc_files: []
|
|
20
|
+
files:
|
|
21
|
+
- bin/_c
|
|
22
|
+
- bin/remember
|
|
23
|
+
- lib/remember.rb
|
|
24
|
+
- lib/terutil.rb
|
|
25
|
+
homepage: https://github.com/vypxl/terutil
|
|
26
|
+
licenses:
|
|
27
|
+
- MIT
|
|
28
|
+
metadata:
|
|
29
|
+
source_code_uri: https://github.com/vypxl/terutil
|
|
30
|
+
post_install_message:
|
|
31
|
+
rdoc_options: []
|
|
32
|
+
require_paths:
|
|
33
|
+
- lib
|
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '0'
|
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '0'
|
|
44
|
+
requirements: []
|
|
45
|
+
rubygems_version: 3.0.3
|
|
46
|
+
signing_key:
|
|
47
|
+
specification_version: 4
|
|
48
|
+
summary: Terminal Util - a collection of useful terminal utilities.
|
|
49
|
+
test_files: []
|