1
0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2026-02-12 05:49:47 +08:00

Compare commits

..

3 Commits

Author SHA1 Message Date
Felipe Gallois
38ef5192cb
feat(oldgalois): add theme (#11880)
Closes #11879
2023-09-11 11:05:50 +02:00
Samuel Beckley
7077989d28
feat(macos): update spotify plugin to upstream (#11534) 2023-09-11 09:35:28 +02:00
AJ Jordan
cd18bce53e
feat(mortalscumbag): show toolbox info (#11884) 2023-09-11 09:31:53 +02:00
3 changed files with 49 additions and 18 deletions

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
function spotify() { 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 # Contains numerous helpful contributions from Jorge Colindres, Thomas
# Pritchard, iLan Epstein, Gabriele Bonetti, Sean Heller, Eric Martin # Pritchard, iLan Epstein, Gabriele Bonetti, Sean Heller, Eric Martin
@ -35,6 +35,9 @@ if ! [[ -f "${USER_CONFIG_FILE}" ]]; then
fi fi
source "${USER_CONFIG_FILE}"; source "${USER_CONFIG_FILE}";
# Set the percent change in volume for vol up and vol down
VOL_INCREMENT=10
showAPIHelp() { showAPIHelp() {
echo; echo;
echo "Connecting to Spotify's API:"; echo "Connecting to Spotify's API:";
@ -170,12 +173,12 @@ while [ $# -gt 0 ]; do
if [ -z "${CLIENT_ID}" ]; then if [ -z "${CLIENT_ID}" ]; then
cecho "Invalid Client ID, please update ${USER_CONFIG_FILE}"; cecho "Invalid Client ID, please update ${USER_CONFIG_FILE}";
showAPIHelp; showAPIHelp;
return 1 return 1;
fi fi
if [ -z "${CLIENT_SECRET}" ]; then if [ -z "${CLIENT_SECRET}" ]; then
cecho "Invalid Client Secret, please update ${USER_CONFIG_FILE}"; cecho "Invalid Client Secret, please update ${USER_CONFIG_FILE}";
showAPIHelp; showAPIHelp;
return 1 return 1;
fi fi
SHPOTIFY_CREDENTIALS=$(printf "${CLIENT_ID}:${CLIENT_SECRET}" | base64 | tr -d "\n"|tr -d '\r'); SHPOTIFY_CREDENTIALS=$(printf "${CLIENT_ID}:${CLIENT_SECRET}" | base64 | tr -d "\n"|tr -d '\r');
SPOTIFY_PLAY_URI=""; SPOTIFY_PLAY_URI="";
@ -198,7 +201,7 @@ while [ $# -gt 0 ]; do
fi fi
SPOTIFY_ACCESS_TOKEN=$( \ SPOTIFY_ACCESS_TOKEN=$( \
printf "${SPOTIFY_TOKEN_RESPONSE_DATA}" \ printf "${SPOTIFY_TOKEN_RESPONSE_DATA}" \
| grep -E -o '"access_token":".*",' \ | command grep -E -o '"access_token":".*",' \
| sed 's/"access_token"://g' \ | sed 's/"access_token"://g' \
| sed 's/"//g' \ | sed 's/"//g' \
| sed 's/,.*//g' \ | sed 's/,.*//g' \
@ -219,9 +222,8 @@ while [ $# -gt 0 ]; do
-H "Accept: application/json" \ -H "Accept: application/json" \
--data-urlencode "q=$Q" \ --data-urlencode "q=$Q" \
-d "type=$type&limit=1&offset=0" \ -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 case $2 in
@ -235,11 +237,11 @@ while [ $# -gt 0 ]; do
results=$( \ 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}" \ 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=$( \ count=$( \
echo "$results" | grep -c "spotify:playlist" \ echo "$results" | command grep -c "spotify:playlist" \
) )
if [ "$count" -gt 0 ]; then if [ "$count" -gt 0 ]; then
@ -333,16 +335,16 @@ while [ $# -gt 0 ]; do
cecho "Current Spotify volume level is $vol."; cecho "Current Spotify volume level is $vol.";
break ; break ;
elif [ "$2" = "up" ]; then elif [ "$2" = "up" ]; then
if [ $vol -le 90 ]; then if [ $vol -le $(( 100-$VOL_INCREMENT )) ]; then
newvol=$(( vol+10 )); newvol=$(( vol+$VOL_INCREMENT ));
cecho "Increasing Spotify volume to $newvol."; cecho "Increasing Spotify volume to $newvol.";
else else
newvol=100; newvol=100;
cecho "Spotify volume level is at max."; cecho "Spotify volume level is at max.";
fi fi
elif [ "$2" = "down" ]; then elif [ "$2" = "down" ]; then
if [ $vol -ge 10 ]; then if [ $vol -ge $(( $VOL_INCREMENT )) ]; then
newvol=$(( vol-10 )); newvol=$(( vol-$VOL_INCREMENT ));
cecho "Reducing Spotify volume to $newvol."; cecho "Reducing Spotify volume to $newvol.";
else else
newvol=0; newvol=0;
@ -354,11 +356,11 @@ while [ $# -gt 0 ]; do
else else
echo "Improper use of 'vol' command" echo "Improper use of 'vol' command"
echo "The 'vol' command should be used as follows:" echo "The 'vol' command should be used as follows:"
echo " vol up # Increases the volume by 10%."; echo " vol up # Increases the volume by $VOL_INCREMENT%.";
echo " vol down # Decreases the volume by 10%."; echo " vol down # Decreases the volume by $VOL_INCREMENT%.";
echo " vol [amount] # Sets the volume to an amount between 0 and 100."; echo " vol [amount] # Sets the volume to an amount between 0 and 100.";
echo " vol # Shows the current Spotify volume."; echo " vol # Shows the current Spotify volume.";
return 1 return 1;
fi fi
osascript -e "tell application \"Spotify\" to set sound volume to $newvol"; osascript -e "tell application \"Spotify\" to set sound volume to $newvol";
@ -468,10 +470,9 @@ while [ $# -gt 0 ]; do
"help" ) "help" )
showHelp; showHelp;
break ;; break ;;
* ) * )
showHelp; showHelp;
return 1 ;; return 1;
esac esac
done done

View File

@ -51,8 +51,14 @@ function ssh_connection() {
fi fi
} }
function _toolbox_prompt_info() {
if typeset -f toolbox_prompt_info > /dev/null; then
toolbox_prompt_info
fi
}
local ret_status="%(?:%{$fg_bold[green]%}:%{$fg_bold[red]%})%?%{$reset_color%}" local ret_status="%(?:%{$fg_bold[green]%}:%{$fg_bold[red]%})%?%{$reset_color%}"
PROMPT=$'\n$(ssh_connection)%{$fg_bold[green]%}%n@%m%{$reset_color%}$(my_git_prompt) : %~\n[${ret_status}] %# ' PROMPT=$'\n$(_toolbox_prompt_info)$(ssh_connection)%{$fg_bold[green]%}%n@%m%{$reset_color%}$(my_git_prompt) : %~\n[${ret_status}] %# '
ZSH_THEME_PROMPT_RETURNCODE_PREFIX="%{$fg_bold[red]%}" ZSH_THEME_PROMPT_RETURNCODE_PREFIX="%{$fg_bold[red]%}"
ZSH_THEME_GIT_PROMPT_PREFIX=" $fg[white] %{$fg_bold[yellow]%}" ZSH_THEME_GIT_PROMPT_PREFIX=" $fg[white] %{$fg_bold[yellow]%}"

View File

@ -0,0 +1,24 @@
# Depends on the git plugin for work_in_progress()
(( $+functions[work_in_progress] )) || work_in_progress() {}
ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[green]%}["
ZSH_THEME_GIT_PROMPT_SUFFIX="]%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}*%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN=""
# Customized git status, oh-my-zsh currently does not allow render dirty status before branch
git_custom_status() {
local branch=$(git_current_branch)
[[ -n "$branch" ]] || return 0
echo "$(parse_git_dirty)\
%{${fg_bold[yellow]}%}$(work_in_progress)%{$reset_color%}\
${ZSH_THEME_GIT_PROMPT_PREFIX}${branch}${ZSH_THEME_GIT_PROMPT_SUFFIX}"
}
# RVM component of prompt
ZSH_THEME_RUBY_PROMPT_PREFIX="%{$fg[red]%}["
ZSH_THEME_RUBY_PROMPT_SUFFIX="]%{$reset_color%}"
# Combine it all into a final right-side prompt
RPS1="\$(git_custom_status)\$(ruby_prompt_info)${RPS1:+ $RPS1}"
PROMPT='%{$fg[cyan]%}[%~% ]%(?.%{$fg[green]%}.%{$fg[red]%})%B$%b '