commit dd6822300855bcdde3cd9b2980ab5d79ae496879
parent 3df3a8e0ffc9f0eebdf375513bf8bed2bb3da41c
Author: Alex Balgavy <a.balgavy@gmail.com>
Date: Mon, 22 Oct 2018 13:57:28 +0200
Moved variables to env, reorganised profile
Diffstat:
2 files changed, 149 insertions(+), 118 deletions(-)
diff --git a/bin/play b/bin/play
@@ -1,5 +1,6 @@
#!/bin/bash
+rootdir="$MUSIC_ROOT"
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"
@@ -53,7 +54,6 @@ init_check() {
init_check
cd /Users/alex/Music/iTunes/iTunes\ Media/Music
-rootdir=/Users/alex/Music/iTunes/iTunes\ Media/Music
trap clean_up INT
clear
echo "Music Player v1"
diff --git a/shell/commonprofile b/shell/commonprofile
@@ -1,7 +1,88 @@
#!/bin/bash
+# vim:foldmethod=marker:foldlevel=0
+
+# Env variables {{{
+
+# Original path:
+# PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
+
+# Add API keys and stuff
source ~/.secret_env_variables
-### SIMPLE COMMANDS ###
+# Include my scripts in PATH (conditionally)
+if [[ $PATH != *"/Users/alex/.bin"* ]]; then
+ export PATH=/Users/alex/.bin:$PATH
+fi
+
+# Set a variable for my confidr
+export CONF_DIR="$HOME/.dotfiles"
+
+# Where my music is located
+export MUSIC_DIR="$HOME/iTunes/iTunes Media/Music"
+
+export EDITOR="vim"
+export HOMEBREW_EDITOR="vim"
+export CASK_REPO=$(brew --repository)/Library/Taps/homebrew/homebrew-cask
+
+# Set python 3 location
+export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
+
+# pip should only run if there is a virtualenv currently activated
+export PIP_REQUIRE_VIRTUALENV=true
+
+# }}}
+
+# Activate programs that need profile entries {{{
+# activate virtualenvwrapper
+source /usr/local/bin/virtualenvwrapper.sh
+
+# activate thefuck
+eval "$(thefuck --alias)"
+
+# }}}
+
+# Set up conf command {{{
+conf() {
+ if [ $# -gt 0 ]; then
+ if [ "$1" = 'cd' ]; then
+ cd ~/.dotfiles || return;
+ elif [ "$1" = 'rc' ]; then
+ if [[ $SHELL = *"zsh"* ]]; then
+ vim ~/.zshrc
+ elif [[ $SHELL = *"bash"* ]]; then
+ vim ~/.bashrc
+ fi
+ elif [ "$1" = 'common' ]; then
+ vim ~/.commonprofile
+ elif [ "$1" = 'reload' ]; then
+ source ~/.commonprofile
+ if [[ $SHELL = *"zsh"* ]]; then
+ START_TIME=$SECONDS
+ source ~/.zshrc
+ echo "Reloaded zsh config ($(( $SECONDS-$START_TIME )) sec)."
+ elif [[ $SHELL = *"bash"* ]]; then
+ START_TIME=$SECONDS
+ source ~/.bashrc
+ echo "Reloaded bash config ($(( $SECONDS-$START_TIME )) sec)."
+ fi
+ elif [ "$1" = 'get' ]; then
+ echo "$CONF_DIR"
+ else
+ $(command -v git) --git-dir="$HOME"/.dotfiles/.git --work-tree "$HOME"/.dotfiles/ "$@"
+ fi
+ else
+ echo "Usage:"
+ echo "conf cd Go to conf directory"
+ echo "conf rc Edit shell-specific profile (zshrc, bashrc, etc.)"
+ echo "conf common Edit common profile"
+ echo "conf reload Reload configuration files"
+ echo "conf get Print path to configuration directory"
+ echo "conf [git command] Run git command in conf directory"
+ fi
+}
+# }}}
+
+# Aliases (simple) {{{
alias c="clear"
alias fucking="sudo"
alias wtf="tldr"
@@ -19,29 +100,17 @@ alias top='sudo htop' # Top should lau
alias g='git' # Make git easier to type
alias r='ranger' # Make Ranger easier to type
alias wheredef='type -a'
+# }}}
-### SIMPLE FUNCTIONS ###
-mark() { mdvl "$1" | less; }
-cd() { builtin cd -P "$@" || return; ls; } # List contents after cding
-mkcd() { mkdir -p -- "$1" && cd -P -- "$1" || return; } # Make dir and cd at the same time
-procinfo() { ps aux | grep "$1"; } # Get info about a process (by name)
-rmempty() { find "${1-.}" -type d -empty -depth -delete; } # Remove empty directories
-todos() { if [ -z "$1" ]; then 1="."; fi; grep -rnw "$1" -e "TODO"; }
-find_in_files() { grep -rnw "$1" -e "$2"; }
-batterypct() { ioreg -l | awk '$3~/Capacity/{c[$3]=$5}END{OFMT="%.2f%%";max=c["\"MaxCapacity\""];print(max>0?100*c["\"CurrentCapacity\""]/max:"?")}' | sed 's/\..*//'; }
-
-### DOUG SCRIPTS TRIAL RESET ###
-alias rs_notinplaylist="rm /Users/alex/Library/iTunes/.ntnny.txt"
-alias rs_removedeadtracks="rm /Users/alex/Library/iTunes/.superremoveapp.plist"
-
-### MAC UI CUSTOMISATIONS ###
+# Aliases (Mac UI) {{{
alias changedock="defaults write com.apple.dock contents-immutable -bool false;killall Dock"
alias nochangedock="defaults write com.apple.dock contents-immutable -bool true;killall Dock"
alias dockspacer="defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type='spacer-tile';}'; killall Dock"
alias spotlighton="sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist"
alias spotlightoff="sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist"
+# }}}
-### SERVICES ###
+# Aliases (services) {{{
alias loadftp="sudo launchctl load /System/Library/LaunchDaemons/ftp.plist"
alias unloadftp="sudo launchctl unload /System/Library/LaunchDaemons/ftp.plist"
alias startftp="sudo launchctl start com.apple.ftpd"
@@ -49,12 +118,38 @@ alias stopftp="sudo launchctl stop com.apple.ftpd"
alias startapache="sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist"
alias stopapache="sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist"
alias startpg='pg_ctl -D $(brew --prefix)/var/postgres start'
+# }}}
-### MORE COMPLEX FUNCTIONS ###
-pip3-upgrade() {
- pip3 list --outdated | cut -d ' ' -f1 | xargs -n1 pip3 install -U
-}
+# Aliases (Dougscripts trial resets) {{{
+alias rs_notinplaylist="rm /Users/alex/Library/iTunes/.ntnny.txt"
+alias rs_removedeadtracks="rm /Users/alex/Library/iTunes/.superremoveapp.plist"
+# }}}
+
+# One-liners {{{
+mark() { mdvl "$1" | less; }
+cd() { builtin cd -P "$@" || return; ls; } # List contents after cding
+mkcd() { mkdir -p -- "$1" && cd -P -- "$1" || return; } # Make dir and cd at the same time
+procinfo() { ps aux | grep "$1"; } # Get info about a process (by name)
+rmempty() { find "${1-.}" -type d -empty -depth -delete; } # Remove empty directories
+todos() { if [ -z "$1" ]; then 1="."; fi; grep -rnw "$1" -e "TODO"; } # Find TODO comments
+find_in_files() { grep -rnw "$1" -e "$2"; } # Search for text in files
+
+# Pip3 upgrade packages
+pip3-upgrade() { pip3 list --outdated | cut -d ' ' -f1 | xargs -n1 pip3 install -U }
+# Get current battery percentage
+batterypct() { ioreg -l | awk '$3~/Capacity/{c[$3]=$5}END{OFMT="%.2f%%";max=c["\"MaxCapacity\""];print(max>0?100*c["\"CurrentCapacity\""]/max:"?")}' | sed 's/\..*//'; }
+
+# create commands to override pip restriction.
+# use `gpip` or `gpip3` to force installation of
+# a package in the global python environment
+gpip(){ PIP_REQUIRE_VIRTUALENV="" pip "$@" }
+gpip3(){ PIP_REQUIRE_VIRTUALENV="" pip3 "$@" }
+
+# }}}
+
+# General functions {{{
+# Define a notification fuction -- notify $title $message
notify() {
if type terminal-notifier &> /dev/null; then
terminal-notifier -title "$1" -message "$2" -activate com.googlecode.iterm2
@@ -63,62 +158,36 @@ notify() {
fi
}
+# Gem update script
gemmaster() {
gem update;
gem update rails;
gem cleanup;
}
-conf() {
- if [ $# -gt 0 ]; then
- if [ "$1" = 'cd' ]; then
- cd ~/.dotfiles || return;
- elif [ "$1" = 'rc' ]; then
- if [[ $SHELL = *"zsh"* ]]; then
- vim ~/.zshrc
- elif [[ $SHELL = *"bash"* ]]; then
- vim ~/.bashrc
- fi
- elif [ "$1" = 'common' ]; then
- vim ~/.commonprofile
- elif [ "$1" = 'reload' ]; then
- source ~/.commonprofile
- if [[ $SHELL = *"zsh"* ]]; then
- START_TIME=$SECONDS
- source ~/.zshrc
- echo "Reloaded zsh config ($(( $SECONDS-$START_TIME )) sec)."
- elif [[ $SHELL = *"bash"* ]]; then
- START_TIME=$SECONDS
- source ~/.bashrc
- echo "Reloaded bash config ($(( $SECONDS-$START_TIME )) sec)."
- fi
- elif [ "$1" = 'get' ]; then
- echo "$CONFDIR"
- else
- $(command -v git) --git-dir="$HOME"/.dotfiles/.git --work-tree "$HOME"/.dotfiles/ "$@"
- fi
- else
- echo "At least one argument needed."
- fi
-}
-### FFMPEG CONVERSIONS ###
+# Webm to mp4 video
webm-mp4() {
ffmpeg -i "$1" -qscale 0 "$1".mp4
}
+# Extract audio from mp4
mp4-mp3() {
ffmpeg -i "$1" "$1".mp3
}
+# Anything to a gif
gifify() {
ffmpeg -i "$1" -r 25 -f image2pipe -vcodec ppm - | \
convert -delay 4 -loop 0 - output.gif
}
+
+# Gif to mp4
gif-mp4() {
ffmpeg -i "$1" -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" "$(echo "$1"|cut -d. -f1).mp4"
}
+# Extract any archive
extract () {
if [ -f "$1" ] ; then
case $1 in
@@ -140,28 +209,12 @@ extract () {
fi
}
+# Echo the current wifi password
current_wifi_password() {
security find-generic-password -ga "$1" | grep password
}
-### MAC FINDER-SPECIFIC ###
-if command -v osascript &> /dev/null; then
- cdf() {
- target=$(osascript -e 'tell application "Finder" to if (count of Finder windows) > 0 then get POSIX path of (target of front Finder window as text)')
- if [ "$target" != "" ]; then
- cd "$target" || return; pwd
- else
- echo 'No Finder window found' >&2
- fi
- }
- gdf() {
- osascript -e 'tell application "Finder" to if (count of Finder windows) > 0 then get POSIX path of (target of front Finder window as text)'
- }
- fsel() {
- osascript -e 'tell application "Finder" to return POSIX path of (first item of (get selection as alias list) as alias)' | rev | sed 's/^\///' | rev;
- };
-fi
-
+# Print real path to a folder (following links)
# This is still a bit buggy
realpath() {
if [ $# -eq 1 ]; then
@@ -188,6 +241,8 @@ realpath() {
echo 'idk what you want dude'
fi
}
+
+# Remove aliases & replace with original files
unlink() {
for i in "$@"; do
p=$(realpath -w "$i")
@@ -196,52 +251,28 @@ unlink() {
unset p
done
}
+# }}}
-######################
-
-### PATH CHANGES ###
-
-# Original path:
-# PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
+# Applescript functions {{{
+if command -v osascript &> /dev/null; then
-# Include my scripts in PATH (conditionally) #
-if [[ $PATH != *"/Users/alex/.bin"* ]]; then
- export PATH=/Users/alex/.bin:$PATH
+ # cd to current Finder directory
+ cdf() {
+ target=$(osascript -e 'tell application "Finder" to if (count of Finder windows) > 0 then get POSIX path of (target of front Finder window as text)')
+ if [ "$target" != "" ]; then
+ cd "$target" || return; pwd
+ else
+ echo 'No Finder window found' >&2
+ fi
+ }
+ # echo current Finder directory
+ gdf() {
+ osascript -e 'tell application "Finder" to if (count of Finder windows) > 0 then get POSIX path of (target of front Finder window as text)'
+ }
+ # echo selected Finder file
+ fsel() {
+ osascript -e 'tell application "Finder" to return POSIX path of (first item of (get selection as alias list) as alias)' | rev | sed 's/^\///' | rev;
+ };
fi
+# }}}
-# Set a variable for my confidr
-export CONFDIR="$HOME/.dotfiles"
-
-#####################
-
-### HOMEBREW VARIABLE CHANGES ###
-export EDITOR="vim"
-export HOMEBREW_EDITOR="vim"
-
-export CASK_REPO=$(brew --repository)/Library/Taps/homebrew/homebrew-cask
-######################
-
-### THEFUCK ###
-eval "$(thefuck --alias)"
-##############
-
-### VIRTUALENV ###
-
-# Set python 3 location
-export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
-
-# activate virtualenvwrapper
-source /usr/local/bin/virtualenvwrapper.sh
-
-# pip should only run if there is a virtualenv currently activated
-export PIP_REQUIRE_VIRTUALENV=true
-
-# create commands to override pip restriction.
-# use `gpip` or `gpip3` to force installation of
-# a package in the global python environment
-gpip(){
- PIP_REQUIRE_VIRTUALENV="" pip "$@"
-}
-gpip3(){
- PIP_REQUIRE_VIRTUALENV="" pip3 "$@"
-}