Skip to content

Commit 16bde81

Browse files
Merge pull request #103 from mg979/master
Option to open file in terminal editor
2 parents 2906f5f + b34b370 commit 16bde81

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ Functions of the items are as follows.
129129
* `"filebrowser"` application to handle opening folders
130130
* `"webbrowser"` application to handle opening urls (web browser)
131131
* `"terminal"` terminal emulator application
132+
* `"terminal_editor"` application used to edit files directly in the terminal
132133
* `"indicator_submenu"` symbol to indicate a submenu item in the cache
133134
* `"indicator_edit"` symbol to indicate an item will launch an editor in the cache
134135
* `"indicator_alias"` symbol to indicate an aliased command in the cache
@@ -195,7 +196,8 @@ Dmenu-extended understands the following modifier characters when entering a spe
195196
1. **+** (plus) - Manually add an entry to the cache
196197
2. **-** (minus) - Remove a manually added entry from the cache
197198
3. **:** (colon) - Open with
198-
4. **;** (semi-colon) - Execute in terminal
199+
4. **@** (at) - Open in default terminal editor
200+
5. **;** (semi-colon) - Execute in terminal
199201

200202
These modifiers are entered into the menu; examples follow.
201203

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

233+
### **@** (at) - Open in terminal editor
234+
235+
Suffix to open the chosen file inside the preferred editor in a terminal window. 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.
236+
For instance:
237+
238+
* `/home/me/Documents/writing.txt@`
239+
231240
### **;** (semi-colon) - Execute in terminal
232241
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.
233242

dmenu_extended/main.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
"filebrowser": "xdg-open", # Program to handle opening paths
149149
"webbrowser": "xdg-open", # Program to hangle opening urls
150150
"terminal": "xterm", # Terminal
151+
"terminal_editor": "vim", # Terminal editor
151152
"indicator_submenu": "->", # Symbol to indicate a submenu item
152153
"indicator_edit": "*", # Symbol to indicate an item will launch an editor
153154
"indicator_alias": "", # Symbol to indecate an aliased command
@@ -587,6 +588,27 @@ def open_terminal(self, command, hold=False, direct=False):
587588
os.system(self.prefs['terminal'] + ' -e ' + sh_command_file)
588589

589590

591+
def open_in_terminal_editor(self, path):
592+
if not os.path.exists(path):
593+
if d.debug:
594+
print("Open in the default terminal editor...")
595+
print(str(path) + ": path doesn't exist")
596+
return
597+
598+
cmd = "%s -e '%s %s'" % (
599+
d.prefs['terminal'],
600+
d.prefs['terminal_editor'],
601+
path.replace(' ', '\\ ')
602+
)
603+
604+
if d.debug:
605+
print("Open in the default terminal editor...")
606+
print("Terminal will be held open upon command finishing")
607+
print("Command is: " + str(cmd))
608+
609+
return d.execute(cmd, False)
610+
611+
590612
def open_file(self, path):
591613
self.load_preferences()
592614
if self.debug:
@@ -1531,7 +1553,9 @@ def handle_command(d, out):
15311553
out = os.path.expanduser(out)
15321554
if d.debug:
15331555
print("Tilda found, expanding to " + str(out))
1534-
if out[-1] == ';':
1556+
if out[-1] == '@':
1557+
d.open_in_terminal_editor(out[:-1])
1558+
elif out[-1] == ';':
15351559
terminal_hold = False
15361560
out = out[:-1]
15371561
if out[-1] == ';':

0 commit comments

Comments
 (0)