Skip to content

Commit

Permalink
remove needed to "middleware" script to install and uninstall and add…
Browse files Browse the repository at this point in the history
… makefile to this
  • Loading branch information
henrybarreto committed Dec 4, 2022
1 parent 35bb85f commit 496edde
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 72 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build:
@cargo build --release
install:
@cargo install --path .
uninstall:
@cargo unistall wk
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ WK is a CLI tool to create, manage and access workspaces.
</p>

## How to install
> In order to install `wk`, you need the `cargo` installed.
First, clone the repository:

Expand All @@ -22,10 +23,10 @@ Go to the repository folder:
cd wk
```

Then, install the wk through the script
Then, install it:

```sh
./scripts/install.sh
make install
```

## How to use
Expand All @@ -41,7 +42,6 @@ wk --save go ~/Documents/Projects/Go
```sh
wk go
```
> It is worth to say that `wk` does not change the directory itself. Currently, it just “split out” a `cd` command with the path to the workspace informed, being necessary to use a shell script to get that output, execute the `cd` command and open the shell into the directory.

**Show saved workspaces**
```sh
Expand Down
41 changes: 0 additions & 41 deletions scripts/install.sh

This file was deleted.

11 changes: 0 additions & 11 deletions scripts/uninstall.sh

This file was deleted.

8 changes: 0 additions & 8 deletions scripts/wk

This file was deleted.

4 changes: 1 addition & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ fn main() {
let matches = command.get_matches();
if matches.is_present("workspace") {
let workspace = matches.value_of("workspace").unwrap();
if let Some(found) = workspace::go(workspace) {
print!("{}", found.path);
}
workspace::go(workspace)
} else if matches.is_present("save") {
let save = matches
.values_of("save")
Expand Down
24 changes: 18 additions & 6 deletions src/workspace.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
use crate::configuration::{Configuration, Workspace};
use std::process::Command;

pub fn go(name: &str) -> Option<Workspace> {
pub fn go(name: &str) {
if let Ok(configuration) = Configuration::new_from_file() {
configuration
let workspace = configuration
.workspaces
.iter()
.find(|workspace| workspace.name == name)
.cloned()
} else {
None
.find(|workspace| workspace.name == name);

if let Some(workspace) = workspace {
println!("Going to {}", workspace.name);
Command::new("sh")
.arg("-c")
.arg(format!("cd {} && exec $SHELL", workspace.path))
.spawn()
.expect("Failed to execute process")
.wait_with_output()
.expect("Failed to wait for the exit");
println!("Exiting from {}", workspace.name)
} else {
println!("Workspace not found");
}
}
}

Expand Down

0 comments on commit 496edde

Please sign in to comment.