Skip to content

Instantly share code, notes, and snippets.

@archae0pteryx
Created May 23, 2022 18:00
Show Gist options
  • Save archae0pteryx/376c7e78662c89e222dc59b0d757bfdb to your computer and use it in GitHub Desktop.
Save archae0pteryx/376c7e78662c89e222dc59b0d757bfdb to your computer and use it in GitHub Desktop.
Script to select random oh-my-posh theme on shell init
POSH_THEME_DIR="$(brew --prefix oh-my-posh)/themes"
LIST_OF_THEMES=()
while IFS='' read -r line; do LIST_OF_THEMES+=("$line"); done < <(find "$POSH_THEME_DIR" -type f -print)
TOTAL_NUM_THEMES=${#LIST_OF_THEMES[@]}
RAND_NUM=$(( RANDOM % TOTAL_NUM_THEMES ))
SELECTED_THEME="${LIST_OF_THEMES[$RAND_NUM]}"
echo "${SELECTED_THEME}"
eval "$(oh-my-posh --init --shell zsh --config ${SELECTED_THEME})"
@archae0pteryx
Copy link
Author

archae0pteryx commented May 23, 2022

Ex. usage

  • copy gist curl -o https://gist.github.com/archae0pteryx/376c7e78662c89e222dc59b0d757bfdb ~/.config/random-posh-theme
  • add to ~/.zshrc like so source ~/.config/random-posh-theme
  • restart shell source ~/.zshrc

When you find one you like, you can copy the eval "$(...)" line with the path to the theme output when the shell loaded directly into your ~/.zshrc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment