Skip to content

Commit fe75d4d

Browse files
committed
Truly watch the correct file and port to 2018. Version bump.
1 parent 230d6be commit fe75d4d

File tree

5 files changed

+37
-20
lines changed

5 files changed

+37
-20
lines changed

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ matrix:
1313
include:
1414
# Linux
1515
- env: TARGET=armv7-unknown-linux-gnueabihf
16+
rust: nightly
1617
- env: TARGET=i686-unknown-linux-musl
18+
rust: nightly
1719
- env: TARGET=x86_64-unknown-linux-musl
20+
rust: nightly
1821

1922
# OSX
2023
- env: TARGET=x86_64-apple-darwin
2124
os: osx
25+
rust: nightly
2226

2327
before_install:
2428
- set -e
@@ -42,7 +46,7 @@ deploy:
4246
file_glob: true
4347
file: $CRATE_NAME-$TRAVIS_TAG-$TARGET.*
4448
on:
45-
condition: $TRAVIS_RUST_VERSION = stable
49+
condition: $TRAVIS_RUST_VERSION = nightly
4650
tags: true
4751
provider: releases
4852
skip_cleanup: true

Cargo.lock

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
authors = ["Holger Rapp <HolgerRapp@gmx.net>"]
33
name = "shell_grunt2"
4-
version = "0.1.5"
4+
version = "0.2.0"
55
edition = "2018"
66

77
[dependencies]
@@ -15,6 +15,7 @@ self_update = "0.4.2"
1515
sha1 = "0.6.0"
1616
term = "0.5.1"
1717
time = "^0.1"
18+
pathdiff = "0.1.0"
1819

1920
[dependencies.ctrlc]
2021
features = ["termination"]

src/main.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ use ctrlc;
33
use notify;
44
use shell_grunt2;
55
use time;
6-
#[macro_use]
7-
extern crate self_update;
86

97
use notify::Watcher;
108
use shell_grunt2::lockfile;
119
use shell_grunt2::task::{Runnable, RunningTask, Task};
12-
use std::path;
10+
use std::path::{Path, PathBuf};
1311
use std::process;
1412
use std::sync::atomic::{AtomicBool, Ordering};
1513
use std::sync::mpsc;
@@ -27,14 +25,14 @@ fn update() -> Result<(), Box<dyn (::std::error::Error)>> {
2725
.show_download_progress(true)
2826
.show_output(false)
2927
.no_confirm(true)
30-
.current_version(cargo_crate_version!())
28+
.current_version(self_update::cargo_crate_version!())
3129
.build()?
3230
.update()?;
3331
Ok(())
3432
}
3533

3634
struct ReloadWatcherFile {
37-
file_name: String,
35+
file_name: PathBuf,
3836
should_reload: Arc<AtomicBool>,
3937
}
4038

@@ -56,44 +54,51 @@ impl Runnable for ReloadWatcherFile {
5654
}
5755

5856
impl Task for ReloadWatcherFile {
59-
fn should_run(&self, path: &path::Path) -> bool {
60-
if let Some(file_name) = path.file_name() {
61-
return file_name.to_string_lossy() == self.file_name;
62-
}
63-
false
57+
fn should_run(&self, path: &Path) -> bool {
58+
path == self.file_name
6459
}
6560

6661
fn start_delay(&self) -> time::Duration {
6762
time::Duration::milliseconds(0)
6863
}
6964
}
7065

71-
fn watch_file_events(watcher_file: &str) {
66+
fn watch_file_events(watcher_file: impl AsRef<Path>) {
7267
let saw_interrupt_signal = Arc::new(AtomicBool::new(false));
7368
let r = saw_interrupt_signal.clone();
7469
ctrlc::set_handler(move || {
7570
r.store(true, Ordering::SeqCst);
7671
})
7772
.expect("Error setting Ctrl-C handler");
7873

74+
let current_dir = std::fs::canonicalize(".").unwrap();
75+
let watcher_file = std::fs::canonicalize(watcher_file.as_ref()).unwrap();
7976
loop {
80-
println!("Watching file system with tasks from {}", watcher_file);
77+
let diff = pathdiff::diff_paths(&watcher_file, &current_dir);
78+
let disp = match &diff {
79+
Some(diff) => diff,
80+
None => &watcher_file,
81+
};
82+
println!("Watching file system with tasks from {}", disp.display());
8183

8284
// Ideally, the RecommendedWatcher would be owned by ShellGrunt2, but whenever I try that,
8385
// the tool crashes whenever it should receive an event on the channel. So it needs to stay
8486
// outside. :(
8587
let (events_tx, events_rx) = mpsc::channel();
8688
let mut watcher = notify::watcher(events_tx, Duration::from_millis(50)).unwrap();
8789
watcher
88-
.watch(&path::Path::new("."), notify::RecursiveMode::Recursive)
90+
.watch(&current_dir, notify::RecursiveMode::Recursive)
91+
.unwrap();
92+
watcher
93+
.watch(&watcher_file, notify::RecursiveMode::Recursive)
8994
.unwrap();
9095

9196
let should_reload = Arc::new(AtomicBool::new(false));
9297
let mut tasks: Vec<Box<dyn Task>> = vec![Box::new(ReloadWatcherFile {
93-
file_name: watcher_file.to_string(),
98+
file_name: watcher_file.clone(),
9499
should_reload: should_reload.clone(),
95100
})];
96-
for task in shell_grunt2::lua_task::run_file(path::Path::new(watcher_file)) {
101+
for task in shell_grunt2::lua_task::run_file(&watcher_file) {
97102
tasks.push(task);
98103
}
99104
let mut shell_grunt2 = shell_grunt2::ShellGrunt2::new(&tasks, events_rx);
@@ -113,7 +118,7 @@ fn watch_file_events(watcher_file: &str) {
113118

114119
fn main() {
115120
let matches = clap::App::new("shell_grunt2")
116-
.version(cargo_crate_version!())
121+
.version(self_update::cargo_crate_version!())
117122
.about("Watches the file system and executes commands from a Lua file.")
118123
.arg(
119124
clap::Arg::with_name("file")

watcher.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ return {
1111
},
1212
commands = {
1313
{
14-
name = "Cargo build (release)",
14+
name = "Cargo jump (release)",
1515
command = "cargo +nightly build --release --color always",
1616
},
1717
},

0 commit comments

Comments
 (0)