Skip to content

Commit 2eb9456

Browse files
authored
Merge pull request #76 from technocake/feature/multiopen
Open multiple things with a single command
2 parents 9cdc3fd + 9663692 commit 2eb9456

File tree

25 files changed

+369
-278
lines changed

25 files changed

+369
-278
lines changed

.circleci/config.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ jobs:
2727
# fallback to using the latest cache if no exact match is found
2828
- v1-dependencies-
2929

30+
- run:
31+
name: make pyperclip work
32+
command: sudo apt-get install -y xsel
33+
3034
- run:
3135
name: install dependencies
3236
command: |
@@ -65,10 +69,9 @@ jobs:
6569
steps:
6670
- checkout
6771
- run:
68-
name: "probe system"
72+
name: "pyperclip work"
6973
command: |
70-
cat ~/.bashrc
71-
pyenv install --list
74+
sudo apt-get install -y xsel
7275
7376
# - restore_cache:
7477
# keys:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ uninstall:
5252
pip uninstall magicgoto
5353

5454

55-
testcircleci:
55+
circleci:
5656
# Testing circleci tests locally using cli:
5757
# https://circleci.com/docs/2.0/local-cli/
5858
circleci config validate

README.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
## Goto
1+
## Goto
22
v1.5.3
33

4-
*Goto is a magic tool that takes you were you want to be, now.*
4+
*Goto is a magic tool that takes you were you want to be, now.*
55

66
When you are involved in different projects, they all have their own folders, important files, links to good articles or key websites. The problem is that all these are spread out on different locations.
77

@@ -19,10 +19,10 @@ $ goto add github https://github.com/user/your-project
1919
Added magic word github
2020

2121
$ goto github
22-
# opens https://github.com/user/your-project in your browser
22+
# opens https://github.com/user/your-project in your browser
2323
```
2424

25-
### Setup
25+
### Setup
2626

2727
#### Mac OS-X / Linux
2828
```
@@ -37,9 +37,10 @@ Do the same as above, but **open git bash as Administrator**
3737
#### Linux - User Site install
3838
On linux, the recommended way to install goto is by `pip install --user magicgoto`
3939

40+
4041
> This requires that you have your User site bin in your path.
4142
> Usually this is `~/.local/bin`. So adding `PATH="${HOME}/.local/bin:$PATH"` to
42-
> your rcfile should do the trick in most cases.
43+
> your rcfile should do the trick in most cases.
4344
4445

4546
### Commands
@@ -51,6 +52,7 @@ On linux, the recommended way to install goto is by `pip install --user magicgot
5152
```
5253
The basics
5354
goto <magicword> Go to shortcut
55+
goto [<magicword>...] Go to many shortcuts
5456
goto add <magicword> <url or path> Add shortcut
5557
goto update <magicword> <new url/path> Update shortcut
5658
goto rename <magicword> <new name> Rename shortcut
@@ -65,13 +67,12 @@ On linux, the recommended way to install goto is by `pip install --user magicgot
6567
goto open <magicword> Open in finder/file explorer
6668
6769
Launching Code editors
68-
goto subl Opens Sublime Text in code folder*
70+
goto subl Opens Sublime Text in code folder*
6971
goto idea Opens IntelliJ in code folder*
7072
goto vscode Opens Visual Studio Code in code folder*
7173
7274
* requires a magicword named code pointing to a folder.
7375
goto add code <path to folder with code>
74-
7576
```
7677

7778

@@ -122,7 +123,7 @@ You tell Goto with the command:
122123

123124
project add <project-name>
124125

125-
126+
126127

127128

128129

@@ -132,19 +133,19 @@ Define them once, and use them a thousand times. By this command:
132133

133134
goto add <magic-word> <URI>
134135

135-
A **magic-word** is the name of your shortcut.
136+
A **magic-word** is the name of your shortcut.
136137
The **URI** is the target of your shortcut. It could be a file, a directory, a web-url.
137138

138139
##### Examples:
139140

