lida 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +5 -3
  3. data/LICENSE +21 -0
  4. data/README.md +35 -3
  5. data/bin/lida +126 -70
  6. data/lida.gemspec +3 -2
  7. metadata +20 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 20cf6abf9becdd6727c1831a93aa51bbc4a4339ffb3d49def5028bd6dd608263
4
- data.tar.gz: 2df93f21e71361ba390bfec669ffeded0ae5e304bfc13ce219b89a6197e87f06
3
+ metadata.gz: f2efbc1792724bcb2d2e1156d92c3241d0f9e15dd80c3759f6ee86560a37eef6
4
+ data.tar.gz: ece9d036d85a0b6af91ec82a9a3fa454946190dbbf59660c0033928ea1a79777
5
5
  SHA512:
6
- metadata.gz: a019bb8eef804aa438fd70d2b7deb88acec7c0fa5f7efe49efb3fd2a75e5e92e4dc6dd8c53da78ccdcebe5cd60d4f6535ff49226a68b18033fd1181c9c8cd415
7
- data.tar.gz: aa6447b949dc381a7740450857f2866d69f6a6f8cfc160e03d5764e9f32827074898e46834a2afe04aa00afbd6ee2e54928b54537e8e07c04c1addb9359c4864
6
+ metadata.gz: b70069ba81672ac2bd74173b4c8488efa56deee8aba9b1965fdde8e58c0305703e0c33ff2634cb82ce04c87377b1ec85152b3bb0f21bf254c8e772f1c6d422f9
7
+ data.tar.gz: df98e617104c04c193791f1d0be023404d34e1f9127026b18f469c5f67a141d44a48c3330d3b2177749a67bbd2943f6010d332eaedf72f2971395eda122e3813
data/Gemfile.lock CHANGED
@@ -1,17 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lida (0.0.1)
4
+ lida (0.0.2)
5
5
  applescript (~> 1.0)
6
6
  commander (~> 4.4)
7
+ rainbow (~> 3.0)
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
10
11
  specs:
11
12
  applescript (1.0)
12
- commander (4.4.5)
13
+ commander (4.4.6)
13
14
  highline (~> 1.7.2)
14
15
  highline (1.7.10)
16
+ rainbow (3.0.0)
15
17
 
16
18
  PLATFORMS
17
19
  ruby
@@ -20,4 +22,4 @@ DEPENDENCIES
20
22
  lida!
21
23
 
22
24
  BUNDLED WITH
23
- 1.16.1
25
+ 1.16.2
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Quentin Jin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,8 +1,40 @@
1
1
  # lida
2
2
 
