Specify files and directories to exclude in a file when compressing with the tar
Verified Environment OS tar Ubuntu 20.04.6 LTS tar (GNU tar) 1.30 macOS 13.2.1 (22D68) Darwin 22.3.0 bsdtar 3.5.3 - libarchive 3.5.3 zlib/1.2.11 liblzma/5.0.5 bz2lib/1.0.8 What to do Note # Ubuntu $ man tar ... -X, --exclude-from=FILE Exclude files matching patterns listed in FILE. # macOS $ man tar ... -X filename, --exclude-from filename Read a list of exclusion patterns from the specified file. See --exclude for more information about the handling of exclusions....
Implement slash command on GitHub Actions
Verified Environment Version image ubuntu-20.04 What to do Note github.event_name == 'issue_comment' Issue or Pull Request https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#issue_comment-on-issues-only-or-pull-requests-only Issue only: github.event_name == 'issue_comment' && !github.event.issue.pull_request Pull Request only: github.event_name == 'issue_comment' && github.event.issue.pull_request startsWith(github.event.comment.body, '/my-slash-command') Check if the comment starts with /my-slash-command Examples name: "Slash command" on: issue_comment: types: [created] jobs: slash-command: if: github.event_name == 'issue_comment' && startsWith(github.event.comment.body, '/my-slash-command') runs-on: ubuntu-20.04 env: REPO: ${{ github.repository }} ISSUE_NUMBER: ${{ github.event.issue.number }} COMMENT_ID: ${{ github....
Take a screenshot of the terminal on macos
Verified Environment Version OS macOS 13.2.1 (22D68) Darwin 22.3.0 What to do Note $ man screencapture ... -c Force screen capture to go to the clipboard. -T <seconds> Take the picture after a delay of <seconds>, default is 5. -x Do not play sounds. -l <windowid> Captures the window with windowid. ... # Get window id osascript -e "tell app \"APPLICATION_NAME\" to id of window 1" window 1 means foreground window Examples Run command and take a screenshot #!...
Google Sheets: How to copy(duplicate) worksheet to same spreadsheet in Go
Verified Environment Version OS macOS 13.2.1 (22D68) Darwin 22.3.0 Go go1.20.1 darwin/arm64 What to do Note SpreadsheetsValuesService.BatchUpdate DuplicateSheetRequest Examples package main import ( "context" "log" "os" "strconv" "time" "google.golang.org/api/option" "google.golang.org/api/sheets/v4" ) func newSheetsClient(ctx context.Context, credentials string) (*sheets.Service, error) { var svc *sheets.Service var err error if credentials == "" { // You may need to run the following commands beforehand: // gcloud auth application-default login --scopes "https://www.googleapis.com/auth/spreadsheets" svc, err = sheets....
jq convert 2D array JSON to array with objects
Verified Environment Version OS Ubuntu 20.04.5 LTS jq jq-1.6 What to do Note https://stedolan.github.io/jq/manual/ –slurp/-s: Instead of running the filter for each JSON object in the input, read the entire input stream into a large array and run the filter just once. to_entries, from_entries, with_entries These functions convert between an object and an array of key-value pairs. If to_entries is passed an object, then for each k: v entry in the input, the output array includes {"key": k, "value": v}....
Get the primary on-caller of PagerDuty
Verified Environment Version OS Ubuntu 20.04.5 LTS bash GNU bash, version 5.0.17(1)-release (aarch64-unknown-linux-gnu) jq jq-1.6 curl curl 7.68.0 PagerDuty API V2 2023-02-14 What to do Note It uses 2 APIs: List all of the on-calls Filter by escalation policy and escalation level = 1 Get a user Examples Here is an example of getting the email of the primary on-caller: #!/bin/bash if [ "${PAGERDUTY_API_KEY}" = "" ]; then echo "\$PAGERDUTY_API_KEY is required....
Example of gcloud spanner operations list --filter
Verified Environment Version spanner-emulator v1.4.9(ae507799872a) Google Cloud SDK 416.0.0 Examples Not completed operations gcloud spanner operations list --filter="done = false" Completed operations gcloud spanner operations list --filter="done = true" Statements gcloud spanner operations list --filter="metadata.statements ~ PART_OF_SQL"
Filter by pod for kubectl (get) events
Verified Environment Version Kubernetes v1.26.0 kubectl Client version v1.26.0 Examples $ kubectl get pods NAME READY STATUS RESTARTS AGE nginx-deployment-85996f8dbd-mq8z9 1/1 Running 0 4m43s nginx-deployment-85996f8dbd-pl2cw 1/1 Running 0 4m43s kubectl get events $ kubectl get events --field-selector involvedObject.name=nginx-deployment-85996f8dbd-mq8z9 LAST SEEN TYPE REASON OBJECT MESSAGE 5m4s Normal Scheduled pod/nginx-deployment-85996f8dbd-mq8z9 Successfully assigned default/nginx-deployment-85996f8dbd-mq8z9 to node01 5m3s Normal Pulling pod/nginx-deployment-85996f8dbd-mq8z9 Pulling image "nginx:1.14.2" 4m59s Normal Pulled pod/nginx-deployment-85996f8dbd-mq8z9 Successfully pulled image "nginx:1.14.2" in 3.911484541s (3....
Avoid "argument list too lang" error when using jq in bash
Verified Environment Version OS Ubuntu 20.04.5 LTS jq jq-1.6 Why is the error occurring? If you run the following scripts in bash, you will get bash: /usr/bin/jq: Argument list too long error. array=$(echo "[" $(echo {1..1000000} | tr ' ' ',') "]") echo '{"array": null}' | jq --arg array "${array}" '.array = $array' This is thought to be because when --arg array "${array}" is used, ${array} is variable expanded and thus exceeds ARG_MAX....
Convert to lower/upper case on the command line
Bash Verified Environment Version OS Ubuntu 20.04.5 LTS bash GNU bash, version 5.0.17(1)-release (aarch64-unknown-linux-gnu) What to do Note The ‘^’ operator converts lowercase letters matching pattern to uppercase; the ‘,’ operator converts matching uppercase letters to lowercase. The ‘^^’ and ‘,,’ expansions convert each matched character in the expanded value; https://www.gnu.org/software/bash/manual/bash.html#Shell-Parameter-Expansion Convert to lowercase val="ABC" echo ${val,,} Convert to uppercase val="abc" echo ${val^^} AWK Verified Environment Version OS Ubuntu 20....