MCPcopy Create free account
hub / github.com/1jehuang/jcode / write_linux_launch_scripts

Function write_linux_launch_scripts

crates/jcode-setup-hints/src/lib.rs:2065–2106  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2063/// user's terminal running jcode, so compositor bind lines stay trivial.
2064#[cfg(target_os = "linux")]
2065fn write_linux_launch_scripts() -> Result<Vec<linux_env::ScriptBind>> {
2066 let hotkey_dir = mac_hotkey_support_dir()?;
2067 std::fs::create_dir_all(&hotkey_dir)?;
2068
2069 let exe_path = std::env::current_exe()
2070 .map(|p| p.to_string_lossy().into_owned())
2071 .unwrap_or_else(|_| "jcode".to_string());
2072 let terminal = linux_launch_terminal();
2073 let last_dir = mac_hotkey_last_dir_file()?.to_string_lossy().into_owned();
2074 let last_repo = mac_hotkey_last_repo_file()?.to_string_lossy().into_owned();
2075
2076 let config = load_launch_hotkeys_config();
2077 let resolved =
2078 launch_hotkeys::resolve_launch_hotkeys(&config, &exe_path, &last_dir, &last_repo);
2079
2080 let mut binds = Vec::with_capacity(resolved.len());
2081 for entry in resolved {
2082 let Some(chord) = keymap::KeyChord::parse(&entry.chord) else {
2083 continue;
2084 };
2085 let self_dev = entry.args.iter().any(|a| a == "self-dev");
2086 let exec = linux_env::terminal_exec_command(&terminal, &exe_path, &entry.chord, self_dev);
2087 let script_body = format!(
2088 "#!/bin/sh\n# Auto-generated by jcode setup-hotkey; re-run it to refresh.\n{cd}exec {exec}\n",
2089 cd = entry.cd_prefix,
2090 );
2091 let script_path = hotkey_dir.join(&entry.script_file_name);
2092 std::fs::write(&script_path, script_body)?;
2093 #[cfg(unix)]
2094 {
2095 use std::os::unix::fs::PermissionsExt;
2096 std::fs::set_permissions(&script_path, std::fs::Permissions::from_mode(0o755))?;
2097 }
2098 binds.push(linux_env::ScriptBind {
2099 chord,
2100 script: script_path.to_string_lossy().into_owned(),
2101 label: entry.label,
2102 self_dev,
2103 });
2104 }
2105 Ok(binds)
2106}
2107
2108/// Timestamped backup matching the `.bak-jcode-*` convention, taken before
2109/// modifying a user's compositor config. Best-effort.

Calls 13

mac_hotkey_support_dirFunction · 0.85
linux_launch_terminalFunction · 0.85
mac_hotkey_last_dir_fileFunction · 0.85
resolve_launch_hotkeysFunction · 0.85
terminal_exec_commandFunction · 0.85
writeFunction · 0.85
anyMethod · 0.80
iterMethod · 0.80
parseFunction · 0.50
lenMethod · 0.45

Tested by

no test coverage detected