From 0cc4bbbcd79226ae0bdd22dc34f12cf561486d28 Mon Sep 17 00:00:00 2001
From: Aleksandar Krsteski <alekrsteski@gmail.com>
Date: Wed, 4 Mar 2009 00:58:58 +0100
Subject: [PATCH] Use user shell by default.
Guake should use user shell defined for the user in /etc/passwd by
default. Also add an option to select user shell in preferences so the
user can return to user shell option after selection another shell.
Implementation uses the user shell by passing None to vte command
argument. Also fallback to user shell if default_shell option defines
invalid path.
---
data/guake.schemas | 7 ++++---
src/guake.py | 21 +++++++++++++++------
src/prefs.py | 17 +++++++++++++++--
3 files changed, 34 insertions(+), 11 deletions(-)
diff --git a/data/guake.schemas b/data/guake.schemas
index f439dd5..1f69379 100644
|
a
|
b
|
|
| 6 | 6 | <applyto>/apps/guake/general/default_shell</applyto> |
| 7 | 7 | <owner>guake</owner> |
| 8 | 8 | <type>string</type> |
| 9 | | <default>/bin/bash</default> |
| | 9 | <default></default> |
| 10 | 10 | <locale name="C"> |
| 11 | 11 | <short>Path to the default shell.</short> |
| 12 | | <long>Path to the default shell. If an invalid shell is placed |
| 13 | | here, guake will fallback to bash.</long> |
| | 12 | <long>Path to the default shell. Set to empty to |
| | 13 | use default user shell. If invalid path is set |
| | 14 | here, guake will fallback to user shell.</long> |
| 14 | 15 | </locale> |
| 15 | 16 | </schema> |
| 16 | 17 | |
diff --git a/src/guake.py b/src/guake.py
index 114c1d7..985045f 100644
|
a
|
b
|
|
| 894 | 894 | """Return all parameters to be passed to the fork_command |
| 895 | 895 | method of a vte terminal. |
| 896 | 896 | """ |
| 897 | | argv = None |
| 898 | | shell = self.client.get_string(KEY('/general/default_shell')) or 'sh' |
| | 897 | # use dictionary to pass named params to work around command |
| | 898 | # parameter in fork_command not accepting None as argument. |
| | 899 | # When we pass None as command, vte starts the default user shell. |
| | 900 | params = {} |
| | 901 | |
| | 902 | shell = self.client.get_string(KEY('/general/default_shell')) |
| | 903 | if shell and os.path.exists(shell): |
| | 904 | params['command'] = shell |
| | 905 | |
| 899 | 906 | login_shell = self.client.get_bool(KEY('/general/use_login_shell')) |
| 900 | 907 | if login_shell: |
| 901 | | argv = ['-'] |
| | 908 | params['argv'] = ['-'] |
| | 909 | |
| | 910 | params['directory'] = self.get_current_dir() |
| | 911 | params['loglastlog'] = login_shell |
| 902 | 912 | |
| 903 | | directory = self.get_current_dir() |
| 904 | | return shell, argv, None, directory, login_shell, False, False |
| | 913 | return params |
| 905 | 914 | |
| 906 | 915 | def add_tab(self, *args): |
| 907 | 916 | """Adds a new tab to the terminal notebook. |
| … |
… |
|
| 915 | 924 | last_added = len(self.term_list) |
| 916 | 925 | self.term_list.append(box.terminal) |
| 917 | 926 | |
| 918 | | pid = box.terminal.fork_command(*self.get_fork_params()) |
| | 927 | pid = box.terminal.fork_command(**self.get_fork_params()) |
| 919 | 928 | self.pid_list.append(pid) |
| 920 | 929 | |
| 921 | 930 | # Adding a new radio button to the tabbar |
diff --git a/src/prefs.py b/src/prefs.py
index d4ab770..3045c0b 100644
|
a
|
b
|
|
| 38 | 38 | # rest of the combo too. |
| 39 | 39 | SHELLS_FILE = '/etc/shells' |
| 40 | 40 | |
| | 41 | # string to show in prefereces dialog for user shell option |
| | 42 | USER_SHELL_VALUE = _('<user shell>') |
| | 43 | |
| 41 | 44 | # translating our types to vte types |
| 42 | 45 | ERASE_BINDINGS = {'ASCII DEL': 'ascii-delete', |
| 43 | 46 | 'Escape sequence': 'delete-sequence', |
| … |
… |
|
| 98 | 101 | if not citer: |
| 99 | 102 | return |
| 100 | 103 | shell = combo.get_model().get_value(citer, 0) |
| 101 | | self.client.set_string(KEY('/general/default_shell'), shell) |
| | 104 | # we unset the value (restore to default) when user chooses to use |
| | 105 | # user shell as guake shell interpreter. |
| | 106 | if shell == USER_SHELL_VALUE: |
| | 107 | self.client.unset(KEY('/general/default_shell')) |
| | 108 | else: |
| | 109 | self.client.set_string(KEY('/general/default_shell'), shell) |
| 102 | 110 | |
| 103 | 111 | def on_use_login_shell_toggled(self, chk): |
| 104 | 112 | """Changes the activity of use_login_shell in gconf |
| … |
… |
|
| 358 | 366 | """ |
| 359 | 367 | # default_shell |
| 360 | 368 | combo = self.get_widget('default_shell') |
| | 369 | # get the value for defualt shell. If unset, set to USER_SHELL_VALUE. |
| | 370 | value = self.client.get_string(KEY('/general/default_shell')) or \ |
| | 371 | USER_SHELL_VALUE |
| 361 | 372 | for i in combo.get_model(): |
| 362 | | if i[0] == self.client.get_string(KEY('/general/default_shell')): |
| | 373 | if i[0] == value: |
| 363 | 374 | combo.set_active_iter(i.iter) |
| 364 | 375 | |
| 365 | 376 | # login shell |
| … |
… |
|
| 449 | 460 | fill the default_shell combobox. |
| 450 | 461 | """ |
| 451 | 462 | cb = self.get_widget('default_shell') |
| | 463 | # append user shell as first option |
| | 464 | cb.append_text(USER_SHELL_VALUE) |
| 452 | 465 | if os.path.exists(SHELLS_FILE): |
| 453 | 466 | lines = open(SHELLS_FILE).readlines() |
| 454 | 467 | for i in lines: |