Skip to content

Commit

Permalink
Merge pull request #2 from cqb13/dev
Browse files Browse the repository at this point in the history
release-0.1.3
  • Loading branch information
cqb13 committed Jan 9, 2024
2 parents 2ade4a3 + 96a0a6e commit 37483f5
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 10 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,22 @@ jobs:
run: |
choco install zip
cd target/${{ matrix.target }}/release
zip fmap-0.1.2-${{ matrix.target }}.zip fmap.exe
zip fmap-0.1.3-${{ matrix.target }}.zip fmap.exe
cd ../../..
- name: Create tar.gz file on macOS
if: ${{ matrix.os == 'macos-latest' }}
run: |
chmod +x target/${{ matrix.target }}/release/fmap
tar -zcf target/${{ matrix.target }}/release/fmap-0.1.2-${{ matrix.target }}.tar.gz -C target/${{ matrix.target }}/release fmap
tar -zcf target/${{ matrix.target }}/release/fmap-0.1.3-${{ matrix.target }}.tar.gz -C target/${{ matrix.target }}/release fmap
chmod +x target/${{ matrix.target2 }}/release/fmap
tar -zcf target/${{ matrix.target2 }}/release/fmap-0.1.2-${{ matrix.target2 }}.tar.gz -C target/${{ matrix.target2 }}/release fmap
tar -zcf target/${{ matrix.target2 }}/release/fmap-0.1.3-${{ matrix.target2 }}.tar.gz -C target/${{ matrix.target2 }}/release fmap
- name: Upload release and assets to GitHub
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
tag: "release-0.1.2-${{ github.run_number }}"
release_name: fmap 0.1.2
tag: "release-0.1.3-${{ github.run_number }}"
release_name: fmap 0.1.3
file_glob: true
file: target/*/release/fmap-0.1.2-*.{zip,tar.gz}
file: target/*/release/fmap-0.1.3-*.{zip,tar.gz}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
.vscode
.DS_Store
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fmap"
version = "0.1.2"
version = "0.1.3"
edition = "2021"
authors = ["cqb13 <cqb13.dev@gmail.com>"]
license = "MIT"
Expand Down
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ The following commands are available for use with Fmap:
fmap -ls -file # Lists all ignored files
# Other Commands
fmap -i # Adds the binary to the PATH environment variable
fmap -v # Prints the version
fmap -h # Prints the help
```
Expand Down Expand Up @@ -79,6 +80,47 @@ You can try out Fmap online at [https://foldermap.cqb13.dev](https://foldermap.c

## Installation

### macOS

1. Download the latest macOS release from [GitHub](https://github.com/cqb13/fmap/releases) or build from source
2. Extract the zip file
3. Open the folder with the extracted file in your terminal
4. Run the following command:

```bash
./fmap -i
```

5. restart your terminal and run the following command:

```bash
fmap -v
```

6. If the version is printed, you have successfully installed Fmap, if not, please submit an issue on [GitHub](https://github.com/cqb13/fmap/issues), with the error message.

### Windows

1. Download the latest windows release from [GitHub](https://github.com/cqb13/fmap/releases) or build from source
2. Extract the zip file
3. Open the folder with the extracted file in your terminal (you must use administrator privileges)
4. Run the following command:

```bash
./fmap.exe -i
```

5. restart your computer
6. Open your terminal and run the following command:

```bash
fmap -v
```

7. If the version is printed, you have successfully installed Fmap, if not, please submit an issue on [GitHub](https://github.com/cqb13/fmap/issues), with the error message.

### Alternative Installation

1. Clone the repository: `git clone https://github.com/cqb13/fmap.git`
2. Navigate to the project directory: `cd fmap`
3. Build and install with Cargo: `cargo install --path .`
Expand Down
1 change: 1 addition & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub fn arg_tokenizer(mut args: Vec<String>) -> Command {
match args[0].as_str() {
"config" | "-c" => return Command::CreateConfig,
"version" | "-v" => return Command::Version,
"install" | "-i" => return Command::Install,
"help" | "-h" => return Command::Help,
"add" | "-add" => {
if args.len() < 3 {
Expand Down
8 changes: 6 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,16 @@ fn update_config_setting_value(value: String, key_line_number: usize, os: &OS) {
}

fn get_config_path(os: &OS) -> String {
let home_dir = get_user_home_dir(os);
format!("{}/{}", home_dir, CONFIG_FILE)
}

pub fn get_user_home_dir(os: &OS) -> String {
let user_dir = match os {
OS::Windows => "USERPROFILE",
OS::Mac => "HOME",
};
let home_dir = std::env::var(format!("{}", user_dir)).unwrap();
format!("{}/{}", home_dir, CONFIG_FILE)
std::env::var(format!("{}", user_dir)).unwrap()
}

fn path_exists(path: &String) -> bool {
Expand Down
114 changes: 114 additions & 0 deletions src/install.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
use crate::config::get_user_home_dir;
use crate::utils::get_current_directory_path;
use crate::OS;
use std::io::Write;

pub fn install(os: &OS) {
println!("starting install on {}", os.get_name());

let home_dir = get_user_home_dir(os);

match os {
OS::Windows => {
let app_data_path = format!("{}/AppData/Roaming/fmap", home_dir);
if !std::path::Path::new(&app_data_path).exists() {
println!("Creating AppData/Roaming/fmap directory");
std::fs::create_dir_all(&app_data_path).unwrap();
}

let new_binary_path = format!("{}/fmap.exe", app_data_path);
if !std::path::Path::new(&new_binary_path).exists() {
println!("Moving binary to AppData/Roaming/fmap");
std::fs::copy(
format!("{}/fmap.exe", get_current_directory_path()),
&new_binary_path,
)
.unwrap();
} else {
println!("Replacing binary in AppData/Roaming/fmap");
std::fs::remove_file(&new_binary_path).unwrap();
std::fs::copy(
format!("{}/fmap.exe", get_current_directory_path()),
&new_binary_path,
)
.unwrap();
}

if let Err(e) = modify_registry_path(&app_data_path) {
eprintln!("Failed to modify system PATH: {}", e);
eprintln!("This action may require administrator permissions.");
return;
}
}
OS::Mac => {
let local_bin_path = format!("{}/.local/bin", home_dir);
if !std::path::Path::new(&local_bin_path).exists() {
println!("creating .local/bin directory");
std::fs::create_dir_all(&local_bin_path).unwrap();
}

let new_binary_path = format!("{}/fmap", local_bin_path);
if !std::path::Path::new(&new_binary_path).exists() {
println!("moving binary to .local/bin");
std::fs::copy(
format!("{}/fmap", get_current_directory_path()),
&new_binary_path,
)
.unwrap();
} else {
println!("replacing binary in .local/bin");
std::fs::remove_file(&new_binary_path).unwrap();
std::fs::copy(
format!("{}/fmap", get_current_directory_path()),
&new_binary_path,
)
.unwrap();
}
let zprofile_path = format!("{}/.zprofile", home_dir);
let zprofile_content = std::fs::read_to_string(&zprofile_path).unwrap();
if !zprofile_content.contains("export PATH=\"$PATH:$HOME/.local/bin\"") {
println!("adding .local/bin to path");
let mut zprofile_file = std::fs::OpenOptions::new()
.append(true)
.open(&zprofile_content)
.unwrap();
zprofile_file
.write_all(b"export PATH=\"$PATH:$HOME/.local/bin\"\n")
.unwrap();
}
}
}

println!("install complete");
}

fn modify_registry_path(new_path: &str) -> std::io::Result<()> {
use std::process::Command;

// Escape percent signs by doubling them
let escaped_path = new_path.replace("%", "%%");

// Prepare the command to modify the registry
let status = Command::new("reg")
.args(&[
"ADD",
"HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment",
"/v",
"Path",
"/t",
"REG_EXPAND_SZ",
"/d",
&escaped_path,
"/f",
])
.status()?;

if !status.success() {
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
"Failed to modify registry",
));
}

Ok(())
}
16 changes: 16 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod commands;
pub mod config;
pub mod display;
pub mod install;
pub mod scan;
pub mod utils;

Expand All @@ -10,6 +11,7 @@ use crate::config::{
ConfigOption,
};
use crate::display::display;
use crate::install::install;
use crate::scan::scan;
use crate::utils::get_current_directory_path;
use std::env;
Expand All @@ -22,10 +24,20 @@ pub enum OS {
Mac,
}

impl OS {
fn get_name(&self) -> &str {
match self {
OS::Windows => "Windows",
OS::Mac => "Mac",
}
}
}

pub enum Command {
Scan(bool, bool, bool, bool),
ScanPath(String, bool, bool, bool, bool),
CreateConfig,
Install,
AddDirectory(String),
AddFile(String),
RemoveDirectory(String),
Expand Down Expand Up @@ -53,6 +65,7 @@ fn main() {
Command::CreateConfig => recreate_config_file(&os),
Command::Version => print_version(),
Command::Help => print_help(),
Command::Install => install(&os),
Command::ListIgnoredDirectories => {
println!(
"Ignored Directories:\n{}",
Expand Down Expand Up @@ -152,6 +165,9 @@ fn print_help() {
println!(" -ds, --dir-sizes Show directory sizes");
println!(" -fc, --file-counts Show file counts in directories\n");

println!("{} install{}", GREEN, RESET);
println!(" Installs fmap to your system.\n");

println!("{} config, -c{}", GREEN, RESET);
println!(" Creates a configuration file.\n");

Expand Down

0 comments on commit 37483f5

Please sign in to comment.