3
+ 🍰 Open current finder/xcode dir in terminal/iterm and vice versa, easy as cake!
4
+
5
+ ## Usage
6
+
3
7
  ```shell
8
+ # Open working directory of current terminal in finder
4
9
  lida
5
- lida i
6
- lida t
10
+
11
+ # Open current finder dir in a new tab of current terminal
12
+ lida finder
7
13
  lida f
8
- ```
14
+
15
+ # Open current xcode dir in a new tab of current terminal
16
+ lida xcode
17
+ lida x
18
+
19
+ #
20
+ lida xcodebeta
21
+ lida xb
22
+ ```
23
+
24
+ ## Installation
25
+
26
+ ```shell
27
+ gem install lida
28
+ ```
29
+
30
+ ## Acknowledgement
31
+
32
+ Inspired by LeEnno's [alfred-terminalfinder](https://github.com/LeEnno/alfred-terminalfinder)!
33
+
34
+ ## Contributing
35
+
36
+ Feel free to criticize!
37
+
38
+ ## License
39
+
40
+ MIT
data/bin/lida CHANGED
@@ -3,100 +3,156 @@
3
3
  require 'rubygems'
4
4
  require 'commander/import'
5
5
  require 'applescript'
6
+ require 'rainbow/refinement'
7
+ using Rainbow
6
8
 
7
9
  program :name, 'Lida'
8
- program :version, '0.0.1'
9
- program :description, 'Folder to terminal, terminal to folder.'
10
+ program :version, '0.0.2'
11
+ program :description, 'Finder to terminal; Xcode to terminal; Terminal to finder'
10
12
  program :help, 'Author', 'Quentin Jin <jianstm@gmail.com>'
11
13
 
12
- # terminal to finder
13
- command :finder do |c|
14
- c.syntax = 'lida folder'
15
- c.description = 'Open current directory in finder'
14
+ # Terminal to finder
15
+ command :terminal do |c|
16
+ c.syntax = 'lida finder'
17
+ c.description = 'Open working directory of current terminal in finder'
16
18
  c.action do
17
19
  `open -a Finder ./`
18
20
  end
19
21
  end
20
22
 
23
+ # Xcode to terminal
24
+ command :xcode do |c|
25
+ c.syntax = 'lida xcode'
26
+ c.description = 'Open current xcode dir in a new tab of current terminal'
27
+ c.action do
28
+ begin
29
+ path = get_current_path_of_xcode 'Xcode'
30
+ rescue
31
+ puts 'No active window or file on Xcode.'.red
32
+ end
21
33
 
22
- # folder to terminal
23
- command :terminal do |c|
34
+ open_path path if path
35
+ end
36
+ end
37
+
38
+ # Xcode-beta to terminal
39
+ command :xcodebeta do |c|
40
+ c.syntax = 'lida xcodebeta'
41
+ c.description = 'Open current xcode dir in a new tab of current terminal'
42
+ c.action do
43
+ begin
44
+ path = get_current_path_of_xcode 'Xcode-beta'
45
+ rescue
46
+ puts 'No active window or file on Xcode-beta.'.red
47
+ end
48
+
49
+ open_path path if path
50
+ end
51
+ end
52
+
53
+ # Finder to terminal
54
+ command :finder do |c|
24
55
  c.syntax = 'lida terminal'
25
- c.description = 'Open current directory in terminal'
56
+ c.description = 'Open current finder dir in a new tab of current terminal'
26
57
  c.action do
27
- script = <<-eos
28
- set result to (path to frontmost application as text)
29
- return result
30
- eos
31
-
32
- if AppleScript.execute(script) =~ /iTerm.app/
33
- AppleScript.execute(FINDER_TO_ITERM)
34
- else
35
- AppleScript.execute(FINDER_TO_TERMINAL)
58
+ begin
59
+ path = get_current_path_of_finder
60
+ rescue
61
+ puts 'No active window on Finder.'.red
36
62
  end
63
+ open_path path if path
37
64
  end
38
65
  end
39
66
 
67
+ alias_command :f, :finder
68
+ alias_command :x, :xcode
69
+ alias_command :xb, :xcodebeta
40
70
  default_command :terminal
41
71
 
42
- FINDER_TO_ITERM = <<EOS
43
- tell application "Finder"
44
- if (count of windows) is 0 then
45
- set pathList to "~"
46
- else
47
- set pathList to (quoted form of POSIX path of (folder of the front window as alias))
48
- end if
49
- set command to "clear; cd " & pathList
50
- end tell
51
-
52
- tell application "System Events"
53
- -- some versions might identify as "iTerm2" instead of "iTerm"
54
- set isRunning to (exists (processes where name is "iTerm")) or (exists (processes where name is "iTerm2"))
55
- end tell
56
-
57
- tell application "iTerm"
58
- activate
59
- set hasNoWindows to ((count of windows) is 0)
60
- if isRunning and hasNoWindows then
61
- create window with default profile
62
- end if
63
- select first window
64
-
65
- tell the first window
66
- if isRunning and hasNoWindows is false then
67
- create tab with default profile
68
- end if
69
- tell current session to write text command
72
+ def get_current_path_of_xcode(xcode)
73
+ script = <<~EOS
74
+ tell application "#{xcode}"
75
+ set CurrentDocument to document 1 whose name ends with (word -1 of (get name of window 1))
76
+ set CurrentPath to path of CurrentDocument
77
+ return CurrentPath
70
78
  end tell
71
- end tell
72
- EOS
73
-
74
- FINDER_TO_TERMINAL = <<-EOS
75
- tell application "Finder"
76
- if (count of windows) is 0 then
77
- set pathList to "~"
78
- else
79
- set pathList to (quoted form of POSIX path of (folder of the front window as alias))
80
- end if
81
- end tell
79
+ EOS
80
+ begin
81
+ path = AppleScript.execute(script)
82
+ rescue
83
+ raise NoWindowError
84
+ end
85
+ path
86
+ end
82
87
 
83
- tell application "System Events"
84
- if not (exists (processes where name is "Terminal")) then
85
- do shell script "open -a Terminal " & pathList
86
- else
87
- tell application "Terminal"
88
- activate
88
+ def get_current_path_of_finder
89
+ script = <<~EOS
90
+ tell application "Finder"
89
91
  if (count of windows) is 0 then
90
- do script ("cd " & pathList)
92
+ set CurrentPath to "nitneuq"
91
93
  else
92
- tell application "System Events" to tell process "Terminal.app" to keystroke "t" using command down
93
- delay 1
94
- do script ("cd " & pathList) in first window
94
+ set CurrentPath to (POSIX path of (folder of the front window as alias))
95
95
  end if
96
96
  end tell
97
- end if
98
- end tell
99
- EOS
97
+ return CurrentPath
98
+ EOS
100
99
 
100
+ path = AppleScript.execute(script)
101
+ raise NoWindowError if path =~ /nitneuq/
102
+ path
103
+ end
101
104
 
105
+ def is_terminal_or_iterm
106
+ script = <<-eos
107
+ set AppPath to (path to frontmost application as text)
108
+ return AppPath
109
+ eos
110
+ if AppleScript.execute(script) =~ /Terminal.app/; 0
111
+ elsif AppleScript.execute(script) =~ /iTerm.app/; 1
112
+ else; -1
113
+ end
114
+ end
115
+
116
+ def open_path(path)
117
+ path.chomp!
118
+ path = File.split(path)[0] unless File.directory?(path)
119
+ flag = is_terminal_or_iterm
120
+ if flag == 0
121
+ open_path_in_terminal path
122
+ elsif flag == 1
123
+ open_path_in_iterm path
124
+ else
125
+ puts 'Lida only supports iterm and terminal for now.'.red
126
+ end
127
+ end
102
128
 
129
+ def open_path_in_iterm(dic)
130
+ script = <<~EOS
131
+ set command to "cd #{dic}"
132
+ tell application "iTerm"
133
+ select first window
134
+ tell the first window
135
+ create tab with default profile
136
+ tell current session to write text "clear"
137
+ tell current session to write text command
138
+ end tell
139
+ end tell
140
+ EOS
141
+ AppleScript.execute(script)
142
+ end
143
+
144
+ def open_path_in_terminal(path)
145
+ script = <<~EOS
146
+ tell application "Terminal"
147
+ activate
148
+ tell application "System Events" to keystroke "t" using command down
149
+ delay 1
150
+ do script ("clear") in first window
151
+ do script ("cd #{path}") in first window
152
+ end tell
153
+ EOS
154
+ AppleScript.execute(script)
155
+ end
156
+
157
+ class NoWindowError < StandardError
158
+ end
data/lida.gemspec CHANGED
@@ -1,10 +1,10 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'lida'
3
- spec.version = '0.0.1'
3
+ spec.version = '0.0.2'
4
4
  spec.authors = ["Quentin Jin"]
5
5
  spec.email = ["jianstm@gmail.com"]
6
6
 
7
- spec.summary = "Folder to terminal, terminal to folder."
7
+ spec.summary = "🍰 Open current finder/xcode dir in terminal/iterm and vice versa, easy as cake!"
8
8
  spec.homepage = "https://github.com/jianstm/lida"
9
9
  spec.license = "MIT"
10
10
 
@@ -13,4 +13,5 @@ Gem::Specification.new do |spec|
13
13
 
14
14
  spec.add_runtime_dependency 'commander', '~> 4.4'
15
15
  spec.add_runtime_dependency 'applescript', '~> 1.0'
16
+ spec.add_runtime_dependency 'rainbow', '~> 3.0'
16
17
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lida
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Quentin Jin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-15 00:00:00.000000000 Z
11
+ date: 2018-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rainbow
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
41
55
  description:
42
56
  email:
43
57
  - jianstm@gmail.com
@@ -49,6 +63,7 @@ files:
49
63
  - ".gitignore"
50
64
  - Gemfile
51
65
  - Gemfile.lock
66
+ - LICENSE
52
67
  - README.md
53
68
  - bin/lida
54
69
  - lida.gemspec
@@ -72,8 +87,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
87
  version: '0'
73
88
  requirements: []
74
89
  rubyforge_project:
75
- rubygems_version: 2.7.3
90
+ rubygems_version: 2.7.7
76
91
  signing_key:
77
92
  specification_version: 4
78
- summary: Folder to terminal, terminal to folder.
93
+ summary: "\U0001F370 Open current finder/xcode dir in terminal/iterm and vice versa,
94
+ easy as cake!"
79
95
  test_files: []