Add an option to override the default shell

This commit is contained in:
Kovid Goyal 2018-01-09 16:28:46 +05:30
parent 5d082d8d5a
commit 6ad49bd7fb
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 19 additions and 7 deletions

View File

@ -104,6 +104,10 @@ click_interval 0.5
# database will be matched. # database will be matched.
select_by_word_characters :@-./_~?&=%+# select_by_word_characters :@-./_~?&=%+#
# The shell program to execute. The default value of . means
# to use whatever shell is set as the default shell for the current user.
shell .
# Hide mouse cursor after the specified number of seconds of the mouse not being used. Set to # Hide mouse cursor after the specified number of seconds of the mouse not being used. Set to
# zero to disable mouse cursor hiding. # zero to disable mouse cursor hiding.
mouse_hide_wait 3.0 mouse_hide_wait 3.0

View File

@ -64,6 +64,15 @@ class Session:
self.tabs[-1].cwd = val self.tabs[-1].cwd = val
def resolved_shell(opts):
ans = opts.shell
if ans == '.':
ans = [shell_path]
else:
ans = shlex.split(ans)
return ans
def parse_session(raw, opts): def parse_session(raw, opts):
ans = Session() ans = Session()
ans.add_tab(opts) ans.add_tab(opts)
@ -90,7 +99,7 @@ def parse_session(raw, opts):
raise ValueError('Unknown command in session file: {}'.format(cmd)) raise ValueError('Unknown command in session file: {}'.format(cmd))
for t in ans.tabs: for t in ans.tabs:
if not t.windows: if not t.windows:
t.windows.append([shell_path]) t.windows.append(resolved_shell(opts))
return ans return ans
@ -108,7 +117,7 @@ def create_session(opts, args=None, special_window=None, cwd_from=None):
ans.add_tab(opts) ans.add_tab(opts)
ans.tabs[-1].layout = current_layout ans.tabs[-1].layout = current_layout
if special_window is None: if special_window is None:
cmd = args.args if args and args.args else [shell_path] cmd = args.args if args and args.args else resolved_shell(opts)
from kitty.tabs import SpecialWindow from kitty.tabs import SpecialWindow
k = {'cwd_from': cwd_from} k = {'cwd_from': cwd_from}
if getattr(args, 'title', None): if getattr(args, 'title', None):

View File

@ -9,15 +9,14 @@ from functools import partial
from .borders import Borders from .borders import Borders
from .child import Child from .child import Child
from .config import build_ansi_color_table from .config import build_ansi_color_table
from .constants import ( from .constants import WindowGeometry, appname, get_boss, is_macos, is_wayland
WindowGeometry, appname, get_boss, is_macos, is_wayland, shell_path
)
from .fast_data_types import ( from .fast_data_types import (
DECAWM, Screen, add_tab, glfw_post_empty_event, remove_tab, remove_window, DECAWM, Screen, add_tab, glfw_post_empty_event, remove_tab, remove_window,
set_active_tab, set_active_window, set_tab_bar_render_data, swap_tabs, set_active_tab, set_active_window, set_tab_bar_render_data, swap_tabs,
swap_windows, viewport_for_window, x11_window_id swap_windows, viewport_for_window, x11_window_id
) )
from .layout import Rect, all_layouts from .layout import Rect, all_layouts
from .session import resolved_shell
from .utils import color_as_int from .utils import color_as_int
from .window import Window, calculate_gl_geometry from .window import Window, calculate_gl_geometry
@ -118,9 +117,9 @@ class Tab: # {{{
def launch_child(self, use_shell=False, cmd=None, stdin=None, cwd_from=None, cwd=None): def launch_child(self, use_shell=False, cmd=None, stdin=None, cwd_from=None, cwd=None):
if cmd is None: if cmd is None:
if use_shell: if use_shell:
cmd = [shell_path] cmd = resolved_shell(self.opts)
else: else:
cmd = self.args.args or [shell_path] cmd = self.args.args or resolved_shell(self.opts)
env = {} env = {}
if not is_macos and not is_wayland: if not is_macos and not is_wayland:
try: try: