Skip to content

Commit

Permalink
Merge pull request #6 from zdcthomas/stdin
Browse files Browse the repository at this point in the history
Stdin
  • Loading branch information
zdcthomas authored May 17, 2020
2 parents 5d1f5bf + 30c44cd commit 81586dc
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 34 deletions.
118 changes: 98 additions & 20 deletions Cargo.lock

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

16 changes: 9 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
[package]
name = "dmux"
version = "0.4.1"
version = "0.4.2"
authors = ["Zachary Thomas <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[profile.release]
codegen-units = 1

[dependencies]
tmux_interface = "0.0.6"
clap = "~2.27.0"
clap = "~2.33.1"
config = '0.10.1'
dirs = "2.0.2"
walkdir = "2"
url = '2.1.1'
grep-cli = "0.1"
regex = '1.3.7'
config = '0.10.1'
serde = "1.0"
serde_derive = "1.0"
tmux_interface = "0.0.6"
url = '2.1.1'
walkdir = "2"
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ brew install dmux
```

## Usage
* `dmux` alone will use `fzf` to open up a list of dirs in `~`.
* `dmux <path>` will open the workspace in the provided path
* `dmux <path>` or `<path> | dmux` will open the workspace in the provided path
* `dmux` alone will use `fzf` to open up a list of dirs in `~`. This is equivalent to saying `fd -td . ~/ | fzf | dmux`
* `dmux --help` for more information


## Configuration
Dmux's configuration tries to be very inclusive in terms of config file types. Dmux supports
`JSON, YAML, TOML,` and ` HJSON`. It also supports a variety of paths including
Expand Down
22 changes: 17 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extern crate dirs;
#[macro_use]
extern crate serde_derive;

extern crate grep_cli;
extern crate tmux_interface;
extern crate url;
extern crate walkdir;
Expand All @@ -18,6 +19,7 @@ use clap::{
};
use regex::Regex;
use select::Selector;
use std::io;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use tmux::{Layout, WorkSpace};
Expand Down Expand Up @@ -181,6 +183,9 @@ impl Default for Config {
}

fn setup_workspace(selected_dir: PathBuf, config: Config) {
if !selected_dir.exists() {
panic!("dude, that's not a path")
}
let layout = Layout {
layout_string: config.layout,
window_count: config.number_of_panes,
Expand Down Expand Up @@ -246,16 +251,23 @@ fn main() {

fn open_in_selected_dir(args: clap::ArgMatches, config: Config) {
if let Ok(selected_dir) = value_t!(args.value_of("selected_dir"), PathBuf) {
if selected_dir.exists() {
setup_workspace(selected_dir, config)
} else {
panic!("dude, that's not a path")
}
setup_workspace(selected_dir, config)
} else if grep_cli::is_readable_stdin() && !grep_cli::is_tty_stdin() {
let selected_dir = PathBuf::from(read_line_iter());
setup_workspace(selected_dir, config)
} else if let Some(selected_dir) = Selector::new(config.search_dir.clone()).select_dir() {
setup_workspace(selected_dir, config)
}
}

fn read_line_iter() -> String {
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("Failed to read line");
input.trim().to_string()
}

// -> Result<Output, Error>
fn git_url_to_dir_name(url: &Url) -> String {
let segments = url.path_segments().ok_or_else(|| "cannot be base").unwrap();
Expand Down

0 comments on commit 81586dc

Please sign in to comment.