Make terminal start with current directory and support any command

from elisp side.
master
Andy Stewart 6 years ago
parent a306a6fb20
commit 3241bc15d5
  1. 27
      app/terminal/buffer.py
  2. 9
      eaf.el

@ -37,9 +37,16 @@ class AppBuffer(BrowserBuffer):
self.port = get_free_port()
self.url = url
argument_list = arguments.split("")
self.command = argument_list[0]
self.start_directory = argument_list[1]
# Start wetty process.
self.background_process = subprocess.Popen(
"wetty -p {0} --base / --sshuser {1} --sshauth publickey -c {2}".format(self.port, getpass.getuser(), os.environ["SHELL"]),
"wetty -p {0} --base / --sshuser {1} --sshauth publickey -c {2}".format(
self.port,
getpass.getuser(),
"'{}'".format(self.command)),
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=True)
@ -53,9 +60,21 @@ class AppBuffer(BrowserBuffer):
def load_wetty_server(self):
self.buffer_widget.setUrl(QUrl("http://localhost:{0}".format(self.port)))
paths = os.path.split(self.url)
if len(paths) > 0:
self.change_title(paths[-1])
self.update_title()
def update_title(self):
self.change_title("{0}-{1}".format(
os.path.basename(os.path.normpath(os.path.expanduser(self.start_directory))),
self.random_string()
))
def before_destroy_buffer(self):
os.kill(self.background_process.pid, signal.SIGTERM)
def random_string(self):
import hashlib
import time
hash = hashlib.sha1()
hash.update(str(time.time()).encode("utf-8"))
return hash.hexdigest()[:4]

@ -1475,7 +1475,7 @@ This function works best if paired with a fuzzy search package."
(if history-file-exists
(mapcar
(lambda (h) (when (string-match history-pattern h)
(format "[%s] ⇰ %s" (match-string 1 h) (match-string 2 h))))
(format "[%s] ⇰ %s" (match-string 1 h) (match-string 2 h))))
(with-temp-buffer (insert-file-contents browser-history-file-path)
(split-string (buffer-string) "\n" t)))
nil)))
@ -1533,7 +1533,12 @@ choose a search engine defined in `eaf-browser-search-engines'"
(defun eaf-open-terminal ()
"Open EAF terminal application."
(interactive)
(eaf-open (eaf--generate-terminal-buffer-name) "terminal"))
(eaf-open (eaf--generate-terminal-buffer-name)
"terminal"
(format "%sᛡ%s" (eaf--generate-terminal-command) default-directory)))
(defun eaf--generate-terminal-command ()
(format "cd %s && exec %s --login" default-directory (getenv "SHELL")))
(defun eaf--generate-terminal-buffer-name ()
(format "%s-%04x" "eaf-terminal" (random (expt 16 4))))

Loading…
Cancel
Save