diff --git a/.github/workflows/awesomebot.yml b/.github/workflows/awesomebot.yml index 6e3cf1a..014f2c4 100644 --- a/.github/workflows/awesomebot.yml +++ b/.github/workflows/awesomebot.yml @@ -2,6 +2,7 @@ name: Check links in README.md on: + schedule: [{cron: "0 1 * * *"}] push: branches: ['*'] pull_request: diff --git a/README.md b/README.md index 990d783..35ca386 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,7 @@ The Tumult collection is Apache 2.0 licensed. Some scripts in the `bin` director | `smart-quote-disable` | Disable smart quote substitution | | `smart-quote-enable` | Enable smart quote substitution | | `speedup-apple-mail` | Speeds up Mail.app by vaccuuming the indexes - Originally from [http://www.hawkwings.net/2007/03/03/scripts-to-automate-the-mailapp-envelope-speed-trick/](http://www.hawkwings.net/2007/03/03/scripts-to-automate-the-mailapp-envelope-speed-trick/) | +| `spotlight-reindex` | Rebuilds/creates the spotlight index for a disk. Defaults to rebuilding the index for `/` | | `stfu` | Mutes sound | | `time-machine-log-viewer` | Dump the Time Machine logs | | `time-machine-throttle` | Restore default Time Machine throttle setting | diff --git a/bin/spotlight-reindex b/bin/spotlight-reindex new file mode 100755 index 0000000..c535d97 --- /dev/null +++ b/bin/spotlight-reindex @@ -0,0 +1,80 @@ +#!/usr/bin/env bash +# +# Reindex a drive with spotlight +# +# Copyright 2024, Joe Block + +set -o pipefail +if [[ -n "$DEBUG" ]]; then + # shellcheck disable=SC2086 + if [[ "$(echo $DEBUG | tr '[:upper:]' '[:lower:]')" == "verbose" ]]; then + set -x + fi +fi + +function debug() { + if [[ -n "$DEBUG" ]]; then + echo "$@" + fi +} + +function echo-stderr() { + echo "$@" 1>&2 ## Send message to stderr. +} + +function fail() { + printf '%s\n' "$1" >&2 ## Send message to stderr. Exclude >&2 if you don't want it that way. + exit "${2-1}" ## Return a code specified by $2 or 1 by default. +} + +function has() { + # Check if a command is in $PATH + which "$@" > /dev/null 2>&1 +} + +function check-dependencies() { + debug "Checking dependencies..." + # shellcheck disable=SC2041 + # Placeholders for whatever programs you really need + for p in 'mdutil' + do + if ! has $p; then + fail "Can't find $p in your $PATH" + else + debug "- Found $p" + fi + done +} + +function my-name() { + basename "$0" +} + +function usage() { + echo "Usage: $(my-name) Volume" + echo "I can never remember what command (mdutil) reindexes a drive, so $(my-name) rebuilds or creates a spotlight index for Volume" + exit 0 +} + +function path-exists() { + local file="${1}" + [[ -s "${file}" ]] || fail "$1 is not valid" + [[ -d "${file}" ]] && return + [[ -f "${file}" ]] && return + fail "$1 is not a directory or file" +} + +check-dependencies +if [[ $1 == '-h' ]];then + usage +fi +if [[ $# == 1 ]]; then + echo "Got a volume" + volume='/' +else + echo "no args" + volume=$1 + shift +fi +echo_stderr "Index rebuilding has to be done as root. You will be asked to enter your password by sudo" +exec sudo mdutil -E $volume $@ diff --git a/tumult.plugin.zsh b/tumult.plugin.zsh index dbc37db..96e7eb0 100644 --- a/tumult.plugin.zsh +++ b/tumult.plugin.zsh @@ -1,4 +1,4 @@ -# Copyright 2015-2023 Joseph Block +# Copyright 2015-2024 Joseph Block # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License.