mirror of
https://github.com/jbranchaud/til
synced 2026-01-06 16:48:01 +00:00
Compare commits
4 Commits
929f7d13ac
...
518eaf0295
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
518eaf0295 | ||
|
|
60b6aa40ad | ||
|
|
f97634a61e | ||
|
|
295fe153ad |
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
||||
|
||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||
|
||||
_1630 TILs and counting..._
|
||||
_1632 TILs and counting..._
|
||||
|
||||
See some of the other learning resources I work on:
|
||||
- [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators)
|
||||
@@ -135,6 +135,7 @@ If you've learned something here, support my efforts writing daily TILs by
|
||||
- [Duplicate The Current Tab](chrome/duplicate-the-current-tab.md)
|
||||
- [Easier Access To Network Throttling Controls](chrome/easier-access-to-network-throttling-controls.md)
|
||||
- [Keybinding To Focus The Address Bar](chrome/keybinding-to-focus-the-address-bar.md)
|
||||
- [Open Current Tab In New Window With Vimium](chrome/open-current-tab-in-new-window-with-vimium.md)
|
||||
- [Pause JavaScript From The Source DevTools Panel](chrome/pause-javascript-from-the-source-devtools-panel.md)
|
||||
- [Navigate The Browser History With Vimium](chrome/navigate-the-browser-history-with-vimium.md)
|
||||
- [Pretty Print Tabular Data](chrome/pretty-print-tabular-data.md)
|
||||
@@ -1588,6 +1589,7 @@ If you've learned something here, support my efforts writing daily TILs by
|
||||
- [Grep For Files Without A Match](unix/grep-for-files-without-a-match.md)
|
||||
- [Grep For Files With Multiple Matches](unix/grep-for-files-with-multiple-matches.md)
|
||||
- [Grep For Multiple Patterns](unix/grep-for-multiple-patterns.md)
|
||||
- [Have Script ShellCheck Itself When Executing](unix/have-script-shellcheck-itself-when-executing.md)
|
||||
- [Hexdump A Compiled File](unix/hexdump-a-compiled-file.md)
|
||||
- [Ignore A Directory During ripgrep Search](unix/ignore-a-directory-during-ripgrep-search.md)
|
||||
- [Ignore The Alias When Running A Command](unix/ignore-the-alias-when-running-a-command.md)
|
||||
|
||||
14
chrome/open-current-tab-in-new-window-with-vimium.md
Normal file
14
chrome/open-current-tab-in-new-window-with-vimium.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# Open Current Tab In New Window With Vimium
|
||||
|
||||
Sometime I have a busy Chrome window going with a bunch of tabs open for
|
||||
various lines of work as well as a number of tabs that I've neglected to close.
|
||||
I then open a new tab, find something useful, and realize I'm at a "branching
|
||||
point". I'm about to start in on a specific chunk of work that will probably
|
||||
involve opening several more tabs and switch back and forth between some
|
||||
dashboards. I want to start all of this from a fresh slate -- or at least from
|
||||
a fresh Chrome window.
|
||||
|
||||
With [Vimium](https://github.com/philc/vimium), I can hit `W` (`Shift-w`) to
|
||||
have the current tab move from the current window to a new window. The original
|
||||
window, minus that one tab, will be left as is so that I can go back to it as
|
||||
needed.
|
||||
@@ -5,6 +5,8 @@ an array-like object with all of the arguments to the function. Even if not
|
||||
all of the arguments are referenced in the function signature, they can
|
||||
still be accessed via the `arguments` object.
|
||||
|
||||
> For ES6+ compatibility, the `spread` operator used via [rest parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters) is preferred over the `arugments` object when accessing an abritrary number of function arguments.
|
||||
|
||||
```javascript
|
||||
function argTest(one) {
|
||||
console.log(one);
|
||||
|
||||
60
unix/have-script-shellcheck-itself-when-executing.md
Normal file
60
unix/have-script-shellcheck-itself-when-executing.md
Normal file
@@ -0,0 +1,60 @@
|
||||
# Have Script ShellCheck Itself When Executing
|
||||
|
||||
The [ShellCheck](https://www.shellcheck.net/) utility can be run against bash
|
||||
scripts to check if there are any warnings or errors we should fix. It works
|
||||
great as long as we remember to run it.
|
||||
|
||||
I wondered if I could make it easier on myself by not having to remember to run
|
||||
it. What if my bash script were to `shellcheck` itself?
|
||||
|
||||
Here is an example script where at the beginning it looks for and runs the
|
||||
`shellcheck` utility against `$0` (the path of the script). This is kind of
|
||||
meta. As the script is executing, it has an external program run against the
|
||||
entire contents of itself. If there are any `shellcheck` issues, they get
|
||||
displayed and the program exits early.
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
# Exit immediately if any command fails
|
||||
set -e
|
||||
|
||||
# Self-validation using ShellCheck
|
||||
if command -v shellcheck &> /dev/null; then
|
||||
echo "Validating script with ShellCheck..."
|
||||
|
||||
# $0 refers to the script itself
|
||||
if ! shellcheck "$0"; then
|
||||
echo "ShellCheck found issues in the script. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
echo "Script validation passed."
|
||||
else
|
||||
echo "Warning: ShellCheck not found. Skipping validation."
|
||||
fi
|
||||
|
||||
echo "Script execution continuing..."
|
||||
|
||||
# shellcheck warning here
|
||||
read -p "Continue with current operation? (yes/no): " CONTINUE_WITH_EXISTING
|
||||
if [[ ! "$CONTINUE_WITH_EXISTING" =~ ^[Yy][Ee][Ss]$ ]]; then
|
||||
echo "Operation cancelled."
|
||||
exit 1
|
||||
fi
|
||||
```
|
||||
|
||||
This last bit of the script with the `read` command will trigger a warning from
|
||||
`shellcheck`.
|
||||
|
||||
```bash
|
||||
$ ./check.sh
|
||||
Validating script with ShellCheck...
|
||||
|
||||
In ./check.sh line 23:
|
||||
read -p "Continue with current operation? (yes/no): " CONTINUE_WITH_EXISTING
|
||||
^--^ SC2162 (info): read without -r will mangle backslashes.
|
||||
|
||||
For more information:
|
||||
https://www.shellcheck.net/wiki/SC2162 -- read without -r will mangle backs...
|
||||
ShellCheck found issues in the script. Exiting.
|
||||
```
|
||||
Reference in New Issue
Block a user