mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-18 13:55:23 -05:00
commit
56773fe7e7
5 changed files with 34 additions and 6 deletions
|
@ -193,3 +193,8 @@ key_bindings:
|
||||||
mouse_bindings:
|
mouse_bindings:
|
||||||
- { mouse: Middle, action: PasteSelection }
|
- { mouse: Middle, action: PasteSelection }
|
||||||
|
|
||||||
|
|
||||||
|
# Shell
|
||||||
|
#
|
||||||
|
# You can set this to a path to your favorite shell, e.g. /bin/fish
|
||||||
|
shell:
|
||||||
|
|
|
@ -193,3 +193,7 @@ key_bindings:
|
||||||
mouse_bindings:
|
mouse_bindings:
|
||||||
- { mouse: Middle, action: PasteSelection }
|
- { mouse: Middle, action: PasteSelection }
|
||||||
|
|
||||||
|
# Shell
|
||||||
|
#
|
||||||
|
# You can set this to a path to your favorite shell, e.g. /bin/fish
|
||||||
|
shell:
|
||||||
|
|
|
@ -196,6 +196,9 @@ pub struct Config {
|
||||||
#[serde(default="default_mouse_bindings")]
|
#[serde(default="default_mouse_bindings")]
|
||||||
mouse_bindings: Vec<MouseBinding>,
|
mouse_bindings: Vec<MouseBinding>,
|
||||||
|
|
||||||
|
/// Path to a shell program to run on startup
|
||||||
|
shell: Option<PathBuf>,
|
||||||
|
|
||||||
/// Path where config was loaded from
|
/// Path where config was loaded from
|
||||||
config_path: Option<PathBuf>,
|
config_path: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
@ -228,6 +231,7 @@ impl Default for Config {
|
||||||
colors: Default::default(),
|
colors: Default::default(),
|
||||||
key_bindings: Vec::new(),
|
key_bindings: Vec::new(),
|
||||||
mouse_bindings: Vec::new(),
|
mouse_bindings: Vec::new(),
|
||||||
|
shell: None,
|
||||||
config_path: None,
|
config_path: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -879,6 +883,12 @@ impl Config {
|
||||||
.map(|p| p.as_path())
|
.map(|p| p.as_path())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn shell(&self) -> Option<&Path> {
|
||||||
|
self.shell
|
||||||
|
.as_ref()
|
||||||
|
.map(PathBuf::as_path)
|
||||||
|
}
|
||||||
|
|
||||||
fn load_from<P: Into<PathBuf>>(path: P) -> Result<Config> {
|
fn load_from<P: Into<PathBuf>>(path: P) -> Result<Config> {
|
||||||
let path = path.into();
|
let path = path.into();
|
||||||
let raw = Config::read_file(path.as_path())?;
|
let raw = Config::read_file(path.as_path())?;
|
||||||
|
|
|
@ -93,7 +93,7 @@ fn run(mut config: Config, options: cli::Options) -> Result<(), Box<Error>> {
|
||||||
// The pty forks a process to run the shell on the slave side of the
|
// The pty forks a process to run the shell on the slave side of the
|
||||||
// pseudoterminal. A file descriptor for the master side is retained for
|
// pseudoterminal. A file descriptor for the master side is retained for
|
||||||
// reading/writing to the shell.
|
// reading/writing to the shell.
|
||||||
let mut pty = tty::new(display.size());
|
let mut pty = tty::new(&config, display.size());
|
||||||
|
|
||||||
// Create the pseudoterminal I/O loop
|
// Create the pseudoterminal I/O loop
|
||||||
//
|
//
|
||||||
|
|
19
src/tty.rs
19
src/tty.rs
|
@ -25,6 +25,7 @@ use libc::{self, winsize, c_int, pid_t, WNOHANG, WIFEXITED, WEXITSTATUS, SIGCHLD
|
||||||
|
|
||||||
use term::SizeInfo;
|
use term::SizeInfo;
|
||||||
use display::OnResize;
|
use display::OnResize;
|
||||||
|
use config::Config;
|
||||||
|
|
||||||
/// Process ID of child process
|
/// Process ID of child process
|
||||||
///
|
///
|
||||||
|
@ -202,14 +203,22 @@ fn get_pw_entry(buf: &mut [i8; 1024]) -> Passwd {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Exec a shell
|
/// Exec a shell
|
||||||
fn execsh() -> ! {
|
fn execsh(config: &Config) -> ! {
|
||||||
let mut buf = [0; 1024];
|
let mut buf = [0; 1024];
|
||||||
let pw = get_pw_entry(&mut buf);
|
let pw = get_pw_entry(&mut buf);
|
||||||
|
|
||||||
|
let shell = match config.shell() {
|
||||||
|
Some(shell) => match shell.to_str() {
|
||||||
|
Some(shell) => shell,
|
||||||
|
None => die!("Invalid shell value")
|
||||||
|
},
|
||||||
|
None => pw.shell
|
||||||
|
};
|
||||||
|
|
||||||
// setup environment
|
// setup environment
|
||||||
env::set_var("LOGNAME", pw.name);
|
env::set_var("LOGNAME", pw.name);
|
||||||
env::set_var("USER", pw.name);
|
env::set_var("USER", pw.name);
|
||||||
env::set_var("SHELL", pw.shell);
|
env::set_var("SHELL", shell);
|
||||||
env::set_var("HOME", pw.dir);
|
env::set_var("HOME", pw.dir);
|
||||||
env::set_var("TERM", "xterm-256color"); // sigh
|
env::set_var("TERM", "xterm-256color"); // sigh
|
||||||
|
|
||||||
|
@ -223,7 +232,7 @@ fn execsh() -> ! {
|
||||||
}
|
}
|
||||||
|
|
||||||
// pw.shell is null terminated
|
// pw.shell is null terminated
|
||||||
let shell = unsafe { CStr::from_ptr(pw.shell.as_ptr() as *const _) };
|
let shell = unsafe { CStr::from_ptr(shell.as_ptr() as *const _) };
|
||||||
|
|
||||||
let argv = [shell.as_ptr(), ptr::null()];
|
let argv = [shell.as_ptr(), ptr::null()];
|
||||||
|
|
||||||
|
@ -239,7 +248,7 @@ fn execsh() -> ! {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new tty and return a handle to interact with it.
|
/// Create a new tty and return a handle to interact with it.
|
||||||
pub fn new<T: ToWinsize>(size: T) -> Pty {
|
pub fn new<T: ToWinsize>(config: &Config, size: T) -> Pty {
|
||||||
let win = size.to_winsize();
|
let win = size.to_winsize();
|
||||||
|
|
||||||
let (master, slave) = openpty(win.ws_row as _, win.ws_col as _);
|
let (master, slave) = openpty(win.ws_row as _, win.ws_col as _);
|
||||||
|
@ -265,7 +274,7 @@ pub fn new<T: ToWinsize>(size: T) -> Pty {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exec a shell!
|
// Exec a shell!
|
||||||
execsh();
|
execsh(config);
|
||||||
},
|
},
|
||||||
Relation::Parent(pid) => {
|
Relation::Parent(pid) => {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
Loading…
Reference in a new issue