Skip to content

Commit

Permalink
v0.3 - See Changelogs
Browse files Browse the repository at this point in the history
  • Loading branch information
hug33k committed Sep 27, 2016
1 parent 27c4877 commit 7e7b406
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 76 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Get your shell's variables into Alfred

## Installation

Download [Alfred-ShellVariables.alfredworkflow](https://github.com/hug33k/Alfred-ShellVariables/releases/download/v0.2/Alfred-ShellVariables.alfredworkflow) and open it with Alfred.
Download [Alfred-ShellVariables.alfredworkflow](https://github.com/hug33k/Alfred-ShellVariables/releases/download/v0.3/Alfred-ShellVariables.alfredworkflow) and open it with Alfred.

## Usage

Expand All @@ -18,16 +18,19 @@ You can now type ___$___, followed by an optional query, to find your shell vari

- [x] Fish Shell
- [x] Bash
- [ ] ZSH
- [x] ZSH

## TODO

* ZSH integration

You can make a PR or ask me for integrate another shell :)

## Changelogs

###v0.3

* Add ZSH support
* Update shell support

###v0.2

* Add Shell selection
Expand Down
99 changes: 44 additions & 55 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@
<dict>
<key>65E57995-6ABE-4CD3-A336-6C263E780080</key>
<array/>
<key>88C5D01E-CA45-44E8-AE9D-DD12542F56EC</key>
<array>
<dict>
<key>destinationuid</key>
<string>031E6FA5-3C1C-42CA-BE2A-09DCB2E275CF</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
<key>90EC00B5-030E-47D2-A490-40514F074398</key>
<array>
<dict>
Expand Down Expand Up @@ -46,8 +59,6 @@
<false/>
</dict>
</array>
<key>992FAE5D-93FC-45A2-9E26-1E24A9FD3E82</key>
<array/>
<key>9D0E5065-0318-4297-A0BC-3F55703183AC</key>
<array>
<dict>
Expand Down Expand Up @@ -166,49 +177,6 @@
<key>version</key>
<integer>2</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>alfredfiltersresults</key>
<false/>
<key>argumenttype</key>
<integer>2</integer>
<key>escaping</key>
<integer>102</integer>
<key>keyword</key>
<string>sv init</string>
<key>queuedelaycustom</key>
<integer>3</integer>
<key>queuedelayimmediatelyinitially</key>
<true/>
<key>queuedelaymode</key>
<integer>0</integer>
<key>queuemode</key>
<integer>1</integer>
<key>runningsubtext</key>
<string>Please wait, initialization in progress</string>
<key>script</key>
<string>python main.py --update</string>
<key>scriptargtype</key>
<integer>0</integer>
<key>scriptfile</key>
<string></string>
<key>subtext</key>
<string></string>
<key>title</key>
<string>Initialize Shell variables</string>
<key>type</key>
<integer>0</integer>
<key>withspace</key>
<false/>
</dict>
<key>type</key>
<string>alfred.workflow.input.scriptfilter</string>
<key>uid</key>
<string>992FAE5D-93FC-45A2-9E26-1E24A9FD3E82</string>
<key>version</key>
<integer>2</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand Down Expand Up @@ -296,6 +264,27 @@
<key>version</key>
<integer>2</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>argumenttype</key>
<integer>2</integer>
<key>keyword</key>
<string>sv init</string>
<key>subtext</key>
<string></string>
<key>text</key>
<string>Initialize Shell variables</string>
<key>withspace</key>
<false/>
</dict>
<key>type</key>
<string>alfred.workflow.input.keyword</string>
<key>uid</key>
<string>88C5D01E-CA45-44E8-AE9D-DD12542F56EC</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand Down Expand Up @@ -329,14 +318,14 @@
<key>xpos</key>
<integer>610</integer>
<key>ypos</key>
<integer>510</integer>
<integer>370</integer>
</dict>
<key>65E57995-6ABE-4CD3-A336-6C263E780080</key>
<dict>
<key>xpos</key>
<integer>610</integer>
<key>ypos</key>
<integer>370</integer>
<integer>240</integer>
</dict>
<key>73C7530A-F827-4010-9A51-F404DE6E591D</key>
<dict>
Expand All @@ -345,24 +334,24 @@
<key>ypos</key>
<integer>110</integer>
</dict>
<key>90EC00B5-030E-47D2-A490-40514F074398</key>
<key>88C5D01E-CA45-44E8-AE9D-DD12542F56EC</key>
<dict>
<key>xpos</key>
<integer>200</integer>
<key>ypos</key>
<integer>110</integer>
<integer>370</integer>
</dict>
<key>921F80D9-092D-4829-B212-7714EA48163A</key>
<key>90EC00B5-030E-47D2-A490-40514F074398</key>
<dict>
<key>xpos</key>
<integer>410</integer>
<integer>200</integer>
<key>ypos</key>
<integer>370</integer>
<integer>110</integer>
</dict>
<key>992FAE5D-93FC-45A2-9E26-1E24A9FD3E82</key>
<key>921F80D9-092D-4829-B212-7714EA48163A</key>
<dict>
<key>xpos</key>
<integer>200</integer>
<integer>410</integer>
<key>ypos</key>
<integer>240</integer>
</dict>
Expand All @@ -378,7 +367,7 @@
<key>xpos</key>
<integer>200</integer>
<key>ypos</key>
<integer>370</integer>
<integer>240</integer>
</dict>
</dict>
<key>webaddress</key>
Expand Down
48 changes: 31 additions & 17 deletions init.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,48 @@
import shell
from workflow import Workflow, ICON_ERROR

shells = ["fish", "bash"]
shells = {
"fish": {
"cmd": ["/usr/local/bin/fish", "-c", "set"],
"replace": {},
"separator": " "
},
"bash": {
"cmd": ["/bin/bash", "-ic", "export"],
"replace": {"declare -x": ""},
"separator": "="
},
"zsh": {
"cmd": ["/bin/zsh", "-ic", "export"],
"replace": {},
"separator": "="
},
}

def getVariables(shellName):

def fish():
variables = sh.execute(["/usr/local/bin/fish", "-c", "set"])
variables = variables.split("\n")
result = []
for variable in variables:
if len(variable):
tmp = variable.split(" ")
result.append({"name": unicode(tmp[0].decode("utf-8")), "value": unicode(" ".join(tmp[1:]).decode("utf-8"))})
return result
def _getVars(cmd):
variables = sh.execute(cmd)
return variables.split(b"\n")

def _split(item, symbol):
tmp = item.split(symbol)
return {"name": unicode(tmp[0].decode("utf-8")), "value": unicode(symbol.join(tmp[1:]).decode("utf-8"))}

def bash():
variables = sh.execute(["/bin/bash", "-ic", "export"])
variables = variables.split("\n")
def execute(shellInfos):
variables = _getVars(shellInfos["cmd"])
result = []
for variable in variables:
if len(variable):
variable = variable.replace("declare -x", "")
tmp = variable.split("=")
result.append({"name": unicode(tmp[0].decode("utf-8")), "value": unicode("=".join(tmp[1:]).decode("utf-8"))})
for pattern in shellInfos["replace"]:
variable = variable.replace(pattern, shellInfos["replace"][pattern])
result.append(_split(variable, shellInfos["separator"]))
return result

sh = shell.Shell()
if shellName in shells:
return locals()[shellName]()
return execute(shells[shellName])
return None

def main(wf):
try:
Expand Down

0 comments on commit 7e7b406

Please sign in to comment.