dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

commit eba9e3a7a9c8f745f662cd940456504c765a0335
parent 84274f1953966a0b8cfdd1766d7c45314e7da125
Author: Alex Balgavy <a.balgavy@gmail.com>
Date:   Sun, 13 Jan 2019 23:34:59 +0100

Separated scripts and binaries


Former-commit-id: 97a4d46aac205d09ba1bb6b4ed507d161cfe0e35
Diffstat:
Dbin/conf | 135-------------------------------------------------------------------------------
Dbin/it-style | 150-------------------------------------------------------------------------------
Dbin/play | 135-------------------------------------------------------------------------------
Dbin/radio | 54------------------------------------------------------
Minstall.sh | 4++--
Rbin/anythingtogif -> scripts/anythingtogif | 0
Rbin/clonedisk -> scripts/clonedisk | 0
Rbin/clonedisk-ignore -> scripts/clonedisk-ignore | 0
Ascripts/conf | 139+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rbin/dashedit.rb -> scripts/dashedit.rb | 0
Rbin/epub-convert -> scripts/epub-convert | 0
Rbin/executable -> scripts/executable | 0
Rbin/ffmpeg-split-README.md -> scripts/ffmpeg-split-README.md | 0
Rbin/ffmpeg-split.py -> scripts/ffmpeg-split.py | 0
Ascripts/it-style | 150+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rbin/it-style-helper.rb -> scripts/it-style-helper.rb | 0
Rbin/linkdir -> scripts/linkdir | 0
Rbin/mdvl -> scripts/mdvl | 0
Rbin/modified_cfscrape.py -> scripts/modified_cfscrape.py | 0
Rbin/mp3tagger.jar -> scripts/mp3tagger.jar | 0
Rbin/percerr.rb -> scripts/percerr.rb | 0
Ascripts/play | 135+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ascripts/radio | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rbin/rplayer -> scripts/rplayer | 0
Rbin/smack.pl -> scripts/smack.pl | 0
Rbin/ss-interceptor -> scripts/ss-interceptor | 0
Rbin/strip-html-tags -> scripts/strip-html-tags | 0
Rbin/tag -> scripts/tag | 0
Rbin/tcprelay.py -> scripts/tcprelay.py | 0
Rbin/topdf -> scripts/topdf | 0
Rbin/updatemaster -> scripts/updatemaster | 0
Rbin/usbmux.py -> scripts/usbmux.py | 0
Rbin/usbmux.pyc -> scripts/usbmux.pyc | 0
Rbin/vimwiki_md -> scripts/vimwiki_md | 0
Rbin/vimwiki_md_ex -> scripts/vimwiki_md_ex | 0
Rbin/visualizer.lua -> scripts/visualizer.lua | 0
Rbin/vwtags.py -> scripts/vwtags.py | 0
Rbin/wattpad-scrape -> scripts/wattpad-scrape | 0
Mshell/commonprofile | 9++++++---
Mvim/pluginconf.vimrc | 2+-
40 files changed, 487 insertions(+), 480 deletions(-)

