Skip to content

Commit

Permalink
Windows bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
htngr committed Oct 11, 2024
1 parent cd28439 commit efa65d4
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 21 deletions.
2 changes: 1 addition & 1 deletion codchi/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions codchi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "codchi"
build = "build/main.rs"
version = "0.2.2"
version = "0.2.3"
edition = "2021"
rust-version = "1.80.0"
resolver = "2"
Expand Down Expand Up @@ -52,13 +52,13 @@ tao = { version = "0.30", default-features = false }
fs4 = { version = "0.9", features = ["sync"] }
git-url-parse = "0.4.5"
toml_edit = { version = "0.22.22", features = ["serde"] }
which = "6.0.3"
# clap-help = "1.3.0"
# termimad = "0.30.0"

[target.'cfg(unix)'.dependencies]
indoc = "2.0.5"
nix = { version = "0.29.0", features = ["user", "hostname"] }
which = "6.0.3"

[target.'cfg(windows)'.dependencies]
known-folders = "1.2.0"
Expand Down
2 changes: 2 additions & 0 deletions codchi/src/module.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::cli::{InputOptions, ModuleAttrPath, ModuleName, NixpkgsLocation, RelativePath};
use crate::config::git_url::{GitUrl, Scheme};
use crate::consts;
use crate::consts::user::DEFAULT_HOME;
use crate::logging::{log_progress, set_progress_status};
use crate::platform::{nix::NixDriver, *};
use crate::progress_scope;
Expand Down Expand Up @@ -664,6 +665,7 @@ nix run nixpkgs#git -- checkout {commit}
.cmd()
.script(cmd)
.with_user(platform::LinuxUser::Default)
.with_cwd(DEFAULT_HOME.clone())
.output_ok_streaming(channel().1, |line| {
log_progress("git clone", log::Level::Info, &line)
})?;
Expand Down
4 changes: 0 additions & 4 deletions codchi/src/platform/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,6 @@ pub trait Host: Sized {
use windows::Win32::System::Threading::*;
cmd.creation_flags(CREATE_NEW_PROCESS_GROUP.0 | CREATE_NO_WINDOW.0);
}
// #[cfg(target_family = "unix")]
// {
// cmd.creation_flags();
// }
cmd.spawn()?;
anyhow::Ok(())
}
Expand Down
33 changes: 23 additions & 10 deletions codchi/src/platform/windows/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use crate::{
use anyhow::{Context, Result};
use known_folders::{get_known_folder_path, KnownFolder};
use mslnk::ShellLink;
use std::{env, fs, os::windows::process::CommandExt, process::Command};
use std::{collections::HashMap, env, fs, os::windows::process::CommandExt, process::Command};
use sysinfo::System;
use windows::Win32::System::Threading::{
CREATE_NEW_CONSOLE, CREATE_NEW_PROCESS_GROUP, CREATE_NO_WINDOW,
CREATE_NEW_PROCESS_GROUP, CREATE_NO_WINDOW, DETACHED_PROCESS,
};
// use winreg::{enums::HKEY_CURRENT_USER, RegKey};

Expand Down Expand Up @@ -151,14 +151,27 @@ impl Host for HostImpl {
}

fn open_terminal(&self, cmd: &[&str]) -> Result<()> {
if let Some((cmd, args)) = cmd.split_first() {
Command::new(cmd)
.args(args)
.creation_flags(CREATE_NEW_CONSOLE.0)
.spawn()?;
} else {
anyhow::bail!("Failed to open terminal with an empty command");
let mut terms = vec![
("wt.exe", vec![]),
("alacritty.exe", vec!["-e"]),
("wezterm.exe", vec!["-e"]),
];
// if let Some((cmd, args)) = cmd.split_first() {
// Command::new(cmd)
// .args(args)
// .creation_flags(DETACHED_PROCESS.0)
// .spawn()?;
for (term, args) in terms {
if let Ok(path) = which::which(term) {
Command::new(path).args(args).args(cmd).spawn()?;
return Ok(());
}
}
Ok(())

Command::new("cmd.exe").arg("/C").args(cmd).spawn()?;
anyhow::bail!("Could not find a terminal.")
// } else {
// anyhow::bail!("Failed to open terminal with an empty command");
// }
}
}
19 changes: 15 additions & 4 deletions docs/src/docs/start/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,25 @@ download and install a newer codchi.msix at any time.

### Shell Completions

On some Windows Systems running PowerShell scripts is considered a security vulnerability and often completely disabled. Therefore Codchi doesn't try to automatically run PowerShell Scripts and you have to manually add the completions:
On some Windows Systems running PowerShell scripts is considered a security vulnerability and often completely disabled. Therefore Codchi doesn't try to automatically run PowerShell scripts and you have to manually add the following to the end of your PowerShell configuration (find it by running `$PROFILE` in PowerShell):

```ps1
# In PowerShell:
mkdir $env:USERPROFILE\Documents\WindowsPowerShell
echo 'codchi completion powershell | invoke-expression' >> $PROFILE
Invoke-Expression (& codchi completion powershell | Out-String)
```

#### Further Recommendations

- For better tab complete and history search:
```ps1
# Shows navigable menu of all options when hitting tab
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
# Autocompletion for arrow keys (when something was already typed)
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward
```
- Install [Starship.rs](https://starship.rs/) for a better prompt


## Linux

Expand Down

0 comments on commit efa65d4

Please sign in to comment.