diff options
Diffstat (limited to 'src/content/tils/2020')
-rw-r--r-- | src/content/tils/2020/08/12/filename-timestamp.adoc | 4 | ||||
-rw-r--r-- | src/content/tils/2020/08/14/browse-git.adoc | 12 | ||||
-rw-r--r-- | src/content/tils/2020/08/16/git-search.adoc | 6 | ||||
-rw-r--r-- | src/content/tils/2020/08/28/grep-online.adoc | 6 | ||||
-rw-r--r-- | src/content/tils/2020/09/04/cli-email-fun-profit.adoc | 11 | ||||
-rw-r--r-- | src/content/tils/2020/09/05/oldschool-pr.adoc | 6 | ||||
-rw-r--r-- | src/content/tils/2020/10/11/search-git-history.adoc | 4 | ||||
-rw-r--r-- | src/content/tils/2020/11/08/find-broken-symlink.adoc | 4 | ||||
-rw-r--r-- | src/content/tils/2020/11/12/diy-nix-bash-ci.adoc | 2 | ||||
-rw-r--r-- | src/content/tils/2020/11/12/git-bisect-automation.adoc | 5 | ||||
-rw-r--r-- | src/content/tils/2020/11/12/useful-bashvars.adoc | 6 | ||||
-rw-r--r-- | src/content/tils/2020/11/30/git-notes-ci.adoc | 4 | ||||
-rw-r--r-- | src/content/tils/2020/12/15/shellcheck-repo.adoc | 17 |
13 files changed, 45 insertions, 42 deletions
diff --git a/src/content/tils/2020/08/12/filename-timestamp.adoc b/src/content/tils/2020/08/12/filename-timestamp.adoc index 1cbe404..aa8d63b 100644 --- a/src/content/tils/2020/08/12/filename-timestamp.adoc +++ b/src/content/tils/2020/08/12/filename-timestamp.adoc @@ -5,7 +5,7 @@ When writing Jekyll posts or creating log files with dates on them, I usually struggle with finding a direct way of accomplishing that. There's a simple solution: `date -I`. -[source,shell] +[source,sh] ---- ./my-program.sh > my-program.$(date -I).log cp post-template.md _posts/$(date -I)-post-slug.md @@ -18,7 +18,7 @@ I always had to read `man date` or search the web over and over, and after doing this repeatedly it became clear that both `date -I` and `date -Is` (`s` here stands for seconds) are the thing that I'm looking for 95% of the time: -[source,shell] +[source,sh] ---- # inside my-program.sh echo "Program started at $(date -Is)" diff --git a/src/content/tils/2020/08/14/browse-git.adoc b/src/content/tils/2020/08/14/browse-git.adoc index 3d7660e..6b3ff6d 100644 --- a/src/content/tils/2020/08/14/browse-git.adoc +++ b/src/content/tils/2020/08/14/browse-git.adoc @@ -4,7 +4,7 @@ I commonly use tools like `git log` together with `git show` when inspecting past changes in a repository: -[source,shell] +[source,sh] ---- git log # search for a the commit I'm looking for @@ -18,7 +18,7 @@ but to browse the whole repository at that specific commit. I used to accomplish it the "brute force" way: clone the whole repository in another folder and checkout the commit there: -[source,shell] +[source,sh] ---- git clone <original-repo> /tmp/tmp-repo-clone cd /tmp-repo-clone @@ -28,7 +28,7 @@ git checkout <my-commit> But git itself allows we to specific the directory of the checkout by using the `--work-tree` global git flag. This is what `man git` says about it: -[source,txt] +[source,text] ---- --work-tree=<path> Set the path to the working tree. It can be an absolute path or a path relative to the current working @@ -40,7 +40,7 @@ But git itself allows we to specific the directory of the checkout by using the So it allows us to set the desired path of the working tree. So if we want to copy the contents of the current working tree into `copy/`: -[source,shell] +[source,sh] ---- mkdir copy git --work-tree=copy/ checkout . @@ -49,7 +49,7 @@ git --work-tree=copy/ checkout . After that `copy/` will contain a replica of the code in HEAD. But to checkout a specific, we need some extra parameters: -[source,shell] +[source,sh] ---- git --work-tree=<dir> checkout <my-commit> -- . ---- @@ -59,7 +59,7 @@ Morse signals to git, but we're actually saying to `git-checkout` which sub directory of `<my-commit>` we want to look at. Which means we can do something like: -[source,shell] +[source,sh] ---- git --work-tree=<dir> checkout <my-commit> -- src/ ---- diff --git a/src/content/tils/2020/08/16/git-search.adoc b/src/content/tils/2020/08/16/git-search.adoc index 26e617d..4113f3f 100644 --- a/src/content/tils/2020/08/16/git-search.adoc +++ b/src/content/tils/2020/08/16/git-search.adoc @@ -11,7 +11,7 @@ Here's a useful trio to know about to help you search things in git: Show a specific commit and it's diff: -[source,shell] +[source,sh] ---- git show # shows the latest commit @@ -25,7 +25,7 @@ git show v1.2 Search through the commit messages: -[source,shell] +[source,sh] ---- git log --grep='refactor' ---- @@ -36,7 +36,7 @@ git log --grep='refactor' Search content in git history: -[source,shell] +[source,sh] ---- git grep 'TODO' # search the repository for the "TODO" string diff --git a/src/content/tils/2020/08/28/grep-online.adoc b/src/content/tils/2020/08/28/grep-online.adoc index 7d22cf8..77363ab 100644 --- a/src/content/tils/2020/08/28/grep-online.adoc +++ b/src/content/tils/2020/08/28/grep-online.adoc @@ -13,7 +13,7 @@ some pattern but I can't, because either: Here's a simple script that allows you to overcome that problem easily: -[source,shell] +[source,sh] ---- #!/usr/bin/env bash set -eu @@ -90,7 +90,7 @@ Perform `git grep`, forwarding the remaining arguments from `$@`. Example output: -[source,shell] +[source,sh] ---- $ git search 'make get-git' https://git.zx2c4.com/cgit/ Clonage dans '/tmp/git-search/cgit'... @@ -114,7 +114,7 @@ needed. When no argument is provided, it prints the usage text: -[source,shell] +[source,sh] ---- $ git search Missing argument REGEX_PATTERN. diff --git a/src/content/tils/2020/09/04/cli-email-fun-profit.adoc b/src/content/tils/2020/09/04/cli-email-fun-profit.adoc index 5476fac..1da1154 100644 --- a/src/content/tils/2020/09/04/cli-email-fun-profit.adoc +++ b/src/content/tils/2020/09/04/cli-email-fun-profit.adoc @@ -15,7 +15,7 @@ Reason 3 is the fun part, reasons 1 and 2 are the profit part. First {ssmpt}[install and configure SSMTP] for using, say, Gmail as the email server: -[source,shell] +[source,sh] ---- # file /etc/ssmtp/ssmtp.conf FromLineOverride=YES @@ -31,7 +31,7 @@ AuthPass=password Now install {mailutils}[GNU Mailutils] (`sudo apt-get install mailutils` or the equivalent on your OS), and send yourself your first email: -[source,shell] +[source,sh] ---- echo body | mail -aFrom:email@example.com email@example.com -s subject ---- @@ -39,7 +39,7 @@ echo body | mail -aFrom:email@example.com email@example.com -s subject And that's about it, you've got mail. Here are some more places where it might be applicable: -[source,shell] +[source,sh] ---- # report a backup cronjob, attaching logs set -e @@ -62,10 +62,11 @@ trap finish EXIT do-long-backup-cmd-here ---- -.... +[source,sh] +---- # share the output of a cmd with someone some-program | mail someone@example.com -s "The weird logs that I was talking about" -.... +---- ...and so on. diff --git a/src/content/tils/2020/09/05/oldschool-pr.adoc b/src/content/tils/2020/09/05/oldschool-pr.adoc index a2c758c..392ec67 100644 --- a/src/content/tils/2020/09/05/oldschool-pr.adoc +++ b/src/content/tils/2020/09/05/oldschool-pr.adoc @@ -26,7 +26,7 @@ to be locked in by any of them, putting the "D" back in "DVCS": it’s a Here’s the raw output of a `git request-pull`: -[source,shell] +[source,sh] ---- $ git request-pull HEAD public-origin The following changes since commit 302c9f2f035c0360acd4e13142428c100a10d43f: @@ -62,7 +62,7 @@ address ready for public consumption. A simple solution for that is for you to add the `public-origin` alias as the HTTPS alternative to the SSH version: -[source,shell] +[source,sh] ---- $ git remote add public-origin https://example.com/user/repo ---- @@ -78,7 +78,7 @@ Experiment it yourself, and get acquainted with the CLI. Now that you can create the content of a pull request, you can just {cli-email}[deliver it] to the interested parties email: -[source,shell] +[source,sh] ---- # send a PR with your last commit to the author's email git request-pull HEAD public-origin | mail author@example.com -s "PR: Add thing to repo" diff --git a/src/content/tils/2020/10/11/search-git-history.adoc b/src/content/tils/2020/10/11/search-git-history.adoc index 06df9dc..696368c 100644 --- a/src/content/tils/2020/10/11/search-git-history.adoc +++ b/src/content/tils/2020/10/11/search-git-history.adoc @@ -15,7 +15,7 @@ name, only bits of it. I immediately went to the list of TILs I had written on searching in Git, but it wasn't readily obvious how to do it, so here it goes: -[source,shell] +[source,sh] ---- git log -- *pattern* ---- @@ -23,7 +23,7 @@ git log -- *pattern* You could add globs before the pattern to match things on any directory, and add our `-p` friend to promptly see the diffs: -[source,shell] +[source,sh] ---- git log -p -- **/*pattern* ---- diff --git a/src/content/tils/2020/11/08/find-broken-symlink.adoc b/src/content/tils/2020/11/08/find-broken-symlink.adoc index 9b44036..624d24a 100644 --- a/src/content/tils/2020/11/08/find-broken-symlink.adoc +++ b/src/content/tils/2020/11/08/find-broken-symlink.adoc @@ -6,7 +6,7 @@ The `find` command knows how to show broken symlinks: -[source,shell] +[source,sh] ---- find . -xtype l ---- @@ -15,7 +15,7 @@ This was useful to me when combined with {annex}[Git Annex]. Its {annex-wanted}[`wanted`] option allows you to have a "sparse" checkout of the content, and save space by not having to copy every annexed file locally: -[source,shell] +[source,sh] ---- git annex wanted . 'exclude=Music/* and exclude=Videos/*' ---- diff --git a/src/content/tils/2020/11/12/diy-nix-bash-ci.adoc b/src/content/tils/2020/11/12/diy-nix-bash-ci.adoc index 219b694..97ace30 100644 --- a/src/content/tils/2020/11/12/diy-nix-bash-ci.adoc +++ b/src/content/tils/2020/11/12/diy-nix-bash-ci.adoc @@ -12,7 +12,7 @@ to the server. In most of my project I like to keep a `test` attribute which runs the test with `nix-build -A test`. This way, a post-receive hook could look like: -[source,shell] +[source,sh] ---- #!/usr/bin/env bash set -Eeuo pipefail diff --git a/src/content/tils/2020/11/12/git-bisect-automation.adoc b/src/content/tils/2020/11/12/git-bisect-automation.adoc index d7ea2ca..dff8737 100644 --- a/src/content/tils/2020/11/12/git-bisect-automation.adoc +++ b/src/content/tils/2020/11/12/git-bisect-automation.adoc @@ -10,11 +10,12 @@ I've already been in the situation when a bug was introduced and I didn't know how it even was occurring, and running Git bisect over hundreds of commits to pinpoint the failing commit was very empowering: -.... +[source,sh] +---- $ GOOD_COMMIT_SHA=e1fd0a817d192c5a5df72dd7422e36558fa78e46 $ git bisect start HEAD $GOOD_COMMIT_SHA $ git bisect run sn -c './build.sh && ./run-failing-case.sh' -.... +---- Git will than do a binary search between the commits, and run the commands you provide it with to find the failing commit. diff --git a/src/content/tils/2020/11/12/useful-bashvars.adoc b/src/content/tils/2020/11/12/useful-bashvars.adoc index 84b93c3..fb148fb 100644 --- a/src/content/tils/2020/11/12/useful-bashvars.adoc +++ b/src/content/tils/2020/11/12/useful-bashvars.adoc @@ -13,7 +13,7 @@ on the terminal. The {bash-bang-bang}[`!!` variable] refers to the previous command, and I find useful when following chains for symlinks: -[source,shell] +[source,sh] ---- $ which git /run/current-system/sw/bin/git @@ -25,7 +25,7 @@ readlink $(which git) It is also useful when you forget to prefix `sudo` to a command that requires it: -[source,shell] +[source,sh] ---- $ requires-sudo.sh requires-sudo.sh: Permission denied @@ -43,7 +43,7 @@ The {bash-dollar-underscore}[`$_` variable] will give you the most recent parameter you provided to a previous argument, which can save you typing sometimes: -[source,shell] +[source,sh] ---- # instead of... $ mkdir -p a/b/c/d/ diff --git a/src/content/tils/2020/11/30/git-notes-ci.adoc b/src/content/tils/2020/11/30/git-notes-ci.adoc index 602e11d..48a996b 100644 --- a/src/content/tils/2020/11/30/git-notes-ci.adoc +++ b/src/content/tils/2020/11/30/git-notes-ci.adoc @@ -13,7 +13,7 @@ I've written a small script that will put log files and CI job data on Git notes, and make it visible on the porcelain log. It is a simple extension of the previous article: -[source,shell] +[source,sh] ---- #!/usr/bin/env bash set -Eeuo pipefail @@ -101,7 +101,7 @@ https://euandre.org/git/servers/commit?id=87c57133abd8be5d7cc46afbf107f59b260665 You can go even further: since cgit can serve raw blob directly, you can even serve such artifacts (log files, release artifacts, binaries) from cgit itself: -[source,shell] +[source,sh] ---- $ SHA="$(git notes --ref=refs/notes/ci-logs list 87c57133abd8be5d7cc46afbf107f59b26066575)" $ echo "https://euandre.org/git/servers/blob?id=$SHA" diff --git a/src/content/tils/2020/12/15/shellcheck-repo.adoc b/src/content/tils/2020/12/15/shellcheck-repo.adoc index db280db..387e793 100644 --- a/src/content/tils/2020/12/15/shellcheck-repo.adoc +++ b/src/content/tils/2020/12/15/shellcheck-repo.adoc @@ -12,7 +12,7 @@ In my repositories I usually have Bash and POSIX scripts, which I want to keep tidy with {shellcheck}[ShellCheck]. Here's the first version of `assert-shellcheck.sh`: -[source,shell] +[source,sh] ---- #!/bin/sh -eux @@ -28,7 +28,7 @@ recently added some scripts without any extension, so `assert-shellcheck.sh` called for a second version. The first attempt was to try grepping the shebang line: -[source,shell] +[source,sh] ---- $ grep '^#!/' assert-shellcheck.sh #!/usr/sh @@ -37,7 +37,7 @@ $ grep '^#!/' assert-shellcheck.sh Good, we have a grep pattern on the first try. Let's try to find all the matching files: -[source,shell] +[source,sh] ---- $ find . -type f | xargs grep -l '^#!/' ./TODOs.org @@ -76,7 +76,7 @@ sample hooks in `.git/hooks/*`. To list the files that Git is tracking we'll try `git ls-files`: -[source,shell] +[source,sh] ---- $ git ls-files | xargs grep -l '^#!/' TODOs.org @@ -109,7 +109,7 @@ and to stop processing the file if the pattern matches. A quick search points me to using `FNR` for the former, and `{ nextline }` for the latter. Let's try it: -[source,shell] +[source,sh] ---- $ git ls-files | xargs awk 'FNR>1 { nextfile } /^#!\// { print FILENAME; nextfile }' bootstrap @@ -131,13 +131,14 @@ matching against any part of the file that may have a shebang-like line, we only look for the first. Let's put it back into the `assert-shellcheck.sh` file and use `NULL` for separators to accommodate files with spaces in the name: -.... +[source,sh] +---- #!/usr/sh -eux git ls-files -z | \ xargs -0 awk 'FNR>1 { nextfile } /^#!\// { print FILENAME; nextfile }' | \ xargs shellcheck -.... +---- This is where I've stopped, but I imagine a likely improvement: match against only +#!/bin/sh+ and +#!/usr/bin/env bash+ shebangs (the ones I use most), to @@ -152,7 +153,7 @@ on the POSIX subset of Awk for working correctly. After publishing, I could remove `{ nextfile }` and even make the script simpler: -[source,shell] +[source,sh] ---- #!/usr/sh -eux |