<commit_before>//#![feature(convert)]

//extern crate std;
extern crate libc;

use std::process::Command;
use std::str;
use std::option::Option;
use std::collections::BTreeSet;
use libc::{execvp, perror};
use std::ptr;
use std::env;
use std::ffi::CString;


fn detached_session_number(line: &str) -> Option<usize> {
    if line.ends_with("(attached)") {
        None
    } else {
        line.split(':').next().and_then(|s| s.parse().ok() )
    }
}

fn detached_sessions(output: &str) -> BTreeSet<usize> {
    output.lines().filter_map(|line| {
            detached_session_number(line)
    }).collect()
}

// XXX: Conversion convenience function until rust allows
//   #![feature(convert)] and
//   .to_cstring
fn c_string_or_bust(arg: &str, error: &str) -> CString {
    let bytes: Vec<u8> = arg.bytes().collect();
    CString::new(bytes).ok().expect(error)
}

fn exec_program(program: &str, args: &[&str]) {
    let c_program = c_string_or_bust(program, "Program name isn't unicode").as_ptr();
    // I don't much care about the ownership of the strings here
    // at this point, so let's just fail if execvp isn't working.
    unsafe {
        let mut c_args = vec![];
        for &arg in args.iter() {
            c_args.push(c_string_or_bust(arg, "Can't with string that aren't valid Unicode").as_ptr());
        }
        c_args.push(ptr::null());
        execvp(c_program, c_args.as_mut_ptr());
        perror(c_string_or_bust("Running tmux failed:", "Invalid text").as_ptr());
    }
    panic!("Oh noes, couldn't exec.");
}

fn prepare_environment() {
    let path = match env::var("PATH") {
        Ok(path) => path + ":/usr/local/bin",
        _ => "/bin:/usr/bin:/usr/local/bin".to_string()
    };
    env::set_var("PATH", &path);<commit_msg>Use env::join_paths to construct a nice PATH<commit_after>//#![feature(convert)]

//extern crate std;
extern crate libc;

use std::process::Command;
use std::str;
use std::option::Option;
use std::collections::BTreeSet;
use libc::{execvp, perror};
use std::ptr;
use std::env;
use std::path::PathBuf;
use std::ffi::CString;


fn detached_session_number(line: &str) -> Option<usize> {
    if line.ends_with("(attached)") {
        None
    } else {
        line.split(':').next().and_then(|s| s.parse().ok() )
    }
}

fn detached_sessions(output: &str) -> BTreeSet<usize> {
    output.lines().filter_map(|line| {
            detached_session_number(line)
    }).collect()
}

// XXX: Conversion convenience function until rust allows
//   #![feature(convert)] and
//   .to_cstring
fn c_string_or_bust(arg: &str, error: &str) -> CString {
    let bytes: Vec<u8> = arg.bytes().collect();
    CString::new(bytes).ok().expect(error)
}

fn exec_program(program: &str, args: &[&str]) {
    let c_program = c_string_or_bust(program, "Program name isn't unicode").as_ptr();
    // I don't much care about the ownership of the strings here
    // at this point, so let's just fail if execvp isn't working.
    unsafe {
        let mut c_args = vec![];
        for &arg in args.iter() {
            c_args.push(c_string_or_bust(arg, "Can't with string that aren't valid Unicode").as_ptr());
        }
        c_args.push(ptr::null());
        execvp(c_program, c_args.as_mut_ptr());
        perror(c_string_or_bust("Running tmux failed:", "Invalid text").as_ptr());
    }
    panic!("Oh noes, couldn't exec.");
}

fn prepare_environment() {
    if let Some(path) = env::var_os("PATH") {
        let mut paths = env::split_paths(&path).collect::<Vec<_>>();
        paths.push(PathBuf::from("/usr/local/bin"));
        let new_path = env::join_paths(paths.iter()).unwrap();
        env::set_var("PATH", &new_path);
    } else {
        let new_path = env::join_paths(["/usr/bin", "/bin", "/usr/local/bin"].iter().map(|p| PathBuf::from(p)).collect::<Vec<_>>()).unwrap();
        env::set_var("PATH", &new_path);
    }
{'fraction_non_alphanumeric': 0.18019185895773918, 'fraction_numerical': 0.0005185377236193933, 'mean_word_length': 3.444700460829493, 'pattern_counts': {'":': 1, '<': 13, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2912297', 'n_tokens_mistral': 1358, 'n_tokens_neox': 1327, 'n_words': 294}