diff --git a/bin/conf b/bin/conf @@ -1,135 +0,0 @@ -#!/bin/sh -# vim: foldmethod=marker:foldlevel=0 - -# Main linking command {{{ -lncommand() { - if [ -e "$1" ]; then - if [ -e "$2" ]; then - echo "-- Backing up original $2" - mv -iv "$2" "$2-orig" - fi - ln -snfv "$1" "$2"; - fi -} -#}}} - -# Use command {{{ -use_files() { - if [ $# -gt 0 ]; then - for f in "$@"; do - case "${f##./}" in - "bin") - lncommand "$CONF_DIR/bin" "$HOME/.bin" - if command -v mpv &> /dev/null; then - mkdir -p "$HOME/.config/mpv" - lncommand "$CONF_DIR/.bin/visualizer.lua" "$HOME/.config/mpv/visualizer.lua" - fi - ;; - "ctags") - lncommand "$CONF_DIR/ctags/ctags" "$HOME/.ctags" - ;; - "gdb") - lncommand "$CONF_DIR/gdb/gdbinit" "$HOME/.gdbinit" - ;; - - "git") - lncommand "$CONF_DIR/git/gitconfig" "$HOME/.gitconfig" - if [ -d git/git_template ]; then - conf_check git config --global init.templatedir "$CONF_DIR"/git/git_template - fi - ;; - "iterm2") - lncommand "$CONF_DIR/iterm2" "$HOME/.iterm2" - ;; - "oh-my-zsh") - lncommand "$CONF_DIR/oh-my-zsh" "$HOME/.oh-my-zsh" - ;; - "radio") - lncommand "$CONF_DIR/radio/radio-config" "$HOME/.radio-config" - ;; - - "shell") - for i in shell/*; do - lncommand "$CONF_DIR/$i" "$HOME/.${i##*/}" - done - ;; - "vim") - lncommand "$CONF_DIR/vim/init.vimrc" "$HOME/.vimrc" # vimrc points directly to other vim configs - lncommand "$CONF_DIR/vim/idea.vimrc" "$HOME/.ideavimrc" # ideavimrc has to be separate - ;; - esac - - done - else - echo "Config files:" - echo "bin various executable scripts" - echo "ctags language definitions for ctags" - echo "gdb gdb dashboard and the like" - echo "git git config files and hooks" - echo "oh-my-zsh the whole oh-my-zsh config directory" - echo "radio radio metadata for the internet radio script" - echo "shell various configs related to shells" - echo "vim vim configuration files" - fi -} -#}}} - -# Check if $CONF_DIR is set {{{ -conf_check() { - if [ -z "$CONF_DIR" ]; then - echo "\$CONF_DIR not set." - echo "Please set the CONF_DIR environment variable to your dotfiles repository." - else - "$@" - fi -} -#}}} - -# Run with arguments {{{ -if [ $# -gt 0 ]; then - if [ "$1" = 'rc' ]; then - if [[ $SHELL = *"zsh"* ]]; then - if [ -f "$HOME"/.zshrc ]; then - "$EDITOR" "$HOME"/.zshrc - else - echo "File $HOME/.zshrc does not exist." - fi - elif [[ $SHELL = *"bash"* ]]; then - if [ -f "$HOME"/.bashrc ]; then - "$EDITOR" "$HOME"/.bashrc - elif [ -f "$HOME"/.bash_profile ]; then - "$EDITOR" "$HOME"/.bash_profile - else - echo "File $HOME/.bashrc does not exist." - fi - else - echo "Shell profile not supported yet." - echo "Feel free to ask me to add support, or you can do it yourself." - fi - - elif [ "$1" = 'common' ]; then - if [ -f "$HOME"/.commonprofile ]; then - "$EDITOR" "$HOME"/.commonprofile - else - echo "File $HOME/.commonprofile does not exist." - fi - elif [ "$1" = 'get' ]; then - conf_check echo "$CONF_DIR" - - elif [ "$1" = 'use' ]; then - conf_check use_files "${@:2}" - - else - conf_check "$(command -v git)" --git-dir="$CONF_DIR"/.git --work-tree "$CONF_DIR" "$@" - fi - #}}} - # ...or print help text {{{ -else - echo "Usage:" - echo "conf rc Edit shell-specific profile (zshrc, bashrc, etc.)" - echo "conf common Edit common profile" - echo "conf get Print path to configuration directory" - echo "conf use [module] Use dotfiles for a specific module (vim, git, shell, etc.)" - echo "conf [git command] Run git command in conf directory" -fi -#}}} diff --git a/bin/it-style b/bin/it-style @@ -1,149 +0,0 @@ -#!/usr/bin/env bash -oldifs="$IFS" -while :; do - if [ $# -ne 0 ]; then - case $1 in - "-p") - artist=$(osascript -e "tell application \"iTunes\" to return artist of current track"); - album=$(osascript -e "tell application \"iTunes\" to return album of current track"); - name=$(osascript -e "tell application \"iTunes\" to return name of current track"); - ;; - "-s") - artist=$(osascript -e "tell application \"iTunes\" to return artist of selection"); - album=$(osascript -e "tell application \"iTunes\" to return album of selection"); - name=$(osascript -e "tell application \"iTunes\" to return name of selection"); - esac - else - echo "Which track?" - select sc in "Selected" "Playing"; do - case $sc in - Selected) - artist=$(osascript -e "tell application \"iTunes\" to return artist of selection"); - album=$(osascript -e "tell application \"iTunes\" to return album of selection"); - name=$(osascript -e "tell application \"iTunes\" to return name of selection"); - break;; - Playing) - artist=$(osascript -e "tell application \"iTunes\" to return artist of current track"); - album=$(osascript -e "tell application \"iTunes\" to return album of current track"); - name=$(osascript -e "tell application \"iTunes\" to return name of current track"); - break;; - esac - done - fi - - if [ -z "$album" ]; then - # If there's no album, query without an album - search_url="https://www.discogs.com/search/?q="$(sed -e 's/ /%20/g' -e 's/&/%26/g' <<< "$artist $name") - echo "Querying: \"$artist $name\" ($search_url)" - response=$(ruby /Users/alex/.bin/it-style-helper.rb "$artist" "$name"); - else - # Otherwise, add the album to query for precision - search_url="https://www.discogs.com/search/?q="$(sed -e 's/ /%20/g' -e 's/&/%26/g' <<< "$artist $album") - echo "Querying: \"$artist $album\" ($search_url)" - response=$(ruby /Users/alex/.bin/it-style-helper.rb "$artist" "$album"); - fi - - # Remove brackets from the Ruby array - response=$(sed -e 's/^\[//' -e 's/\]$//' <<< "$response") - - # Read the response into a bash array (genres, styles, url) - IFS=',' read -ra response <<< "${response}"; unset IFS - - # Create a bash array from the genres, stripping quotes - IFS='~' read -ra genre <<< "${response[0]//\"/}"; unset IFS - genre=$(sed -e 's/^ //' <<< $genre) - - # Create a bash array from the styles, stripping quotes - # potential regex to surround each style in quotes: 's/\([^~]*\)/"\1"/g' - - IFS='~' read -ra style <<< "${response[1]//\"/}"; unset IFS - style=$(sed -e 's/^ //' <<< $style) - - # Save the url as a string, stripping quotes (and remove the brackets entered by Ruby) - url=$(sed -e 's/^ *\[//' -e 's/\]$//' <<<${response[2]//\"/}) - - # If there's no url, there's no result - if [ -z "$url" ]; then - echo -e "\nNot found.\n" - continue - fi - - IFS="$oldifs" - - # Give the user the source information - echo "URL: $url" - echo "You're changing the album \"$album\" by \"$artist\"" - printf '\n' - - # Select menu for genre - echo "Genre options:" - printf '%s\n' "${genre[@]}" - printf "\nWould you like to use one of these?\n" - select yn in "Yes" "No"; do - case $yn in - Yes) - select opt in "${genre[@]}"; do - case $opt in - *) - finalg=$(sed -e 's/"//g' <<< $opt) - if [[ $finalg = "Hip Hop" ]]; then finalg="Hip-Hop"; fi # consistency - break;; - esac - done - break;; - No) - echo "Write your own then:" - read finalg - if [[ $finalg = "Hip Hop" ]]; then finalg="Hip-Hop"; fi # consistency - if [[ $finalg = "Post-Rock" ]]; then finalg="Post Rock"; fi # consistency - break;; - esac - done - - # Select menu for style - if [ -z "$style" ]; then - echo "No style from Discogs." - echo "Write your own:" - read finals - finals="/$finals" - else - echo "Style options:" - printf '%s\n' "${style[@]}" - printf "\nWould you like to use one of these?\n" - select yn in "Yes" "No" "None needed"; do - case $yn in - Yes) - select opt in "${style[@]}"; do - case $opt in - *) - # Add a forward slash at start, remove extra spaces, - # also remove repetitions in genre/style like "Rock/Alternative Rock" - finals="/"$(echo $opt | cut -d ' ' -f1- | sed -e "s/\"//g" -e "s/ *$finalg *//") - break;; - esac - done - break;; - No) - echo "Write your own then:" - read finals - finals="/$finals" - break;; - "None needed") - finals="" - break;; - esac - done - fi - - # Finally, write the info to the iTunes track (AppleScript) - # If there's an album, change the genre of the whole album - if [ -z "$album" ]; then - osascript -e "tell application \"iTunes\" to set the genre of every track whose name is \"$name\" and artist is \"${artist}\" to \"$finalg$finals\"" > /dev/null - # Otherwise, just change the genre of that one track - else - osascript -e "tell application \"iTunes\" to set the genre of every track whose album is \"$album\" and artist is \"${artist}\" to \"$finalg$finals\"" > /dev/null - fi - - # ...and give a status message. - printf "\nGenre set to: $finalg$finals\n" -done- \ No newline at end of file diff --git a/bin/play b/bin/play @@ -1,135 +0,0 @@ -#!/usr/bin/env bash - -rootdir="$MUSIC_DIR" -mpv_options="--no-video --really-quiet --volume=50" -mpv_options_vis="--no-video --really-quiet --volume=50 --script=/Users/alex/.config/mpv/visualizer.lua -vo caca" -mpv_options_noart="--no-video --volume=50" - -play_track() { - trap '' INT - vis=0 - if [ -z "$2" ]; then - vis=1 - fi - if [[ "$1" == "all" ]]; then - track=$(ls|sort -n|head -1) - ffmpeg -i "$track" art.jpg &>/dev/null - - if [ -e "art.jpg" ] && [ $vis -eq 1 ]; then - im2a art.jpg -T - mpv "$(pwd)" $mpv_options - rm art.jpg - elif [ $vis -eq 1 ]; then - mpv "$(pwd)" $mpv_options_vis - else - clear - mpv "$(pwd)" $mpv_options_noart - fi - else - if [ ! -e "$1" ]; then - echo "File does not exist: $1" - else - ffmpeg -i "$1" art.jpg &>/dev/null - if [ -e "art.jpg" ] && [ $vis -eq 1 ] ; then - im2a art.jpg -T - mpv "$(pwd)/$1" $mpv_options - rm art.jpg - elif [ $vis -eq 1 ]; then - mpv "$(pwd)/$1" $mpv_options_vis - else - clear - mpv "$(pwd)/$1" $mpv_options_noart - fi - fi - fi - trap clean_up INT - clear -} -read_letter() { - read -sn 1 -p "Continue? [Y/n]" CONF -} -clean_up() { - trap - INT - clear - exit 0 -} - -init_check() { - deps=(ffmpeg mpv im2a) - for dep in ${deps[@]}; do - if ! command -v $dep &>/dev/null; then - echo "Please install $dep." - exit 1 - fi - done -} - -init_check -cd /Users/alex/Music/iTunes/iTunes\ Media/Music -trap clean_up INT -clear -echo "Music Player v1" -while :; do - read -e -p "> " -a INPUT - CMD=${INPUT[0]} - ARGS=("${INPUT[@]:1}") - case $CMD in - "cd") - if [ -z "$ARGS" ]; then - echo "No directory provided." - elif [[ "$ARGS" == "/" ]]; then - cd "$rootdir" - elif [ ! -d "$ARGS" ]; then - echo "Directory does not exist." - else - pushd "$ARGS" &>/dev/null - if [[ $(pwd) == $rootdir* ]]; then - popd &>/dev/null - cd "$ARGS" - else - echo "Cannot enter this directory." - popd&>/dev/null - fi - fi - ;; - "play") - if [ -z "$ARGS" ]; then - echo "No file provided." - else - play_track "${ARGS[@]}" - fi - ;; - "ls") - if command -v less &> /dev/null; then - ls -C | less - elif command -v more &> /dev/null; then - ls -C | more - else - ls -C - fi - ;; - "pwd") - dir=$(pwd) - if [[ $dir == $rootdir ]]; then - echo "/" - else - echo ${dir##$rootdir} - fi - ;; - "q"|"quit") - clean_up;; - "help") - echo "Commands:" - echo "cd: change to artist/album directory" - echo "pwd: print current directory" - echo "ls: list contents of current directory" - echo "play all: play everything in current directory" - echo "play [file]: play specific track" - echo "play [all|file] [something]: disable visualiser/art" - ;; - *) - echo "Command does not exist." - echo "Type 'help' to show commands." - ;; - esac -done diff --git a/bin/radio b/bin/radio @@ -1,54 +0,0 @@ -#!/usr/bin/env bash - -# Initial config, setting $radios and $radio_names -if [ -e ~/.radio-config ]; then - source ~/.radio-config -elif [ -e ~/.config/radio-config ]; then - source ~/.config/radio-config -else - echo "No radios set up. Please create a config file." - exit 1 -fi - -## MAIN SCRIPT ## - -VISUALISER=false -while getopts ":v" opt; do - case ${opt} in - v ) - VISUALISER=true - esac -done - -clear -echo "Welcome to the command line radio player." -PS3="Select a radio, or type q to exit: " -select RADIO in "${radio_names[@]}" -do - if [[ $RADIO = "q" ]]; then - break - else - for i in "${!radio_names[@]}"; do - if [[ "${radio_names[$i]}" = "${RADIO}" ]]; then - if [[ "$RADIO" = "Play from music subreddit" ]]; then - if command -v rplayer &> /dev/null; then - rplayer - else - echo "rplayer not in path." - fi - else - clear - echo "Now playing $RADIO" - echo "Loading..." - if $VISUALISER; then - nice -n 20 mpv ${radios[$i]} --volume=50 --script="/Users/alex/.config/mpv/visualizer.lua" --really-quiet -vo caca - else - nice -n 20 mpv ${radios[$i]} --volume=50 - fi - break - fi - fi - done - break - fi -done diff --git a/install.sh b/install.sh @@ -37,13 +37,13 @@ read -n 1 -p "Install all dotfiles? [Y/n]" yn echo case $yn in [Yy]* ) - bin/conf use $(find . ! -iwholename '*.git*' -type d -d 1) + scripts/conf use $(find . ! -iwholename '*.git*' -type d -d 1) echo "Dotfiles installed." echo "Run \`conf\` for more help." ;; * ) echo "No dotfiles installed automatically." - echo "Run \`bin/conf\` for more help." + echo "Run \`scripts/conf\` for more help." ;; esac diff --git a/bin/anythingtogif b/scripts/anythingtogif diff --git a/bin/clonedisk b/scripts/clonedisk diff --git a/bin/clonedisk-ignore b/scripts/clonedisk-ignore diff --git a/scripts/conf b/scripts/conf @@ -0,0 +1,139 @@ +#!/bin/sh +# vim: foldmethod=marker:foldlevel=0 + +# Main linking command {{{ +lncommand() { + if [ -e "$1" ]; then + if [ -e "$2" ]; then + echo "-- Backing up original $2" + mv -iv "$2" "$2-orig" + fi + ln -snfv "$1" "$2"; + fi +} +#}}} + +# Use command {{{ +use_files() { + if [ $# -gt 0 ]; then + for f in "$@"; do + case "${f##./}" in + "bin") + lncommand "$CONF_DIR/bin" "$HOME/.bin" + ;; + "ctags") + lncommand "$CONF_DIR/ctags/ctags" "$HOME/.ctags" + ;; + "gdb") + lncommand "$CONF_DIR/gdb/gdbinit" "$HOME/.gdbinit" + ;; + + "git") + lncommand "$CONF_DIR/git/gitconfig" "$HOME/.gitconfig" + if [ -d git/git_template ]; then + conf_check git config --global init.templatedir "$CONF_DIR"/git/git_template + fi + ;; + "iterm2") + lncommand "$CONF_DIR/iterm2" "$HOME/.iterm2" + ;; + "oh-my-zsh") + lncommand "$CONF_DIR/oh-my-zsh" "$HOME/.oh-my-zsh" + ;; + "radio") + lncommand "$CONF_DIR/radio/radio-config" "$HOME/.radio-config" + ;; + + "scripts") + lncommand "$CONF_DIR/scripts" "$HOME/.scripts" + if command -v mpv &> /dev/null; then + mkdir -p "$HOME/.config/mpv" + lncommand "$CONF_DIR/.scripts/visualizer.lua" "$HOME/.config/mpv/visualizer.lua" + fi + ;; + "shell") + for i in shell/*; do + lncommand "$CONF_DIR/$i" "$HOME/.${i##*/}" + done + ;; + "vim") + lncommand "$CONF_DIR/vim/init.vimrc" "$HOME/.vimrc" # vimrc points directly to other vim configs + lncommand "$CONF_DIR/vim/idea.vimrc" "$HOME/.ideavimrc" # ideavimrc has to be separate + ;; + esac + + done + else + echo "Config files:" + echo "bin various binaries" + echo "ctags language definitions for ctags" + echo "gdb gdb dashboard and the like" + echo "git git config files and hooks" + echo "oh-my-zsh the whole oh-my-zsh config directory" + echo "radio radio metadata for the internet radio script" + echo "scripts misc executable scripts (like this one" + echo "shell various configs related to shells" + echo "vim vim configuration files" + fi +} +#}}} + +# Check if $CONF_DIR is set {{{ +conf_check() { + if [ -z "$CONF_DIR" ]; then + echo "\$CONF_DIR not set." + echo "Please set the CONF_DIR environment variable to your dotfiles repository." + else + "$@" + fi +} +#}}} + +# Run with arguments {{{ +if [ $# -gt 0 ]; then + if [ "$1" = 'rc' ]; then + if [[ $SHELL = *"zsh"* ]]; then + if [ -f "$HOME"/.zshrc ]; then + "$EDITOR" "$HOME"/.zshrc + else + echo "File $HOME/.zshrc does not exist." + fi + elif [[ $SHELL = *"bash"* ]]; then + if [ -f "$HOME"/.bashrc ]; then + "$EDITOR" "$HOME"/.bashrc + elif [ -f "$HOME"/.bash_profile ]; then + "$EDITOR" "$HOME"/.bash_profile + else + echo "File $HOME/.bashrc does not exist." + fi + else + echo "Shell profile not supported yet." + echo "Feel free to ask me to add support, or you can do it yourself." + fi + + elif [ "$1" = 'common' ]; then + if [ -f "$HOME"/.commonprofile ]; then + "$EDITOR" "$HOME"/.commonprofile + else + echo "File $HOME/.commonprofile does not exist." + fi + elif [ "$1" = 'get' ]; then + conf_check echo "$CONF_DIR" + + elif [ "$1" = 'use' ]; then + conf_check use_files "${@:2}" + + else + conf_check "$(command -v git)" --git-dir="$CONF_DIR"/.git --work-tree "$CONF_DIR" "$@" + fi + #}}} + # ...or print help text {{{ +else + echo "Usage:" + echo "conf rc Edit shell-specific profile (zshrc, bashrc, etc.)" + echo "conf common Edit common profile" + echo "conf get Print path to configuration directory" + echo "conf use [module] Use dotfiles for a specific module (vim, git, shell, etc.)" + echo "conf [git command] Run git command in conf directory" +fi +#}}} diff --git a/bin/dashedit.rb b/scripts/dashedit.rb diff --git a/bin/epub-convert b/scripts/epub-convert diff --git a/bin/executable b/scripts/executable diff --git a/bin/ffmpeg-split-README.md b/scripts/ffmpeg-split-README.md diff --git a/bin/ffmpeg-split.py b/scripts/ffmpeg-split.py diff --git a/scripts/it-style b/scripts/it-style @@ -0,0 +1,149 @@ +#!/usr/bin/env bash +oldifs="$IFS" +while :; do + if [ $# -ne 0 ]; then + case $1 in + "-p") + artist=$(osascript -e "tell application \"iTunes\" to return artist of current track"); + album=$(osascript -e "tell application \"iTunes\" to return album of current track"); + name=$(osascript -e "tell application \"iTunes\" to return name of current track"); + ;; + "-s") + artist=$(osascript -e "tell application \"iTunes\" to return artist of selection"); + album=$(osascript -e "tell application \"iTunes\" to return album of selection"); + name=$(osascript -e "tell application \"iTunes\" to return name of selection"); + esac + else + echo "Which track?" + select sc in "Selected" "Playing"; do + case $sc in + Selected) + artist=$(osascript -e "tell application \"iTunes\" to return artist of selection"); + album=$(osascript -e "tell application \"iTunes\" to return album of selection"); + name=$(osascript -e "tell application \"iTunes\" to return name of selection"); + break;; + Playing) + artist=$(osascript -e "tell application \"iTunes\" to return artist of current track"); + album=$(osascript -e "tell application \"iTunes\" to return album of current track"); + name=$(osascript -e "tell application \"iTunes\" to return name of current track"); + break;; + esac + done + fi + + if [ -z "$album" ]; then + # If there's no album, query without an album + search_url="https://www.discogs.com/search/?q="$(sed -e 's/ /%20/g' -e 's/&/%26/g' <<< "$artist $name") + echo "Querying: \"$artist $name\" ($search_url)" + response=$(ruby $CONF_DIR/scripts/it-style-helper.rb "$artist" "$name"); + else + # Otherwise, add the album to query for precision + search_url="https://www.discogs.com/search/?q="$(sed -e 's/ /%20/g' -e 's/&/%26/g' <<< "$artist $album") + echo "Querying: \"$artist $album\" ($search_url)" + response=$(ruby $CONF_DIR/scripts/it-style-helper.rb "$artist" "$album"); + fi + + # Remove brackets from the Ruby array + response=$(sed -e 's/^\[//' -e 's/\]$//' <<< "$response") + + # Read the response into a bash array (genres, styles, url) + IFS=',' read -ra response <<< "${response}"; unset IFS + + # Create a bash array from the genres, stripping quotes + IFS='~' read -ra genre <<< "${response[0]//\"/}"; unset IFS + genre=$(sed -e 's/^ //' <<< $genre) + + # Create a bash array from the styles, stripping quotes + # potential regex to surround each style in quotes: 's/\([^~]*\)/"\1"/g' + + IFS='~' read -ra style <<< "${response[1]//\"/}"; unset IFS + style=$(sed -e 's/^ //' <<< $style) + + # Save the url as a string, stripping quotes (and remove the brackets entered by Ruby) + url=$(sed -e 's/^ *\[//' -e 's/\]$//' <<<${response[2]//\"/}) + + # If there's no url, there's no result + if [ -z "$url" ]; then + echo -e "\nNot found.\n" + continue + fi + + IFS="$oldifs" + + # Give the user the source information + echo "URL: $url" + echo "You're changing the album \"$album\" by \"$artist\"" + printf '\n' + + # Select menu for genre + echo "Genre options:" + printf '%s\n' "${genre[@]}" + printf "\nWould you like to use one of these?\n" + select yn in "Yes" "No"; do + case $yn in + Yes) + select opt in "${genre[@]}"; do + case $opt in + *) + finalg=$(sed -e 's/"//g' <<< $opt) + if [[ $finalg = "Hip Hop" ]]; then finalg="Hip-Hop"; fi # consistency + break;; + esac + done + break;; + No) + echo "Write your own then:" + read finalg + if [[ $finalg = "Hip Hop" ]]; then finalg="Hip-Hop"; fi # consistency + if [[ $finalg = "Post-Rock" ]]; then finalg="Post Rock"; fi # consistency + break;; + esac + done + + # Select menu for style + if [ -z "$style" ]; then + echo "No style from Discogs." + echo "Write your own:" + read finals + finals="/$finals" + else + echo "Style options:" + printf '%s\n' "${style[@]}" + printf "\nWould you like to use one of these?\n" + select yn in "Yes" "No" "None needed"; do + case $yn in + Yes) + select opt in "${style[@]}"; do + case $opt in + *) + # Add a forward slash at start, remove extra spaces, + # also remove repetitions in genre/style like "Rock/Alternative Rock" + finals="/"$(echo $opt | cut -d ' ' -f1- | sed -e "s/\"//g" -e "s/ *$finalg *//") + break;; + esac + done + break;; + No) + echo "Write your own then:" + read finals + finals="/$finals" + break;; + "None needed") + finals="" + break;; + esac + done + fi + + # Finally, write the info to the iTunes track (AppleScript) + # If there's an album, change the genre of the whole album + if [ -z "$album" ]; then + osascript -e "tell application \"iTunes\" to set the genre of every track whose name is \"$name\" and artist is \"${artist}\" to \"$finalg$finals\"" > /dev/null + # Otherwise, just change the genre of that one track + else + osascript -e "tell application \"iTunes\" to set the genre of every track whose album is \"$album\" and artist is \"${artist}\" to \"$finalg$finals\"" > /dev/null + fi + + # ...and give a status message. + printf "\nGenre set to: $finalg$finals\n" +done+ \ No newline at end of file diff --git a/bin/it-style-helper.rb b/scripts/it-style-helper.rb diff --git a/bin/linkdir b/scripts/linkdir diff --git a/bin/mdvl b/scripts/mdvl diff --git a/bin/modified_cfscrape.py b/scripts/modified_cfscrape.py diff --git a/bin/mp3tagger.jar b/scripts/mp3tagger.jar Binary files differ. diff --git a/bin/percerr.rb b/scripts/percerr.rb diff --git a/scripts/play b/scripts/play @@ -0,0 +1,135 @@ +#!/usr/bin/env bash + +rootdir="$MUSIC_DIR" +mpv_options="--no-video --really-quiet --volume=50" +mpv_options_vis="--no-video --really-quiet --volume=50 --script=$HOME/.config/mpv/visualizer.lua -vo caca" +mpv_options_noart="--no-video --volume=50" + +play_track() { + trap '' INT + vis=0 + if [ -z "$2" ]; then + vis=1 + fi + if [[ "$1" == "all" ]]; then + track=$(ls|sort -n|head -1) + ffmpeg -i "$track" art.jpg &>/dev/null + + if [ -e "art.jpg" ] && [ $vis -eq 1 ]; then + im2a art.jpg -T + mpv "$(pwd)" $mpv_options + rm art.jpg + elif [ $vis -eq 1 ]; then + mpv "$(pwd)" $mpv_options_vis + else + clear + mpv "$(pwd)" $mpv_options_noart + fi + else + if [ ! -e "$1" ]; then + echo "File does not exist: $1" + else + ffmpeg -i "$1" art.jpg &>/dev/null + if [ -e "art.jpg" ] && [ $vis -eq 1 ] ; then + im2a art.jpg -T + mpv "$(pwd)/$1" $mpv_options + rm art.jpg + elif [ $vis -eq 1 ]; then + mpv "$(pwd)/$1" $mpv_options_vis + else + clear + mpv "$(pwd)/$1" $mpv_options_noart + fi + fi + fi + trap clean_up INT + clear +} +read_letter() { + read -sn 1 -p "Continue? [Y/n]" CONF +} +clean_up() { + trap - INT + clear + exit 0 +} + +init_check() { + deps=(ffmpeg mpv im2a) + for dep in ${deps[@]}; do + if ! command -v $dep &>/dev/null; then + echo "Please install $dep." + exit 1 + fi + done +} + +init_check +cd "$rootdir" +trap clean_up INT +clear +echo "Music Player v1" +while :; do + read -e -p "> " -a INPUT + CMD=${INPUT[0]} + ARGS=("${INPUT[@]:1}") + case $CMD in + "cd") + if [ -z "$ARGS" ]; then + echo "No directory provided." + elif [[ "$ARGS" == "/" ]]; then + cd "$rootdir" + elif [ ! -d "$ARGS" ]; then + echo "Directory does not exist." + else + pushd "$ARGS" &>/dev/null + if [[ $(pwd) == $rootdir* ]]; then + popd &>/dev/null + cd "$ARGS" + else + echo "Cannot enter this directory." + popd&>/dev/null + fi + fi + ;; + "play") + if [ -z "$ARGS" ]; then + echo "No file provided." + else + play_track "${ARGS[@]}" + fi + ;; + "ls") + if command -v less &> /dev/null; then + ls -C | less + elif command -v more &> /dev/null; then + ls -C | more + else + ls -C + fi + ;; + "pwd") + dir=$(pwd) + if [[ $dir == $rootdir ]]; then + echo "/" + else + echo ${dir##$rootdir} + fi + ;; + "q"|"quit") + clean_up;; + "help") + echo "Commands:" + echo "cd: change to artist/album directory" + echo "pwd: print current directory" + echo "ls: list contents of current directory" + echo "play all: play everything in current directory" + echo "play [file]: play specific track" + echo "play [all|file] [something]: disable visualiser/art" + ;; + *) + echo "Command does not exist." + echo "Type 'help' to show commands." + ;; + esac +done diff --git a/scripts/radio b/scripts/radio @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +# Initial config, setting $radios and $radio_names +if [ -e ~/.radio-config ]; then + source ~/.radio-config +elif [ -e ~/.config/radio-config ]; then + source ~/.config/radio-config +else + echo "No radios set up. Please create a config file." + exit 1 +fi + +## MAIN SCRIPT ## + +VISUALISER=false +while getopts ":v" opt; do + case ${opt} in + v ) + VISUALISER=true + esac +done + +clear +echo "Welcome to the command line radio player." +PS3="Select a radio, or type q to exit: " +select RADIO in "${radio_names[@]}" +do + if [[ $RADIO = "q" ]]; then + break + else + for i in "${!radio_names[@]}"; do + if [[ "${radio_names[$i]}" = "${RADIO}" ]]; then + if [[ "$RADIO" = "Play from music subreddit" ]]; then + if command -v rplayer &> /dev/null; then + rplayer + else + echo "rplayer not in path." + fi + else + clear + echo "Now playing $RADIO" + echo "Loading..." + if $VISUALISER; then + nice -n 20 mpv ${radios[$i]} --volume=50 --script="$HOME/.config/mpv/visualizer.lua" --really-quiet -vo caca + else + nice -n 20 mpv ${radios[$i]} --volume=50 + fi + break + fi + fi + done + break + fi +done diff --git a/bin/rplayer b/scripts/rplayer diff --git a/bin/smack.pl b/scripts/smack.pl diff --git a/bin/ss-interceptor b/scripts/ss-interceptor diff --git a/bin/strip-html-tags b/scripts/strip-html-tags diff --git a/bin/tag b/scripts/tag diff --git a/bin/tcprelay.py b/scripts/tcprelay.py diff --git a/bin/topdf b/scripts/topdf diff --git a/bin/updatemaster b/scripts/updatemaster diff --git a/bin/usbmux.py b/scripts/usbmux.py diff --git a/bin/usbmux.pyc b/scripts/usbmux.pyc Binary files differ. diff --git a/bin/vimwiki_md b/scripts/vimwiki_md diff --git a/bin/vimwiki_md_ex b/scripts/vimwiki_md_ex diff --git a/bin/visualizer.lua b/scripts/visualizer.lua diff --git a/bin/vwtags.py b/scripts/vwtags.py diff --git a/bin/wattpad-scrape b/scripts/wattpad-scrape diff --git a/shell/commonprofile b/shell/commonprofile @@ -20,9 +20,12 @@ if [ -f "$HOME/.secret_env_variables" ]; then fi # Include my scripts in PATH (conditionally) -if [[ $PATH != *"/Users/alex/.bin"* ]]; then +if [[ $PATH != *"$HOME/.bin"* ]]; then PATH=$HOME/.bin:$PATH fi +if [[ $PATH != *"$HOME/.scripts"* ]]; then + PATH=$HOME/.scripts:$PATH +fi # Golang if command -v go &> /dev/null; then @@ -108,8 +111,8 @@ alias startpg='pg_ctl -D $(brew --prefix)/var/postgres start' # }}} # Aliases (Dougscripts trial resets) {{{ -alias rs_notinplaylist="rm /Users/alex/Library/iTunes/.ntnny.txt" -alias rs_removedeadtracks="rm /Users/alex/Library/iTunes/.superremoveapp.plist" +alias rs_notinplaylist="rm $HOME/Library/iTunes/.ntnny.txt" +alias rs_removedeadtracks="rm $HOME/Library/iTunes/.superremoveapp.plist" # }}} # One-liners {{{ diff --git a/vim/pluginconf.vimrc b/vim/pluginconf.vimrc @@ -8,7 +8,7 @@ let g:tagbar_type_vimwiki = { \ , 'sro':'&&&' \ , 'kind2scope':{'h':'header'} \ , 'sort':0 - \ , 'ctagsbin':'$CONF_DIR/bin/vwtags.py' + \ , 'ctagsbin':'$CONF_DIR/scripts/vwtags.py' \ , 'ctagsargs': 'default' \ }