commit c501efed55ceb52b1e251c88053325f30f9d8960
parent d0dbb83385a50dfdbb5e1715185599974a2200c8
Author: Alex Balgavy <a.balgavy@gmail.com>
Date: Tue, 8 Jan 2019 20:22:17 +0100
Miscellaneous improvements
Former-commit-id: d5228ed05db75b38e2fce7939a35d7b661665ac6
Diffstat:
3 files changed, 77 insertions(+), 48 deletions(-)
diff --git a/bin/conf b/bin/conf
@@ -1,16 +1,19 @@
#!/usr/bin/env bash
# vim: foldmethod=marker:foldlevel=0
-# Functions {{{
+# 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 $(pwd)/"$1" "$2";
+ ln -snfv "$(pwd)/$1" "$2";
fi
}
+#}}}
+
+# Stow command {{{
stow_files() {
if [ $# -gt 0 ]; then
for f in "$@"; do
@@ -18,7 +21,7 @@ stow_files() {
"bin")
lncommand "bin" "$HOME/.bin"
if command -v mpv &> /dev/null; then
- mkdir -p $HOME/.config/mpv
+ mkdir -p "$HOME/.config/mpv"
lncommand ".bin/visualizer.lua" "$HOME/.config/mpv/visualizer.lua"
fi
;;
@@ -46,13 +49,13 @@ stow_files() {
;;
"shell")
- for i in $(ls shell); do
- lncommand shell/"$i" $HOME/."$i"
+ for i in shell/*; do
+ lncommand shell/"$i" "$HOME/.$i"
done
;;
"vim")
- lncommand vim/init.vimrc $HOME/.vimrc # vimrc points directly to other vim configs
- lncommand vim/idea.vimrc $HOME/.ideavimrc # ideavimrc has to be separate
+ lncommand vim/init.vimrc "$HOME/.vimrc" # vimrc points directly to other vim configs
+ lncommand vim/idea.vimrc "$HOME/.ideavimrc" # ideavimrc has to be separate
;;
esac
@@ -69,18 +72,23 @@ stow_files() {
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 "\$CONF_DIR not set."
else
"$@"
fi
}
#}}}
+# Run with arguments {{{
if [ $# -gt 0 ]; then
if [ "$1" = 'cd' ]; then
conf_check cd "$CONF_DIR"
+
elif [ "$1" = 'rc' ]; then
if [[ $SHELL = *"zsh"* ]]; then
vim "$HOME"/.zshrc
@@ -90,31 +98,27 @@ if [ $# -gt 0 ]; then
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
vim "$HOME"/.commonprofile
- elif [ "$1" = 'reload' ]; then
- if [[ $SHELL = *"zsh"* ]]; then
- START_TIME=$SECONDS
- source "$HOME"/.zshrc
- echo "Reloaded zsh config ($(( SECONDS-START_TIME )) sec)."
- elif [[ $SHELL = *"bash"* ]]; then
- START_TIME=$SECONDS
- source "$HOME"/.bashrc
- echo "Reloaded bash config ($(( SECONDS-START_TIME )) sec)."
- fi
+
elif [ "$1" = 'get' ]; then
conf_check echo "$CONF_DIR"
+
elif [ "$1" = 'stow' ]; then
stow_files "${@:2}"
+
else
- conf_check $(command -v git) --git-dir="$CONF_DIR"/.git --work-tree "$CONF_DIR" "$@"
+ conf_check "$(command -v git)" --git-dir="$CONF_DIR"/.git --work-tree "$CONF_DIR" "$@"
fi
+ #}}}
+ # ...or print help text {{{
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
+#}}}
diff --git a/shell/commonprofile b/shell/commonprofile
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
# vim:foldmethod=marker:foldlevel=0
# Env variables {{{
@@ -6,41 +6,52 @@
# Original path:
# PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
+export \
+ PATH GOPATH \
+ CONF_DIR MUSIC_DIR \
+ EDITOR HOMEBREW_EDITOR \
+ VIRTUALENVWRAPPER_PYTHON PIP_REQUIRE_VIRTUALENV \
+ CASK_REPO \
+ SHELLCHECK_OPTS
+
# Add API keys and stuff
-if [ -f $HOME/.secret_env_variables ]; then
- source ~/.secret_env_variables
+if [ -f "$HOME/.secret_env_variables" ]; then
+ source "$HOME/.secret_env_variables"
fi
# Include my scripts in PATH (conditionally)
if [[ $PATH != *"/Users/alex/.bin"* ]]; then
- export PATH=$HOME/.bin:$PATH
+ PATH=$HOME/.bin:$PATH
fi
# Golang
if command -v go &> /dev/null; then
if [[ $PATH != *"$(go env GOPATH)"* ]]; then
- export PATH=$PATH:$(go env GOPATH)/bin
+ PATH=$PATH:$(go env GOPATH)/bin
fi
- export GOPATH=$(go env GOPATH)
+ GOPATH=$(go env GOPATH)
fi
# Set a variable for my confidr
-export CONF_DIR="$HOME/.dotfiles"
+CONF_DIR="$HOME/.dotfiles"
# Where my music is located
-export MUSIC_DIR="$HOME/Music/iTunes/iTunes Media/Music"
+MUSIC_DIR="$HOME/Music/iTunes/iTunes Media/Music"
-export EDITOR="vim"
+EDITOR="vim"
if command -v brew &> /dev/null; then
- export HOMEBREW_EDITOR="vim"
- export CASK_REPO=$(brew --repository)/Library/Taps/homebrew/homebrew-cask
+ HOMEBREW_EDITOR="vim"
+ CASK_REPO=$(brew --repository)/Library/Taps/homebrew/homebrew-cask
fi
# Set python 3 location
-export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
+VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
# pip should only run if there is a virtualenv currently activated
-export PIP_REQUIRE_VIRTUALENV=true
+PIP_REQUIRE_VIRTUALENV=true
+
+# what to exclude for shellcheck
+SHELLCHECK_OPTS='--exclude=SC1090,SC1091,SC2009'
# }}}
@@ -57,7 +68,6 @@ fi
# }}}
-
# Aliases (simple) {{{
alias c="clear"
alias fucking="sudo"
@@ -107,10 +117,11 @@ 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)
+procinfo2() { pgrep -f "$1"; }
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
-hr() { for i in {1..$COLUMNS}; do echo -n "#"; done; echo; }
+hr() { for ((i=0; i<COLUMNS; i++)); do echo -n "#"; done; echo; }
# Pip3 upgrade packages
pip3-upgrade() { pip3 list --outdated | cut -d ' ' -f1 | xargs -n1 pip3 install -U; }
@@ -136,6 +147,19 @@ notify() {
fi
}
+# Reload configs
+reload() {
+ START_TIME=$SECONDS
+ source "$HOME"/.commonprofile
+
+ if [[ $SHELL = *"zsh"* ]]; then
+ source "$HOME"/.zshrc
+ elif [[ $SHELL = *"bash"* ]]; then
+ source "$HOME"/.bash_profile
+ fi
+ echo "Reloaded config ($(( SECONDS-START_TIME )) sec)."
+}
+
# Gem update script
gemmaster() {
gem update;
@@ -146,23 +170,23 @@ gemmaster() {
# Webm to mp4 video
webm-mp4() {
- ffmpeg -i "$1" -qscale 0 "$1".mp4
+ffmpeg -i "$1" -qscale 0 "$1".mp4
}
# Extract audio from mp4
mp4-mp3() {
- ffmpeg -i "$1" "$1".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"
+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
@@ -243,14 +267,14 @@ if command -v osascript &> /dev/null; then
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;
- };
+# 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
# }}}
diff --git a/shell/zshrc b/shell/zshrc
@@ -1,8 +1,9 @@
+#!/usr/bin/env zsh
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
-export ZSH=/Users/alex/.oh-my-zsh
+export ZSH="$HOME"/.oh-my-zsh
# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.