Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spotlight index rebuild command #143

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/awesomebot.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
name: Check links in README.md

on:

Check warning on line 4 in .github/workflows/awesomebot.yml

View workflow job for this annotation

GitHub Actions / Megalint Code Base

4:1 [truthy] truthy value should be one of [false, true]

Check warning on line 4 in .github/workflows/awesomebot.yml

View workflow job for this annotation

GitHub Actions / Megalint Code Base

4:1 [truthy] truthy value should be one of [false, true]
schedule: [{cron: "0 1 * * *"}]
push:
branches: ['*']
pull_request:
Expand All @@ -13,7 +14,7 @@
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

Check failure on line 17 in .github/workflows/awesomebot.yml

View workflow job for this annotation

GitHub Actions / Megalint Code Base

17:5 [indentation] wrong indentation: expected 6 but found 4

Check failure on line 17 in .github/workflows/awesomebot.yml

View workflow job for this annotation

GitHub Actions / Megalint Code Base

17:5 [indentation] wrong indentation: expected 6 but found 4
- uses: docker://dkhamsing/awesome_bot:latest
with:
args: /github/workspace/README.md --allow-timeout --allow-dupe --request-delay 1 --allow-redirect --white-list http://www.hawkwings.net/2007/03/03/scripts-to-automate-the-mailapp-envelope-speed-trick,http://lostechies.com/derickbailey/2012/09/08/screencasting-tip-resize-your-app-to-720p-1280x720-in-osx/,https://img.shields.io
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
80 changes: 80 additions & 0 deletions bin/spotlight-reindex
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env bash
#
# Reindex a drive with spotlight
#
# Copyright 2024, Joe Block <[email protected]>

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 $@
2 changes: 1 addition & 1 deletion tumult.plugin.zsh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015-2023 Joseph Block <[email protected]>
# Copyright 2015-2024 Joseph Block <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
Loading