Update 05.04.2026
This commit is contained in:
@@ -8,7 +8,12 @@ To start using it, add the `macos` plugin to your plugins array in `~/.zshrc`:
|
||||
plugins=(... macos)
|
||||
```
|
||||
|
||||
Original author: [Sorin Ionescu](https://github.com/sorin-ionescu)
|
||||
## Supported Terminals
|
||||
- [iTerm](https://iterm.sourceforge.net/)
|
||||
- [iTerm2](https://iterm2.com/)
|
||||
- [Hyper](https://hyper.is/)
|
||||
- [Tabby](https://tabby.sh/)
|
||||
- [Ghostty](https://ghostty.org)
|
||||
|
||||
## Commands
|
||||
|
||||
@@ -17,7 +22,7 @@ Original author: [Sorin Ionescu](https://github.com/sorin-ionescu)
|
||||
| `tab` | Open the current directory in a new tab |
|
||||
| `split_tab` | Split the current terminal tab horizontally |
|
||||
| `vsplit_tab` | Split the current terminal tab vertically |
|
||||
| `ofd` | Open the current directory in a Finder window |
|
||||
| `ofd` | Open passed directories (or $PWD by default) in Finder |
|
||||
| `pfd` | Return the path of the frontmost Finder window |
|
||||
| `pfs` | Return the current Finder selection |
|
||||
| `cdf` | `cd` to the current Finder directory |
|
||||
@@ -25,7 +30,7 @@ Original author: [Sorin Ionescu](https://github.com/sorin-ionescu)
|
||||
| `pxd` | Return the current Xcode project directory |
|
||||
| `cdx` | `cd` to the current Xcode project directory |
|
||||
| `quick-look` | Quick-Look a specified file |
|
||||
| `man-preview` | Open a specified man page in Preview app |
|
||||
| `man-preview` | Open man pages in Preview app |
|
||||
| `showfiles` | Show hidden files in Finder |
|
||||
| `hidefiles` | Hide the hidden files in Finder |
|
||||
| `itunes` | _DEPRECATED_. Use `music` from macOS Catalina on |
|
||||
@@ -37,7 +42,9 @@ Original author: [Sorin Ionescu](https://github.com/sorin-ionescu)
|
||||
|
||||
## Acknowledgements
|
||||
|
||||
This application makes use of the following third party scripts:
|
||||
Original author: [Sorin Ionescu](https://github.com/sorin-ionescu)
|
||||
|
||||
This application makes use of the following third-party scripts:
|
||||
|
||||
[shpotify](https://github.com/hnarayanan/shpotify)
|
||||
|
||||
|
||||
@@ -3,8 +3,15 @@
|
||||
0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
|
||||
0="${${(M)0:#/*}:-$PWD/$0}"
|
||||
|
||||
# Open the current directory in a Finder window
|
||||
alias ofd='open_command $PWD'
|
||||
# Open in Finder the directories passed as arguments, or the current directory if
|
||||
# no directories are passed
|
||||
function ofd {
|
||||
if (( ! $# )); then
|
||||
open_command $PWD
|
||||
else
|
||||
open_command $@
|
||||
fi
|
||||
}
|
||||
|
||||
# Show/hide hidden files in the Finder
|
||||
alias showfiles="defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder"
|
||||
@@ -72,6 +79,19 @@ EOF
|
||||
key code 36 #(presses enter)
|
||||
end tell
|
||||
EOF
|
||||
|
||||
elif [[ "$the_app" == 'Tabby' ]]; then
|
||||
osascript >/dev/null <<EOF
|
||||
tell application "System Events"
|
||||
tell process "Tabby" to keystroke "t" using command down
|
||||
end tell
|
||||
EOF
|
||||
elif [[ "$the_app" == 'ghostty' ]]; then
|
||||
osascript >/dev/null <<EOF
|
||||
tell application "System Events"
|
||||
tell process "Ghostty" to keystroke "t" using command down
|
||||
end tell
|
||||
EOF
|
||||
else
|
||||
echo "$0: unsupported terminal app: $the_app" >&2
|
||||
return 1
|
||||
@@ -119,6 +139,18 @@ EOF
|
||||
delay 1
|
||||
keystroke "${command} \n"
|
||||
end tell
|
||||
EOF
|
||||
elif [[ "$the_app" == 'Tabby' ]]; then
|
||||
osascript >/dev/null <<EOF
|
||||
tell application "System Events"
|
||||
tell process "Tabby" to keystroke "D" using command down
|
||||
end tell
|
||||
EOF
|
||||
elif [[ "$the_app" == 'ghostty' ]]; then
|
||||
osascript >/dev/null <<EOF
|
||||
tell application "System Events"
|
||||
tell process "Ghostty" to keystroke "D" using command down
|
||||
end tell
|
||||
EOF
|
||||
else
|
||||
echo "$0: unsupported terminal app: $the_app" >&2
|
||||
@@ -168,6 +200,18 @@ EOF
|
||||
delay 1
|
||||
keystroke "${command} \n"
|
||||
end tell
|
||||
EOF
|
||||
elif [[ "$the_app" == 'Tabby' ]]; then
|
||||
osascript >/dev/null <<EOF
|
||||
tell application "System Events"
|
||||
tell process "Tabby" to keystroke "d" using command down
|
||||
end tell
|
||||
EOF
|
||||
elif [[ "$the_app" == 'ghostty' ]]; then
|
||||
osascript >/dev/null <<EOF
|
||||
tell application "System Events"
|
||||
tell process "Ghostty" to keystroke "d" using command down
|
||||
end tell
|
||||
EOF
|
||||
else
|
||||
echo "$0: unsupported terminal app: $the_app" >&2
|
||||
@@ -224,8 +268,12 @@ function quick-look() {
|
||||
}
|
||||
|
||||
function man-preview() {
|
||||
# Don't let Preview.app steal focus if the man page doesn't exist
|
||||
man -w "$@" &>/dev/null && man -t "$@" | open -f -a Preview || man "$@"
|
||||
[[ $# -eq 0 ]] && >&2 echo "Usage: $0 command1 [command2 ...]" && return 1
|
||||
|
||||
local page
|
||||
for page in "${(@f)"$(command man -w $@)"}"; do
|
||||
command mandoc -Tpdf $page | open -f -a Preview
|
||||
done
|
||||
}
|
||||
compdef _man man-preview
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
function spotify() {
|
||||
# Copyright (c) 2012--2019 Harish Narayanan <mail@harishnarayanan.org>
|
||||
# Copyright (c) 2012--2023 Harish Narayanan <mail@harishnarayanan.org>
|
||||
#
|
||||
# Contains numerous helpful contributions from Jorge Colindres, Thomas
|
||||
# Pritchard, iLan Epstein, Gabriele Bonetti, Sean Heller, Eric Martin
|
||||
@@ -35,6 +35,9 @@ if ! [[ -f "${USER_CONFIG_FILE}" ]]; then
|
||||
fi
|
||||
source "${USER_CONFIG_FILE}";
|
||||
|
||||
# Set the percent change in volume for vol up and vol down
|
||||
VOL_INCREMENT=10
|
||||
|
||||
showAPIHelp() {
|
||||
echo;
|
||||
echo "Connecting to Spotify's API:";
|
||||
@@ -43,7 +46,7 @@ showAPIHelp() {
|
||||
echo " find music by name. It is very likely you want this feature!";
|
||||
echo;
|
||||
echo " To get this to work, you need to sign up (or in) and create an 'Application' at:";
|
||||
echo " https://developer.spotify.com/my-applications/#!/applications/create";
|
||||
echo " https://developer.spotify.com/dashboard/create";
|
||||
echo;
|
||||
echo " Once you've created an application, find the 'Client ID' and 'Client Secret'";
|
||||
echo " values, and enter them into your shpotify config file at '${USER_CONFIG_FILE}'";
|
||||
@@ -170,12 +173,12 @@ while [ $# -gt 0 ]; do
|
||||
if [ -z "${CLIENT_ID}" ]; then
|
||||
cecho "Invalid Client ID, please update ${USER_CONFIG_FILE}";
|
||||
showAPIHelp;
|
||||
return 1
|
||||
return 1;
|
||||
fi
|
||||
if [ -z "${CLIENT_SECRET}" ]; then
|
||||
cecho "Invalid Client Secret, please update ${USER_CONFIG_FILE}";
|
||||
showAPIHelp;
|
||||
return 1
|
||||
return 1;
|
||||
fi
|
||||
SHPOTIFY_CREDENTIALS=$(printf "${CLIENT_ID}:${CLIENT_SECRET}" | base64 | tr -d "\n"|tr -d '\r');
|
||||
SPOTIFY_PLAY_URI="";
|
||||
@@ -198,7 +201,7 @@ while [ $# -gt 0 ]; do
|
||||
fi
|
||||
SPOTIFY_ACCESS_TOKEN=$( \
|
||||
printf "${SPOTIFY_TOKEN_RESPONSE_DATA}" \
|
||||
| grep -E -o '"access_token":".*",' \
|
||||
| command grep -E -o '"access_token":".*",' \
|
||||
| sed 's/"access_token"://g' \
|
||||
| sed 's/"//g' \
|
||||
| sed 's/,.*//g' \
|
||||
@@ -219,9 +222,8 @@ while [ $# -gt 0 ]; do
|
||||
-H "Accept: application/json" \
|
||||
--data-urlencode "q=$Q" \
|
||||
-d "type=$type&limit=1&offset=0" \
|
||||
| grep -E -o "spotify:$type:[a-zA-Z0-9]+" -m 1
|
||||
| command grep -E -o "spotify:$type:[a-zA-Z0-9]+" -m 1
|
||||
)
|
||||
echo "play uri: ${SPOTIFY_PLAY_URI}"
|
||||
}
|
||||
|
||||
case $2 in
|
||||
@@ -235,11 +237,11 @@ while [ $# -gt 0 ]; do
|
||||
|
||||
results=$( \
|
||||
curl -s -G $SPOTIFY_SEARCH_API --data-urlencode "q=$Q" -d "type=playlist&limit=10&offset=0" -H "Accept: application/json" -H "Authorization: Bearer ${SPOTIFY_ACCESS_TOKEN}" \
|
||||
| grep -E -o "spotify:playlist:[a-zA-Z0-9]+" -m 10 \
|
||||
| command grep -E -o "spotify:playlist:[a-zA-Z0-9]+" -m 10 \
|
||||
)
|
||||
|
||||
count=$( \
|
||||
echo "$results" | grep -c "spotify:playlist" \
|
||||
echo "$results" | command grep -c "spotify:playlist" \
|
||||
)
|
||||
|
||||
if [ "$count" -gt 0 ]; then
|
||||
@@ -333,16 +335,16 @@ while [ $# -gt 0 ]; do
|
||||
cecho "Current Spotify volume level is $vol.";
|
||||
break ;
|
||||
elif [ "$2" = "up" ]; then
|
||||
if [ $vol -le 90 ]; then
|
||||
newvol=$(( vol+10 ));
|
||||
if [ $vol -le $(( 100-$VOL_INCREMENT )) ]; then
|
||||
newvol=$(( vol+$VOL_INCREMENT ));
|
||||
cecho "Increasing Spotify volume to $newvol.";
|
||||
else
|
||||
newvol=100;
|
||||
cecho "Spotify volume level is at max.";
|
||||
fi
|
||||
elif [ "$2" = "down" ]; then
|
||||
if [ $vol -ge 10 ]; then
|
||||
newvol=$(( vol-10 ));
|
||||
if [ $vol -ge $(( $VOL_INCREMENT )) ]; then
|
||||
newvol=$(( vol-$VOL_INCREMENT ));
|
||||
cecho "Reducing Spotify volume to $newvol.";
|
||||
else
|
||||
newvol=0;
|
||||
@@ -354,11 +356,11 @@ while [ $# -gt 0 ]; do
|
||||
else
|
||||
echo "Improper use of 'vol' command"
|
||||
echo "The 'vol' command should be used as follows:"
|
||||
echo " vol up # Increases the volume by 10%.";
|
||||
echo " vol down # Decreases the volume by 10%.";
|
||||
echo " vol up # Increases the volume by $VOL_INCREMENT%.";
|
||||
echo " vol down # Decreases the volume by $VOL_INCREMENT%.";
|
||||
echo " vol [amount] # Sets the volume to an amount between 0 and 100.";
|
||||
echo " vol # Shows the current Spotify volume.";
|
||||
return 1
|
||||
return 1;
|
||||
fi
|
||||
|
||||
osascript -e "tell application \"Spotify\" to set sound volume to $newvol";
|
||||
@@ -468,10 +470,9 @@ while [ $# -gt 0 ]; do
|
||||
"help" )
|
||||
showHelp;
|
||||
break ;;
|
||||
|
||||
* )
|
||||
showHelp;
|
||||
return 1 ;;
|
||||
return 1;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user