pub fn add_to_path(name: String) -> Result<(), String> {
        // The home directory
        let home = Self::home_dir();
        match Platform::get() {
            // On linux / macos, edit .bashrc
            Platform::Unknown | Platform::MacOS | Platform::Ubuntu => {
                // Start opening the .bashrc file
                let mut bashrc = PathBuf::new();
                bashrc.push(home);
                bashrc.push(".bashrc");
                let mut file = OpenOptions::new()
                    .read(true)
                    .append(true)
                    .open(bashrc.clone());
                // Finish opening the .bashrc file

                // Verify file is good
                match &mut file {
                    Ok(f) => {
                        // If file is good, get the absolute path of the directory
                        // we will add the the users path in .bashrc
                        let package_dir = Self::package_dir(name);
                        // Make a fmt string to write to the file
                        let path_addition = format!("export PATH=\"$PATH:{}\"", package_dir);

                        // Read bashrc to a string
                        let mut contents = String::new();
                        f.read_to_string(&mut contents).unwrap();

                        // If bashrc contains the line already, return and do nothing
                        for line in contents.lines() {
                            if line.to_string().contains(&path_addition) {
                                return Ok(());
                            }
                        }
                        
                        // If bashrc doesnt have the path already, write it.
                        match writeln!(f, "{}", path_addition) {
                            Ok(_) => Ok(()),
                            Err(_) => Err(format!("Failed to append to file {}", path_to_string(bashrc)))
                        }
                    },
                    Err(_) => Err(format!("Failed to add {} to PATH", name))
                }
            },

            // Windows support is very minimal.
            // I dont know if this works, but set path using the set command?
            Platform::Windows => {
                let package_dir = Self::package_dir(name);
                let path_addition = format!("set PATH=%PATH%;{}", package_dir.clone());

                // Because i dont know if this works, print the path so the user can
                // add the path if it is necessary.
                println!("WARNING: modifying the path on windows is experimental. If this install does not seem to work, add '{}' to your path environment variable.", package_dir);
                Platform::command(format!("{}", path_addition))
            },
        }
    }
/// This function adds a path from inside the package installation directory.
/// For example, if i call this function with "one/two/three/four",
/// in a package named `wonderful`, this will add 
/// `/home/user/.rapture/wonderful/one/two/three/four` to the path.
/// If i call this with `/one/two/three/four`, however, it will add
/// `/one/two/three/four` to the path.
/// 
/// This is very experimental on windows. This is not guaranteed to work on windows
/// platforms at all yet. Full support is intended in the future, however.
This function adds a path from inside the package installation directory.

This is very experimental on windows. This is not guaranteed to work on windows
platforms at all yet. Full support is intended in the future, however.
This function adds a path from inside the package installation directory . This is very experimental on windows . This is not guaranteed to work on windows platforms at all yet . Full support is intended in the future however .
pub fn add_to_path(name: String) -> Result<(), String> {
        // The home directory
        let home = Self::home_dir();
        match Platform::get() {
            // On linux / macos, edit .bashrc
            Platform::Unknown | Platform::MacOS | Platform::Ubuntu => {
                // Start opening the .bashrc file
                let mut bashrc = PathBuf::new();
                bashrc.push(home);
                bashrc.push(".bashrc");
                let mut file = OpenOptions::new()
                    .read(true)
                    .append(true)
                    .open(bashrc.clone());
                // Finish opening the .bashrc file
                // Verify file is good
                match &mut file {
                    Ok(f) => {
                        // If file is good, get the absolute path of the directory
                        // we will add the the users path in .bashrc
                        let package_dir = Self::package_dir(name);
                        // Make a fmt string to write to the file
                        let path_addition = format!("export PATH=\"$PATH:{}\"", package_dir);
                        // Read bashrc to a string
                        let mut contents = String::new();
                        f.read_to_string(&mut contents).unwrap();
                        // If bashrc contains the line already, return and do nothing
                        for line in contents.lines() {
                            if line.to_string().contains(&path_addition) {
                                return Ok(());
                            }
                        }
                        // If bashrc doesnt have the path already, write it.
                        match writeln!(f, "{}", path_addition) {
                            Ok(_) => Ok(()),
                            Err(_) => Err(format!("Failed to append to file {}", path_to_string(bashrc)))
                        }
                    },
                    Err(_) => Err(format!("Failed to add {} to PATH", name))
                }
            },
            // Windows support is very minimal.
            // I dont know if this works, but set path using the set command?
            Platform::Windows => {
                let package_dir = Self::package_dir(name);
                let path_addition = format!("set PATH=%PATH%;{}", package_dir.clone());
                // Because i dont know if this works, print the path so the user can
                // add the path if it is necessary.
                println!("WARNING: modifying the path on windows is experimental. If this install does not seem to work, add '{}' to your path environment variable.", package_dir);
                Platform::command(format!("{}", path_addition))
            },
        }
    }
pub fn add_to_path ( name : String ) -> Result < ( ) , String > { // The home directory let home = Self :: home_dir ( ) ; match Platform :: get ( ) { // On linux / macos, edit .bashrc Platform :: Unknown | Platform :: MacOS | Platform :: Ubuntu => { // Start opening the .bashrc file let mut bashrc = PathBuf :: new ( ) ; bashrc . push ( home ) ; bashrc . push ( " " ) ; let mut file = OpenOptions :: new ( ) . read ( true ) . append ( true ) . open ( bashrc . clone ( ) ) ; // Finish opening the .bashrc file // Verify file is good match & mut file { Ok ( f ) => { // If file is good, get the absolute path of the directory // we will add the the users path in .bashrc let package_dir = Self :: package_dir ( name ) ; // Make a fmt string to write to the file let path_addition = format ! ( " \" \" " package_dir ) ; // Read bashrc to a string let mut contents = String :: new ( ) ; f . read_to_string ( & mut contents ) . unwrap ( ) ; // If bashrc contains the line already, return and do nothing for line in contents . lines ( ) { if line . to_string ( ) . contains ( & path_addition ) { return Ok ( ( ) ) ; } } // If bashrc doesnt have the path already, write it. match writeln ! ( f " " path_addition ) { Ok ( _ ) => Ok ( ( ) ) , Err ( _ ) => Err ( format ! ( " " path_to_string ( bashrc ) ) ) } } , Err ( _ ) => Err ( format ! ( " " name ) ) } } , // Windows support is very minimal. // I dont know if this works, but set path using the set command? Platform :: Windows => { let package_dir = Self :: package_dir ( name ) ; let path_addition = format ! ( " " package_dir clone ( ) ) ; // Because i dont know if this works, print the path so the user can // add the path if it is necessary. println ! ( " " package_dir ) ; Platform :: command ( format ! ( " " path_addition ) ) } , } }
This function adds a path from inside the package installation directory.
This function adds a path from inside the package installation directory .
name
String
name
String