Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to open file in terminal editor #103

Merged
merged 2 commits into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ Functions of the items are as follows.
* `"filebrowser"` application to handle opening folders
* `"webbrowser"` application to handle opening urls (web browser)
* `"terminal"` terminal emulator application
* `"terminal_editor"` application used to edit files directly in the terminal
* `"indicator_submenu"` symbol to indicate a submenu item in the cache
* `"indicator_edit"` symbol to indicate an item will launch an editor in the cache
* `"indicator_alias"` symbol to indicate an aliased command in the cache
Expand Down Expand Up @@ -195,7 +196,8 @@ Dmenu-extended understands the following modifier characters when entering a spe
1. **+** (plus) - Manually add an entry to the cache
2. **-** (minus) - Remove a manually added entry from the cache
3. **:** (colon) - Open with
4. **;** (semi-colon) - Execute in terminal
4. **@** (at) - Open in default terminal editor
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a note that the @ symbol must come at the end of the command?

5. **;** (semi-colon) - Execute in terminal

These modifiers are entered into the menu; examples follow.

Expand Down Expand Up @@ -228,6 +230,10 @@ There are a few different ways to use the colon operator, summarised by example
* `/home/me/Documents/writing.txt:gedit` - Open this file with gedit.
* `gedit:/home/me/Documents/writing.txt` - Open this file with gedit.

### **@** (at) - Open in terminal editor

Default editor is set to `vim`, but it can be changed in the preferences (`"terminal_editor"`). The terminal window is closed as soon as the application is exited.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you could put an example in here for the way to use the operator like the : operator (above) I think that would help people understand how to use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added an example, since also : and ; are suffixes, I thought it was not necessary. How does it look now?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! Thank you :)


### **;** (semi-colon) - Execute in terminal
Dmenu-extended doesn't know when the application you enter needs to be executed in a terminal window. To tell dmenu-extended to launch the following in a terminal, append a semi-colon to the end. Once the terminal program has exited the terminal will close.

Expand Down
26 changes: 25 additions & 1 deletion dmenu_extended/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
"filebrowser": "xdg-open", # Program to handle opening paths
"webbrowser": "xdg-open", # Program to hangle opening urls
"terminal": "xterm", # Terminal
"terminal_editor": "vim", # Terminal editor
"indicator_submenu": "->", # Symbol to indicate a submenu item
"indicator_edit": "*", # Symbol to indicate an item will launch an editor
"indicator_alias": "", # Symbol to indecate an aliased command
Expand Down Expand Up @@ -587,6 +588,27 @@ def open_terminal(self, command, hold=False, direct=False):
os.system(self.prefs['terminal'] + ' -e ' + sh_command_file)


def open_in_terminal_editor(self, path):
if not os.path.exists(path):
if d.debug:
print("Open in the default terminal editor...")
print(str(path) + ": path doesn't exist")
return

cmd = "%s -e '%s %s'" % (
d.prefs['terminal'],
d.prefs['terminal_editor'],
path.replace(' ', '\\ ')
)

if d.debug:
print("Open in the default terminal editor...")
print("Terminal will be held open upon command finishing")
print("Command is: " + str(cmd))

return d.execute(cmd, False)


def open_file(self, path):
self.load_preferences()
if self.debug:
Expand Down Expand Up @@ -1531,7 +1553,9 @@ def handle_command(d, out):
out = os.path.expanduser(out)
if d.debug:
print("Tilda found, expanding to " + str(out))
if out[-1] == ';':
if out[-1] == '@':
d.open_in_terminal_editor(out[:-1])
elif out[-1] == ';':
terminal_hold = False
out = out[:-1]
if out[-1] == ';':
Expand Down