140141
* `goto add github https://github.com/technocake/goto`
141-
* `goto add music ~/the/sound/of/music`
142+
* `goto add music ~/the/sound/of/music`
142143
* `goto add jira http://jira.com/project/X`
143144

144145
First one adds a url to a repo on github relevant to the project.
145146
The second one adds a folder path.
146147

147-
When you activate a project, Goto remembers which project you are thinking about right now.
148+
When you activate a project, Goto remembers which project you are thinking about right now.
148149

149150
Then it makes sense to call the shortcut visualstudio, because it implicit means the visual studio project associated with this project.
150151

@@ -162,3 +163,11 @@ pip uninstall magicgoto
162163
# project data is kept intact in ~/.goto
163164
```
164165

166+
167+
## Features
168+
169+
### Goto many things with one command
170+
171+
![goto-many](./images/goto-many.gif)
172+
173+

bin/goto

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#!/usr/bin/env bash
22

3+
34
# Checking if we are sourced
45
# see: https://stackoverflow.com/questions/2683279/how-to-detect-if-a-script-is-being-sourced
56
([[ -n $ZSH_EVAL_CONTEXT && $ZSH_EVAL_CONTEXT =~ :file$ ]] ||
67
[[ -n $BASH_VERSION ]] && (return 0 2>/dev/null)) && _GOTO_IS_SOURCED=0 || _GOTO_IS_SOURCED=1
78

9+
810
. _gotoutils
11+
load_gotopath
912

1013

1114
function _goto_main {
@@ -25,32 +28,11 @@ function _goto_main {
2528
# Else: print warning. NO EXIT statement.
2629
if [[ $_GOTO_IS_SOURCED -eq 0 ]]; then
2730

28-
# GOTOPATH may be set from environment,
29-
# if not default to ~/.goto
30-
if [[ -z "$GOTOPATH" ]]; then
31-
GOTOPATH="${HOME}/.goto"
32-
fi
33-
34-
3531
PROJECT=$(cat "${GOTOPATH}/active-project")
3632

3733
# Catching deactivated state
38-
# TODO: make a better way to print to stderr
3934
if [ -z "$PROJECT" ]; then
40-
echo "Ah hoy!" >&2
41-
echo >&2
42-
echo "Goto has no project context set." >&2
43-
echo >&2
44-
echo "An example project is bundled with goto, it is called goto." >&2
45-
echo "You may try it by typing:" >&2
46-
echo >&2
47-
echo " project goto" >&2
48-
echo >&2
49-
echo "Other usefull commands to work with projects:" >&2
50-
echo " create project: project add <project-name>" >&2
51-
echo " more help: project help" >&2
52-
53-
35+
_no_project
5436
return 1
5537
fi
5638

@@ -86,7 +68,6 @@ function _goto_main {
8668
fi
8769

8870

89-
9071
# General case
9172
if [ -n "$(command -v the_real_goto.py)" ]; then
9273
the_real_goto.py "$PROJECT" "$@"
@@ -96,14 +77,34 @@ function _goto_main {
9677
fi
9778

9879
else
99-
echo "Ah hoy!" >&2
100-
echo >&2
101-
echo "In order to make goto work properly, run this command now:" >&2
102-
echo >&2
103-
echo " install_goto" >&2
104-
echo >&2
80+
_not_installed
10581
exit 1
10682
fi
10783
}
10884

85+
function _no_project {
86+
echo "Ah hoy!" >&2
87+
echo >&2
88+
echo "Goto has no project context set." >&2
89+
echo >&2
90+
echo "An example project is bundled with goto, it is called goto." >&2
91+
echo "You may try it by typing:" >&2
92+
echo >&2
93+
echo " project goto" >&2
94+
echo >&2
95+
echo "Other usefull commands to work with projects:" >&2
96+
echo " create project: project add <project-name>" >&2
97+
echo " more help: project help" >&2
98+
}
99+
100+
function _not_installed {
101+
echo "Ah hoy!" >&2
102+
echo >&2
103+
echo "In order to make goto work properly, run this command now:" >&2
104+
echo >&2
105+
echo " install_goto" >&2
106+
echo >&2
107+
}
108+
109+
109110
_goto_main "$@"

goto/commands/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
from .copy import copy
77
from .list import list
88
from .migrate import migrate
9+
from .check_migrate import check_migrate
910
from .subl import subl
1011
from .vscode import vscode
1112
from .intellij import intellij
1213
from .open import open
13-
from .cd import cd
1414
from .default import default
1515
from .rename import rename

goto/commands/add.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from __future__ import unicode_literals
33
from ..gotomagic.text import GotoError, GotoWarning
44

5-
def add(magic, args):
5+
6+
def add(magic, command, args, options):
67
"""
78
Add magicword
89
"""
@@ -18,7 +19,12 @@ def add(magic, args):
1819
magicword = args[0]
1920
uri = args[1]
2021

21-
magic.add_shortcut(magicword, uri)
22-
magic.save()
22+
err = magic.add_shortcut(magicword, uri)
23+
if err:
24+
return None, err
25+
26+
err = magic.save()
27+
if err:
28+
return None, err
2329

2430
return 'Added magic word {}'.format(magicword), None

goto/commands/cd.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

goto/commands/check_migrate.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# coding: utf-8
2+
from __future__ import unicode_literals
3+
4+
from ..gotomagic.text import GotoError, GotoWarning
5+
from ..gotomagic.utils import detect_unmigrated_data
6+
7+
8+
def check_migrate(magic, command, args, options):
9+
''' checks if we need to migrate underlaying data structure in goto'''
10+
11+
if detect_unmigrated_data():
12+
return None, GotoWarning('data_not_migrated')
13+
else:
14+
return "Nothing to migrate", None

goto/commands/copy.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@
44
from ..gotomagic.text import GotoError, GotoWarning
55

66

7-
def copy(magic, args):
7+
def copy(magic, command, args, options):
88
"""
99
Copy uri to clipboard
1010
"""
1111

1212
if (len(args) == 0):
13-
return None, GotoWarning("missing_magicword", command='cd')
13+
return None, GotoWarning("missing_magicword", command='copy')
1414

1515
word = args[0]
16-
url = str(magic.get_uri(word))
16+
uri = str(magic.get_uri(word))
1717

18-
pyperclip.copy(url)
19-
20-
return None, None
18+
if uri:
19+
pyperclip.copy(uri)
20+
return "Copied uri to clipboard", None
21+
else:
22+
return None, GotoWarning("magicword_does_not_exist", magicword=word)

goto/commands/default.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
11
import webbrowser
22
from ..gotomagic.utils import is_file
3-
from ..gotomagic.text import GotoWarning
3+
from ..gotomagic.text import GotoWarning, GotoError
44
from .open import open
55

66

7-
def default(magic, magicword):
7+
def default(magic, command, args, options):
88
"""
99
Default behaviour when no commands are found in the first argument
1010
"""
11+
verbose = '--verbose' in options or '-v' in options
1112

12-
url = magic.get_uri(magicword)
13-
# for this time beeing, the get_uri is exiting and printing warning itself
14-
# TODO: it would be better to have that kind of logic up in here.
13+
output = ""
14+
for magicword in args:
15+
uri = magic.get_uri(magicword)
1516

16-
if is_file(url):
17-
return open(magic, [magicword])
18-
else:
19-
webbrowser.open(magic[magicword])
17+
if uri is None:
18+
return None, GotoWarning('magicword_does_not_exist', magicword=magicword) # noqa
2019

21-
return None, None
20+
if is_file(uri):
21+
_output, err = open(magic, '', [magicword], verbose)
22+
if err:
23+
return None, err
24+
output += "%s\n" % _output
25+
else:
26+
try:
27+
webbrowser.open_new_tab(uri)
28+
output += "%s\n" % uri
29+
except webbrowser.Error:
30+
return None, GotoError('open_browser_tab_error')
31+
32+
return output if verbose else None, None

0 commit comments

Comments
 (0)