Added watchexec + cheat sheets

This commit is contained in:
Anurag sati
2020-09-26 14:52:30 -06:00
committed by AJ ONeal
parent 92a9674ed9
commit 8973d951e4
4 changed files with 171 additions and 0 deletions
+57
View File
@@ -0,0 +1,57 @@
---
title: watchexec
homepage: https://github.com/watchexec/watchexec
tagline: |
watchexec is a simple, standalone tool that watches a path and runs a command whenever it detects modifications.
---
### Updating `watchexec`
`webi watchexec@stable`
Use the `@beta` tag for pre-releases.
## Cheat Sheet
Watch all JavaScript, CSS and HTML files in the current directory and all
subdirectories for changes, running `make` when a change is detected:
$ watchexec --exts js,css,html make
Call `make test` when any file changes in this directory/subdirectory, except
for everything below `target`:
$ watchexec -i target make test
Call `ls -la` when any file changes in this directory/subdirectory:
$ watchexec -- ls -la
Call/restart `python server.py` when any Python file in the current directory
(and all subdirectories) changes:
$ watchexec -e py -r python server.py
Call/restart `my_server` when any file in the current directory (and all
subdirectories) changes, sending `SIGKILL` to stop the child process:
$ watchexec -r -s SIGKILL my_server
Send a SIGHUP to the child process upon changes (Note: with using
`-n | --no-shell` here, we're executing `my_server` directly, instead of
wrapping it in a shell:
$ watchexec -n -s SIGHUP my_server
Run `make` when any file changes, using the `.gitignore` file in the current
directory to filter:
$ watchexec make
Run `make` when any file in `lib` or `src` changes:
$ watchexec -w lib -w src make
Run `bundle install` when the `Gemfile` changes:
$ watchexec -w Gemfile bundle install
+55
View File
@@ -0,0 +1,55 @@
#!/usr/bin/env pwsh
#####################
# Install watchexec #
#####################
# Every package should define these variables
$pkg_cmd_name = "watchexec"
$pkg_dst_cmd = "$Env:USERPROFILE\.local\bin\watchexec.exe"
$pkg_dst = "$pkg_dst_cmd"
$pkg_src_cmd = "$Env:USERPROFILE\.local\opt\watchexec-v$Env:WEBI_VERSION\bin\watchexec.exe"
$pkg_src_bin = "$Env:USERPROFILE\.local\opt\watchexec-v$Env:WEBI_VERSION\bin"
$pkg_src_dir = "$Env:USERPROFILE\.local\opt\watchexec-v$Env:WEBI_VERSION"
$pkg_src = "$pkg_src_cmd"
$pkg_download = "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE"
# Fetch archive
IF (!(Test-Path -Path "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE"))
{
# TODO: arch detection
echo "Downloading watchexec from $Env:WEBI_PKG_URL to $pkg_download"
& curl.exe -A "$Env:WEBI_UA" -fsSL "$Env:WEBI_PKG_URL" -o "$pkg_download.part"
& move "$pkg_download.part" "$pkg_download"
}
IF (!(Test-Path -Path "$pkg_src_cmd"))
{
echo "Installing watchexec"
# TODO: create package-specific temp directory
# Enter tmp
pushd .local\tmp
# Remove any leftover tmp cruft
Remove-Item -Path ".\watchexec-v*" -Recurse -ErrorAction Ignore
Remove-Item -Path ".\watchexec.exe" -Recurse -ErrorAction Ignore
echo "Unpacking $pkg_download"
& tar xf "$pkg_download"
# Settle unpacked archive into place
echo "Install Location: $pkg_src_cmd"
New-Item "$pkg_src_bin" -ItemType Directory
Move-Item -Path ".\watchexec-*\watchexec.exe" -Destination "$pkg_src_bin"
# Exit tmp
popd
}
echo "Copying into '$pkg_dst_cmd' from '$pkg_src_cmd'"
Remove-Item -Path "$pkg_dst_cmd" -Recurse -ErrorAction Ignore
Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse
+39
View File
@@ -0,0 +1,39 @@
#!/bin/bash
{
set -e
set -u
#####################
# Install watchexec #
#####################
# Every package should define these 6 variables
pkg_cmd_name="watchexec"
pkg_dst_cmd="$HOME/.local/bin/watchexec"
pkg_dst="$pkg_dst_cmd"
pkg_src_cmd="$HOME/.local/opt/watchexec-v$WEBI_VERSION/bin/watchexec"
pkg_src_dir="$HOME/.local/opt/watchexec-v$WEBI_VERSION"
pkg_src="$pkg_src_cmd"
# pkg_install must be defined by every package
pkg_install() {
# ~/.local/opt/watchexec-v0.99.9/bin
mkdir -p "$(dirname $pkg_src_cmd)"
# mv ./watchexec-*/watchexec ~/.local/opt/watchexec-v0.99.9/bin/watchexec
mv ./watchexec-*/watchexec "$pkg_src_cmd"
}
# pkg_get_current_version is recommended, but (soon) not required
pkg_get_current_version() {
# 'watchexec --version' has output in this format:
# watchexec 0.99.9 (rev abcdef0123)
# This trims it down to just the version number:
# 0.99.9
echo $(watchexec --version 2>/dev/null | head -n 1 | cut -d ' ' -f 2)
}
}
+20
View File
@@ -0,0 +1,20 @@
'use strict';
var github = require('../_common/github.js');
var owner = 'watchexec';
var repo = 'watchexec';
module.exports = function (request) {
return github(request, owner, repo).then(function (all) {
return all;
});
};
if (module === require.main) {
module.exports(require('@root/request')).then(function (all) {
all = require('../_webi/normalize.js')(all);
// just select the first 5 for demonstration
all.releases = all.releases.slice(0, 5);
console.info(JSON.stringify(all, null, 2));
});
}