Compare commits

...

53 Commits

Author SHA1 Message Date
Jacob Kiers 07f3d361d1 Fix get command to follow redirects
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2022-01-06 19:29:04 +01:00
Jacob Kiers 0be93c3520 Ignore symlink to git hooks
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2022-01-06 19:22:05 +01:00
Jacob Kiers 9718fb26ba Do not install php tools on composer update
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2022-01-06 19:21:05 +01:00
Jacob Kiers 72c0f1b3c8 More updates
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2022-01-06 19:17:46 +01:00
Jacob Kiers 99533ff670 Update
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2022-01-06 18:42:28 +01:00
Jacob Kiers 4ddeb426d2 Make xdebug version-aware
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2022-01-06 18:36:49 +01:00
Jacob Kiers a6973ace15 Update for Python 3
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2022-01-06 18:28:35 +01:00
Jacob Kiers 2755650734 More tools and improvements
Signed-off-by: Jacob Kiers <kiers@comandi.nl>
2017-12-08 18:36:39 +01:00
Jacob Kiers 4b36c35285 Add better bash completion support
Now it is easy to add new completion scripts: just drop them in the
bash_completion.d directory.

Signed-off-by: Jacob Kiers <kiers@comandi.nl>
2017-12-08 18:33:28 +01:00
Jacob Kiers 12ba7965a4 Add a better XDebug command
Signed-off-by: Jacob Kiers <kiers@comandi.nl>
2017-12-08 18:30:50 +01:00
Jacob Kiers a67b2ace9e Add more tools to auto-install
Signed-off-by: Jacob Kiers <kiers@comandi.nl>
2017-12-08 18:30:32 +01:00
Jacob Kiers 2559f7b69e Add command to gist something
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2015-06-08 16:08:54 +02:00
Jacob Kiers 1ef3690fbc Install apps when reinstalling OS.
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2015-06-08 16:07:57 +02:00
Jacob Kiers 2cdb12a071 Remove includes/bash_ssh.bash
The automatic SSH agent functionality did not work correctly. Therefore,
it is removed.

Signed-off-by: Jacob Kiers <jacob@alphacomm.nl>
2015-05-12 12:09:35 +02:00
Jacob Kiers 116fcc44c4 Use new update script for dotfiles
This script will also install composer, set up the git hooks and install
some global dependencies.

Signed-off-by: Jacob Kiers <jacob@alphacomm.nl>
2015-05-12 12:08:20 +02:00
Jacob Kiers ebddd9bb7f Add git pre-commit hook
The pre-commit hook will lint-check the added PHP files and also check
their CS.

Signed-off-by: Jacob Kiers <jacob@alphacomm.nl>
2015-05-12 12:07:08 +02:00
Jacob Kiers 38a0a2fa3d Update jq
Signed-off-by: Jacob Kiers <jacob@alphacomm.nl>
2015-05-12 11:59:36 +02:00
Jacob Kiers b21c4e4d12 Add some more gitconfig shortcuts
These just make some things a little easier when a repository is
directly cloned.

Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2015-04-10 13:53:10 +00:00
Jacob Kiers 3cbff4da78 Improve setup-server
The order of parameters is now changed to make it easier when deploying
to a lot of servers.

Also, it introduces the concept of a friendly name, which is useful when
DNS is not available for a specific host. Instead of being forced to
have the alias be the same as the IP address, it can now be named.

Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2015-04-10 13:51:06 +00:00
Jacob Kiers 1415dec58b Add SSH Agent startup.
Signed-off-by: Jacob Kiers <jacob@alphacomm.nl>
2015-04-07 11:38:01 +02:00
Jacob Kiers 9a9d1beb88 Make sure server exists in ~/.ssh/config
Signed-off-by: Jacob Kiers <jacob@alphacomm.nl>
2015-02-02 15:44:56 +01:00
Jacob Kiers b3e4231ae0 Change order of $PATH
First use ./vendor/bin, then $COMPOSER_HOME/vendor/bin and only then
$HOME/dotfiles/bin, so that local commands are executed first.

Signed-off-by: Jacob Kiers <jacob@alphacomm.nl>
2015-01-27 12:27:49 +01:00
Jacob Kiers 79074be926 Improve bin/xdebug to use command from path.
It uses the `which` command to find the command that you actually want
to run, and runs that.

This makes it possible to run any php binary (like phpunit or phing)
with xdebug.

Signed-off-by: Jacob Kiers <jacob@alphacomm.nl>
2015-01-27 12:25:03 +01:00
Jacob Kiers ba33a48144 Update composer to the latest version.
Signed-off-by: Jacob Kiers <jacob@alphacomm.nl>
2015-01-27 12:24:34 +01:00
Jacob Kiers 882d2087cc Add alias 'gitclean'
It removes all branches that are already merged into the master branch.

Signed-off-by: Jacob Kiers <jacob@alphacomm.nl>
2015-01-27 12:23:55 +01:00
Jacob Kiers 5c5efbe77d Added script to setup environment on a new server.
Signed-off-by: Jacob Kiers <jacob@alphacomm.nl>
2015-01-14 18:21:04 +01:00
Jacob Kiers 9eaea22b9f Add <pwd>/vendor/bin to $PATH.
Signed-off-by: Jacob Kiers <jacob@alphacomm.nl>
2015-01-14 15:47:39 +01:00
Jacob Kiers f3c4c0275a Add XDebug launcher.
Signed-off-by: Jacob Kiers <jacob@alphacomm.nl>
2015-01-14 15:42:43 +01:00
Jacob Kiers bb4576886d Update composer to latest version.
Signed-off-by: Jacob Kiers <jacob@alphacomm.nl>
2015-01-14 15:42:22 +01:00
Jacob Kiers 0e4fd52450 Fix the clone URL for installation.
Signed-off-by: Jacob Kiers <jacob@alphacomm.nl>
2014-12-23 11:24:55 +01:00
Jacob Kiers eb61134f29 First make sure that a battery is present.
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2014-09-25 10:07:51 +02:00
Jacob Kiers e194d43baa Update composer to the latest version.
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2014-09-25 09:59:37 +02:00
Jacob Kiers 1aa504dda8 Add script to test a git sequence of commits.
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2014-09-25 09:59:19 +02:00
Jacob Kiers 43585e1519 Add script to show battery status.
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2014-09-25 09:58:48 +02:00
Jacob Kiers 5da5ecef49 Ignore the Atlassian configs by default.
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2014-09-25 09:57:54 +02:00
Jacob Kiers 2c4229696e Add the Go language on OS X.
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2014-09-25 09:57:20 +02:00
Jacob Kiers bdc6a5856b Add global composer vendors to bin path.
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2014-09-25 09:56:55 +02:00
Jacob Kiers 56a65c36c5 Improve aliases and autocompletion.
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2014-09-25 09:55:13 +02:00
Jacob Kiers 5e9e061e4f Make sure the repo is clean before releasing.
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2014-09-25 09:47:21 +02:00
Jacob Kiers 8e3b0a28e9 Update composer.
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2014-06-25 18:11:25 +02:00
Jacob Kiers fd237f2e62 Fix terminal title for paths with spaces.
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2014-06-25 18:10:54 +02:00
Jacob Kiers fb10240506 Split off bash completion.
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2014-06-25 18:10:23 +02:00
Jacob Kiers 646138bb6b Use local jq if available on Mac.
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2014-06-25 18:09:27 +02:00
Jacob Kiers f91e0e90ab Changed git shortcuts.
Signed-off-by: Jacob Kiers <jacob@alphacomm.nl>
2014-05-13 13:41:37 +02:00
Jacob Kiers e534a8de0e Automatically autocorrect misspelled git commands. 2014-05-08 11:52:48 +02:00
Jacob Kiers b36abc6f30 Add jq for linux.
jq is a JSON parser. It is used by the release script.

Signed-off-by: Jacob Kiers <jacob@alphacomm.nl>
2014-05-08 08:36:08 +02:00
Jacob Kiers 8358cb6759 git: Change push.default to upstream.
Signed-off-by: Jacob Kiers <jacob@alphacomm.nl>
2014-05-08 08:35:56 +02:00
Jacob Kiers bfa37857c6 Added bin/wav2alaw
Signed-off-by: Jacob Kiers <jacob@alphacomm.nl>
2014-05-07 07:53:02 +02:00
Jacob Kiers 3d9e4513a3 Force vim in foreground mode when using git.
Signed-off-by: Jacob Kiers <jacob@alphacomm.nl>
2014-05-06 21:35:45 +02:00
Jacob Kiers 7d4c9b54e7 bin/release: also check git tags for current version.
Signed-off-by: Jacob Kiers <jacob@alphacomm.nl>
2014-05-05 16:16:51 +02:00
Jacob Kiers cfd3316811 Automatically prune when fetching.
Signed-off-by: Jacob Kiers <jacob@alphacomm.nl>
2014-05-05 16:15:49 +02:00
Jacob Kiers 604b094cea Force a default path, and prepend the rest.
Signed-off-by: Jacob Kiers <jacob@alphacomm.nl>
2014-05-03 00:45:04 +02:00
Jacob Kiers ae3b45b0ab Update paths.
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
2014-04-30 14:19:29 +02:00
30 changed files with 901 additions and 79 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
*.cache
sublime/User/Package Control.last-run
sublime/User/Package Control.system-ca-bundle
bash_completion.d
resources/git-template/hooks

View File

View File

@ -0,0 +1,5 @@
# Adding new completions
Add a file ending with the `.sh` extension, which contains the completion
configuration. This will then automatically be picked up.

126
bin/battery Executable file
View File

@ -0,0 +1,126 @@
#!/bin/sh
HEART_FULL=♥
HEART_EMPTY=♡
[ -z "$NUM_HEARTS" ] &&
NUM_HEARTS=5
cutinate()
{
perc=$1
inc=$(( 100 / $NUM_HEARTS))
for i in `seq $NUM_HEARTS`; do
if [ $perc -lt 100 ]; then
echo $HEART_EMPTY
else
echo $HEART_FULL
fi
perc=$(( $perc + $inc ))
done
}
linux_get_bat ()
{
bf=$(cat $BAT_FULL)
bn=$(cat $BAT_NOW)
echo $(( 100 * $bn / $bf ))
}
freebsd_get_bat ()
{
sysctl -n hw.acpi.battery.life
}
# Do with grep and awk unless too hard
# TODO Identify which machine we're on from teh script.
battery_status()
{
case $(uname -s) in
"Linux")
BATPATH=${BATPATH:-/sys/class/power_supply/BAT0}
if [ ! -d $BATPATH ]; then
exit 0
fi
STATUS=$BATPATH/status
[ "$1" = `cat $STATUS` ] || [ "$1" = "" ] || return 0
if [ -f "$BATPATH/energy_full" ]; then
naming="energy"
elif [ -f "$BATPATH/charge_full" ]; then
naming="charge"
elif [ -f "$BATPATH/capacity" ]; then
cat "$BATPATH/capacity"
return 0
fi
BAT_FULL=$BATPATH/${naming}_full
BAT_NOW=$BATPATH/${naming}_now
linux_get_bat
;;
"FreeBSD")
STATUS=`sysctl -n hw.acpi.battery.state`
case $1 in
"Discharging")
if [ $STATUS -eq 1 ]; then
freebsd_get_bat
fi
;;
"Charging")
if [ $STATUS -eq 2 ]; then
freebsd_get_bat
fi
;;
"")
freebsd_get_bat
;;
esac
;;
"Darwin")
case $1 in
"Discharging")
ext="No";;
"Charging")
ext="Yes";;
esac
ioreg -c AppleSmartBattery -w0 | \
grep -o '"[^"]*" = [^ ]*' | \
sed -e 's/= //g' -e 's/"//g' | \
sort | \
while read key value; do
case $key in
"MaxCapacity")
export maxcap=$value;;
"CurrentCapacity")
export curcap=$value;;
"ExternalConnected")
if [ -n "$ext" ] && [ "$ext" != "$value" ]; then
exit
fi
;;
"FullyCharged")
if [ "$value" = "Yes" ]; then
exit
fi
;;
esac
if [[ -n "$maxcap" && -n $curcap ]]; then
echo $(( 100 * $curcap / $maxcap ))
break
fi
done
esac
}
BATTERY_STATUS=`battery_status $1`
[ -z "$BATTERY_STATUS" ] && exit
if [ -n "$CUTE_BATTERY_INDICATOR" ]; then
cutinate $BATTERY_STATUS
else
echo ${BATTERY_STATUS}%
fi

Binary file not shown.

15
bin/dcdebug Executable file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env bash
COMMAND=$1;
shift 1
if [ ! -f $COMMAND ]; then
COMMAND=`which ${COMMAND}`
fi
if [ ! -f "${COMMAND}" ]; then
echo "Usage: ${0} <command>"
exit 1;
fi
PHP_IDE_CONFIG="serverName=local" XDEBUG_CONFIG="remote_enable=1 remote_mode=req remote_port=9000 remote_host=127.0.0.1 remote_connect_back=0" php -d zend_extension=xdebug.so $COMMAND "$@"

2
bin/docker-php Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
docker run --rm -it --entrypoint /usr/bin/php --user $(id -u):$(id -g) -e HOME="${HOME}" -v ${HOME}:${HOME} --workdir $(pwd) php:70 $@

5
bin/git-fixup Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
set -e
TARGET=$(git rev-parse ${1})
git commit --fixup=${TARGET} ${@:2}
EDITOR=true git rebase -i --autostash --autosquash ${TARGET}^;

99
bin/git-test-sequence Executable file
View File

@ -0,0 +1,99 @@
#!/bin/sh
# Run a command over a sequence of commits.
# Example:
# git test-sequence origin/master.. 'make clean && make test'
. "$(git --exec-path)/git-sh-setup"
require_work_tree
t=
force=
run_once=
ref_name=pass
# The tree must be really really clean.
if ! git update-index --ignore-submodules --refresh > /dev/null; then
echo >&2 "cannot rebase: you have unstaged changes"
git diff-files --name-status -r --ignore-submodules -- >&2
exit 1
fi
diff=$(git diff-index --cached --name-status -r --ignore-submodules HEAD --)
case "$diff" in
?*) echo >&2 "cannot rebase: your index contains uncommitted changes"
echo >&2 "$diff"
exit 1
;;
esac
start_branch=`git rev-parse --symbolic-full-name HEAD | sed s,refs/heads/,,`
git checkout `git rev-parse HEAD` > /dev/null 2>/dev/null
cleanup() {
git checkout $start_branch > /dev/null 2>/dev/null
}
already_passed() {
obdata=${ref_name}-$t-$1
obhash=`echo $obdata | git hash-object --stdin`
git cat-file blob $obhash > /dev/null 2>/dev/null \
&& echo "Already ${ref_name} $1"
}
passed_on() {
obdata=${ref_name}-$t-$1
echo $obdata | git hash-object -w --stdin > /dev/null
echo "Passed: $1."
}
broke_on() {
git log --pretty="format:Broke on %H (%s)%n" -n 1 $1
cleanup
exit 1
}
new_test() {
echo "Testing $2"
git reset --hard $v && eval "$2" && passed_on $1 || broke_on $v
status=$?
if test -n "$run_once"; then
cleanup
exit $status
fi
}
while test $# != 0
do
case "$1" in
--force)
force=yes
;;
--once)
run_once=yes
;;
--ref-name)
ref_name=$2
shift
;;
*)
break;
;;
esac
shift
done
t=`echo "$2" | git hash-object --stdin`
for v in `git rev-list --reverse $1`
do
tree_ver=`git rev-parse "$v^{tree}"`
test -z "$force" && already_passed $tree_ver || new_test $tree_ver "$2"
done
cleanup
if test -n "$run_once"; then
echo "All commits already passed for --once argument. Quiting."
exit 127
fi
echo "All's well."

View File

@ -32,6 +32,17 @@ if [ "$1" == "" ]; then
exit 1
fi
git pull
# Make sure all changes are merged.
if [ $? -ne 0 ]; then
error "Branch did not contain the latest changes and could not be merged automatically."
echo "Please merge by hand before continue."
echo
git status
exit 1
fi
# Dirty repo?
if [ "$(git status --porcelain 2>/dev/null)" ]; then
error "Repo is dirty."
@ -45,6 +56,7 @@ fi
jq_ver=$(find . -maxdepth 1 -name "*.jquery.json" | xargs cat | jq -r ".version")
cmpnt_ver=$(find . -maxdepth 1 -name "bower.json" | xargs cat | jq -r ".version")
pkg_ver=$(find . -maxdepth 1 -name "package.json" | xargs cat | jq -r ".version")
git_ver=$(git tag | sort -rV | head -n1)
# Non npm package
[ "$pkg_ver" == "0.0.0" ] && pkg_ver=
@ -54,6 +66,7 @@ current_ver=
[ -n "$jq_ver" ] && current_ver="$jq_ver"
[ -n "$cmpnt_ver" ] && current_ver="$cmpnt_ver"
[ -n "$pkg_ver" ] && current_ver="$pkg_ver"
[ -n "$git_ver" ] && current_ver="$git_ver"
[ -z "$current_ver" ] && current_ver="0.0.0"
# Validate current versions and determine new version
@ -103,11 +116,11 @@ if [ -f src/Gruntfile.js ]; then
fi
# Commit changed files
git commit -am "v$new_ver"
git commit -am "$new_ver"
git push origin
# Create tag
git tag "v$new_ver"
git tag "$new_ver"
git push origin --tags
# Publish npm package

66
bin/setup-server Executable file
View File

@ -0,0 +1,66 @@
#!/usr/bin/env bash
NORMAL=$(tput sgr0)
GREEN=$(tput setaf 2; tput bold)
YELLOW=$(tput setaf 3)
RED=$(tput setaf 1)
function red() { echo -e "$RED$*$NORMAL"; }
function green() { echo -e "$GREEN$*$NORMAL"; }
function yellow() { echo -e "$YELLOW$*$NORMAL"; }
if [ $# -lt 1 ]; then
echo "Usage: $0 <host|IP> [friendly-name] [user]"
echo "Example: $0 127.0.0.1 server-name $USER"
echo
echo "Afterwards you can login with: ssh server-name"
exit 1;
fi
HOST=$1
NAME=$2
USERNAME=$3
IP=`dig +short $HOST`
if [ -z "$USERNAME" ]; then
USERNAME=$USER
fi
if [ -z "$IP" ]; then
IP=$HOST
fi
if [ -z "$NAME" ]; then
NAME=$HOST
fi
yellow "Setting up server $USERNAME@$HOST with name '$NAME'"
grep "Host $NAME" ~/.ssh/config 2>&1 > /dev/null
if [ 0 -eq $? ]; then
echo $NAME is already in .ssh/config
else
echo Adding server to .ssh/config...
cat >> ~/.ssh/config <<END_OF_HOST
Host $NAME
HostName $IP
User $USERNAME
END_OF_HOST
fi
echo Copying .ssh directory...
scp -qr $HOME/.ssh/ $NAME:
echo Installing dotfiles...
ssh $NAME 'find . -maxdepth 1 -type l -exec unlink {} \;; rm $HOME/.bash*; curl -s https://dot.jacobkiers.net | bash'
echo
green "Done installing server. You can now log in with: ssh $NAME"
green "As a convenience, you will be logged in immediately."
ssh $NAME

26
bin/wav2alaw Executable file
View File

@ -0,0 +1,26 @@
#!/bin/bash
# Converts all wav-files in a directory to alaw.
if [[ -z "$1" ]]; then
DIR='.'
else
if [ ! -d "$1" ]; then
echo "Directory does not exist!"
exit
else
DIR=$1
fi
fi
cd $DIR
for f in `ls -1 *.wav | sed 's/\.[^.]*$//' | sort -n`; do
echo "Converting $f.wav to $f.alaw..."
`sox $f.wav --channels 1 --encoding a-law --rate 8000 --type raw $f.alaw.wav`
if [ $? -eq 0 ]; then
`mv $f.alaw.wav $f.alaw`
`rm $f.wav`
fi
done
echo "Done."

18
bin/xdebug Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env bash
VERSION=$1
shift 1
COMMAND=$1;
shift 1
if [ ! -f $COMMAND ]; then
COMMAND=`which ${COMMAND}`
fi
if [ ! -f "${COMMAND}" ]; then
echo "Usage: ${0} <command>"
exit 1;
fi
PHP_IDE_CONFIG="serverName=local" XDEBUG_CONFIG="remote_enable=1 remote_mode=req remote_port=9000 remote_host=127.0.0.1 remote_connect_back=0" php$VERSION -d zend_extension=xdebug.so $COMMAND "$@"

View File

@ -7,21 +7,21 @@ alias ~="cd ~"
alias -- -="cd -" # The alias is `-`, not `--`
# Shortcuts
alias c="composer"
alias c="php -dmemory_limit=2G $HOME/dotfiles/bin/composer"
alias e=$EDITOR
alias o="open"
alias oo="open ."
alias e=$EDITOR
alias gh="github"
alias +x="chmod +x"
alias t="tmux"
alias x+="chmod +x"
alias +x="chmod +x"
# Git
alias gs="git status"
alias gd="git diff"
alias gds="git diff --staged"
alias gc="git commit -sv"
alias rb="git rebase"
alias rbi="git rebase -i"
if [ `uname` == 'Linux' ]; then
alias open='xdg-open'
fi
# Remove all local branches already merged in master.
alias gitclean='git branch --merged master | grep -v "\smaster$" | grep -v "*" | xargs --no-run-if-empty git branch -d'
alias gist='gist -c'
# Detect which `ls` flavor is in use
if ls --color > /dev/null 2>&1; then # GNU `ls`
@ -46,7 +46,7 @@ alias myip="ifconfig | grep 'inet ' | grep -v 127.0.0.1 | awk '{print \$2}'"
alias update="source "$HOME/dotfiles/setup/update.sh""
# Update dotfiles
alias dotfiles="pushd "$HOME/dotfiles" > /dev/null 2>&1; git pull && ./sync.py && . "$HOME/.bashrc"; popd > /dev/null 2>&1; nyan"
alias dotfiles="$HOME/dotfiles/update.sh"
# Clean up LaunchServices to remove duplicates in the “Open With” menu
#alias lscleanup="/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user && killall Finder"
@ -74,14 +74,14 @@ for method in GET HEAD POST PUT DELETE TRACE OPTIONS; do
done
# Download file and save it with filename of remote file
alias get="curl -O"
alias get="curl -LO"
# Convert line endings to UNIX
# tr -d '\015'
alias dos2unix="perl -pi -e 's/\r\n?/\n/g'"
# Password generator
password() { cat /dev/urandom | tr -dc A-Za-z0-9_ | head -c ${1:-10}; }
password() { cat /dev/urandom 2>/dev/null | tr -dc A-Za-z0-9_ 2>/dev/null | head --bytes=${1:-10}; }
# Show $PATH in a readable way
alias path='echo -e ${PATH//:/\\n}'
@ -103,3 +103,4 @@ alias dot-git="killall Marked; open -a marked --args $HOME/dotfiles/docs/Git.md"
alias dot-hub="killall Marked; find /usr/local/Cellar/hub/ -name README.md -exec open -a marked --args {} \;"
#alias dot-extras="killall Marked; find /usr/local/Cellar/git-extras/ -name README.md -exec open -a marked --args {} \;"
alias dot-extras="open https://github.com/visionmedia/git-extras/blob/master/Readme.md#readme"

View File

@ -0,0 +1,26 @@
# If possible, add tab completion for many commands
[ -f /etc/bash_completion ] && source /etc/bash_completion
# Bash completion (installed via Homebrew; source after `brew` is added to PATH)
command -v brew >/dev/null 2>&1 && [ -r "$(brew --prefix)/etc/bash_completion" ] && source "$(brew --prefix)/etc/bash_completion"
# Add tab completion for SSH hostnames based on ~/.ssh/config, ignoring wildcards
function _ssh_reload_autocomplete() {
[ -e "~/.ssh/config" ] && complete -o "default" -o "nospace" -W "$(grep "^Host" ~/.ssh/config | grep -v "[?*]" | cut -d " " -f2)" scp sftp ssh
}
_ssh_reload_autocomplete
# Add AWS CLI Completion.
complete -C aws_completer aws
complete -F _tmux t
# Add Gush completion.
[ -f $HOME/.gush/.gush-autocomplete.bash ] && source $HOME/.gush/.gush-autocomplete.bash
if [ -d $HOME/dotfiles/bash_completion.d ];
then
for file in `find $HOME/dotfiles/bash_completion.d/ -type f -name '*.sh'`
do
source $file
done
fi

View File

@ -157,13 +157,22 @@ function _crlf_file() {
grep -q $'\x0D' "$1" && echo "$1" && [ $2 ] && dos2unix "$1"
}
function git-comandi()
{
if [ -s ~/.gitlocal ]; then
unlink ~/.gitlocal
fi
ln -s ~/.gitlocal_comandi ~/.gitlocal
}
function git-work()
{
if [ -s ~/.gitlocal ]; then
unlink ~/.gitlocal
fi
ln -s ~/.gitlocal_work ~/.gitlocal
ln -s ~/.gitlocal_yuki ~/.gitlocal
}
function git-private()
@ -179,3 +188,8 @@ function git-private()
for cmd in password hex2hsl hex2rgb escape codepoint ssh-key myip; do
eval "function $cmd+() { $cmd \$@ | c; }"
done
function k8s-ssh()
{
ssh admin@$(kubectl describe node $1 | grep -i externaldns | awk '{print $2}')
}

View File

@ -78,7 +78,7 @@ function prompt_command() {
PS2="\[$CYAN\]$prompt_symbol\[$NOCOLOR\] "
# Terminal title
local title="$(basename $PWD)"
local title=`basename "$PWD"`
[ -n "$remote" ] && title="$title \xE2\x80\x94 $HOSTNAME"
echo -ne "\033]0;$title"; echo -ne "\007"
}

View File

@ -0,0 +1,11 @@
#!/bin/bash
if [ -z "$SSH_AUTH_SOCK" ] ; then
eval `ssh-agent -s`
fi
KEY="$HOME/.ssh/work"
[ -f $KEY ] || return;
ssh-add -l | grep $KEY > /dev/null || ssh-add $KEY

View File

@ -17,7 +17,7 @@ fi
# Clone dotfiles and make symlinks
echo "Installing dotfiles..."
cd ~ && git clone git@bitbucket.org:jacobkiers/dotfiles.git && cd dotfiles && ./sync.py
cd ~ && git clone https://bitbucket.org/jacobkiers/dotfiles.git && cd dotfiles && ./sync.py
source ~/.bashrc
echo "Dotfiles installed successfully."

View File

@ -0,0 +1 @@
You can add global git hooks in this directory.

266
resources/git-hooks/pre-commit Executable file
View File

@ -0,0 +1,266 @@
#!/usr/bin/env php
<?php
/**
* .git/hooks/pre-commit
*
* This pre-commit hooks will check for PHP errors (lint), and make sure the
* code is PSR-2 compliant.
*
* @author Reen Lokum http://github.com/reenl
*
* The orignal version of this file can be found at:
* https://github.com/zendframework/zf2/blob/master/README-GIT.md
*
* Extended with functionality found at:
* http://kvz.io/blog/2013/12/29/one-git-commit-hook-to-rule-them-all/
*/
$exit = 0;
// Initial commit
$against = '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
if (run('git rev-parse --verify HEAD > /dev/null')) {
$against = 'HEAD';
}
// Only run when we're on a branch (to avoid rebase hell)
// http://git-blame.blogspot.nl/2013/06/checking-current-branch-programatically.html
$branch = run('git symbolic-ref --short -q HEAD');
if (!$branch) {
writeln('Not on any branch');
exit(0);
}
/*
* collect all files which have been added, copied or
* modified and store them in an array called output
*/
$diffLines = array();
exec('git diff-index --cached --full-index --diff-filter=ACM '.$against, $diffLines);
writeln();
// Filter files that don't need a check.
foreach ($diffLines as $line) {
$partList = preg_split('#\s+#', $line, 6);
$hash = $partList[3];
$status = $partList[4];
$fileName = $partList[5];
if ('D' === $status) {
// deleted file; do nothing
continue;
}
$type = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
$validator = 'validator_'.$type;
if (!$type || !function_exists($validator)) {
$type = run("git cat-file -p ".$hash." | head -n1 | awk -F/ '/^#\!/ {print \$NF}' | sed 's/^env //g'");
$validator = 'validator_'.$type;
if (!function_exists($validator)) {
// No validator
writeln(' Skipping "'.format($fileName, 'green').'" no validator available.');
continue;
}
}
write(' Checking "'.format($fileName, 'green').'" with validator '.format($type, 'green').'.');
$output = '';
if (!$validator($hash, $fileName, $output)) {
writeln(PHP_EOL.'X ERROR '.implode(PHP_EOL.' ', explode(PHP_EOL, $output)).PHP_EOL, 'red');
$exit = 1;
continue;
}
writeln(' OK', 'green');
}
if ($exit > 0) {
writeln(PHP_EOL."Please fix the above errors and run 'git add'.", 'gray');
}
exit($exit);
function validator_php($hash, $fileName, &$output)
{
if (validator_php_syntax($hash, $fileName, $output)) {
return validator_php_cs($hash, $fileName, $output);
}
return false;
}
function validator_php_syntax($hash, $fileName, &$output)
{
$output = '';
$exitCode = 0;
$result = run('git cat-file -p '.escapeshellarg($hash).' | php -l', $output, $exitCode, "purge", "default");
if ($result) {
return true;
}
$output = 'Syntax Error'.PHP_EOL.$output;
return false;
}
function validator_php_cs($hash, $fileName, &$output)
{
// Use .php_cs config if project has one.
$configFile = '';
if (file_exists('.php_cs')) {
$configFile = ' --config-file='.escapeshellarg(realpath('.php_cs'));
}
$tmpDir = '/tmp/cs-check/'.$hash;
$tmp = $tmpDir.'/'.$fileName;
run('mkdir -p '.dirname($tmp));
run('git cat-file -p '.escapeshellarg($hash).' > '.$tmp);
$return = null;
run('php-cs-fixer fix --dry-run --diff --verbose --rules=@Symfony'.$configFile.' '.escapeshellarg($tmp), $currentOutput, $return, 'default', 'default');
run('rm -rf '.escapeshellarg($tmpDir));
// Check output
if ($return !== 0) {
$out = explode(PHP_EOL, $currentOutput);
$rule = null;
foreach ($out as $line) {
if (preg_match('#\s+[0-9]+\)\s#', $line)) {
$rule = $line;
break;
}
}
if ($rule !== null && preg_match('#\((.*)\)#', $rule, $matches)) {
$output = 'Code Style errors'.PHP_EOL.$matches[1];
} else {
$output = 'Code Style errors'.PHP_EOL.implode(PHP_EOL, $out).PHP_EOL;
}
return false;
}
return true;
}
/**
* Runs like exec with a few changes:
* - Output is returned as a string.
* - Output is NOT appended.
* - STDERR is also added to the output.
* - STDERR and/or STDOUT can be disabled by passing purge.
* - Returns the first output line if successful and false when failed.
* - If no output is generated and the exit status equals 0 then true is returned.
*
* @param string $command
* @param string &$output
* @param int &$exitCode
* @param string $stdout
* @param string $stderr
*
* @return boolean
*/
function run($command, &$output = '', &$exitCode = 0, $stdout = 'default', $stderr = 'purge')
{
$descriptors = array(
0 => array("pipe", "r"), // stdin
1 => array("pipe", "w"), // stdout
2 => array("pipe", "w"), // stderr
);
$pipes = array();
$out = array();
$process = proc_open($command, $descriptors, $pipes);
fclose($pipes[0]);
unset($pipes[0]);
do {
$read = $pipes;
$write = $except = array();
if (!stream_select($read, $write, $except, 5)) {
writeln('Timeout on process: '.$command, 'red');
break;
}
foreach ($read as $pipe) {
$pipeId = array_search($pipe, $pipes);
if ($pipeId === false) {
writeln('Unable to determine where the output came from.', 'red');
}
if (feof($pipe)) {
fclose($pipe);
if ($pipeId !== false) {
unset($pipes[$pipeId]);
}
continue;
}
$line = fgets($pipe);
if ($line === false) {
continue;
}
$color = $stderr;
if ($pipeId == 1) {
$color = $stdout;
}
if ($color != 'purge') {
$out[] = format(rtrim($line), $color);
}
}
} while (count($pipes) > 0);
$exitCode = proc_close($process);
$output = implode(PHP_EOL, $out);
if ($exitCode == 0) {
if (!isset($out[0]) || $out[0] == '') {
return true;
}
return $out[0];
}
return false;
}
function format($string, $color = 'default')
{
if ($color == 'default') {
return $string;
}
if ($color == 'purge') {
return '';
}
$colors = array(
'gray' => 37,
'green' => 32,
'red' => 31,
);
if (!isset($colors[$color])) {
writeln($color.' is not a valid color.');
exit(1);
}
return chr(0x1B).'['.$colors[$color].'m'.$string.chr(0x1B).'[m';
}
function writeln($write = '', $color = 'default')
{
write($write.PHP_EOL, $color);
}
function write($write = '', $color = 'default')
{
echo format($write, $color);
flush();
}

View File

View File

@ -1,5 +1,67 @@
#!/bin/bash
source "$HOME/dotfiles/includes/installer.sh"
if command -v brew >/dev/null 2>&1; then
brew install caskroom/cask/brew-cask
install_cleanup
brew cask install alfred
brew cask install arq
brew cask install firefox
brew cask install google-chrome
brew cask install hipchat
brew cask install iterm2
brew cask install java
brew cask install libreoffice
brew cask install phpstorm
brew cask install skype
brew cask install slack
fi
if command -v apt >/dev/null 2>&1; then
sudo -v
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
# Add repositories
## Ondrej PHP PPA
sudo add-apt-repository -y ppa:ondrej/php
## Docker
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository -y "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
## Virtualbox
curl -fsSL https://www.virtualbox.org/download/oracle_vbox_2016.asc | sudo apt-key add -
sudo add-apt-repository -y "deb http://download.virtualbox.org/virtualbox/debian $(lsb_release -cs) contrib"
sudo apt update
# Install apt packages
sudo apt install -y \
chromium-browser \
dkms virtualbox-6.0 \
dnsmasq \
docker-ce \
git \
htop \
jq \
mysql-workbench \
scdaemon pcscd libccid \
transmission \
vim \
vlc
## Docker Compose
if [ ! -f /usr/local/bin/docker-compose ]; then
DOCKER_COMPOSE_VERSION=1.23.2
sudo curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose && sudo chmod +x /usr/local/bin/docker-compose
sudo curl -L https://raw.githubusercontent.com/docker/compose/${DOCKER_COMPOSE_VERSION}/contrib/completion/bash/docker-compose -o /etc/bash_completion.d/docker-compose
fi
## Vagrant
if [ ! -f /usr/bin/vagrant ]; then
sudo curl -L https://releases.hashicorp.com/vagrant/2.2.4/vagrant_2.2.4_x86_64.deb -o vagrant.deb && sudo dpkg -i vagrant.deb && rm -rf vagrant.deb
fi
fi

View File

@ -38,5 +38,7 @@ brew install https://raw.github.com/nybblr/homebrew-dev/master/sack.rb
brew install python
sudo pip install fabric
brew install gist
# Remove outdated versions from the cellar
brew cleanup

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""
Dotfiles syncronization.
@ -47,15 +47,15 @@ def main():
if is_link_to(dotfile, source):
continue
response = raw_input("Overwrite file `%s'? [y/N] " % dotfile)
response = input("Overwrite file `%s'? [y/N] " % dotfile)
if not response.lower().startswith('y'):
print "Skipping `%s'..." % dotfile
print("Skipping `%s'..." % dotfile)
continue
force_remove(dotfile)
os.symlink(source, dotfile)
print "%s => %s" % (dotfile, source)
print("%s => %s" % (dotfile, source))
if __name__ == '__main__':

View File

@ -27,9 +27,11 @@ for option in autocd globstar; do
done
# Locale
export LC_ALL=en_US.UTF-8
export LANG="en_US"
export LC_ALL=en_GB.UTF-8
export LANG="en_GB"
# Set the composer home.
export COMPOSER_HOME="$HOME/.composer"
# Prepend $PATH without duplicates
function _prepend_path() {
@ -39,16 +41,17 @@ function _prepend_path() {
}
# Construct $PATH
PATH='/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin'
[ -d /usr/texbin ] && _prepend_path "/usr/texbin"
PATH="/snap/bin:/usr/bin:/bin:/usr/sbin:/sbin"
[ -d /usr/local/sbin ] && _prepend_path "/usr/local/sbin"
[ -d /usr/local/bin ] && _prepend_path "/usr/local/bin"
[ -d /usr/local/share/npm/bin ] && _prepend_path "/usr/local/share/npm/bin"
[ -d /usr/local/opt/ruby/bin ] && _prepend_path "/usr/local/opt/ruby/bin"
[ -d /usr/local/share/python ] && _prepend_path "/usr/local/share/python"
command -v brew >/dev/null 2>&1 && _prepend_path "$(brew --prefix coreutils)/libexec/gnubin"
[ -d ~/dotfiles/bin ] && _prepend_path "$HOME/dotfiles/bin"
[ -d ~/bin ] && _prepend_path "$HOME/bin"
[ -f /usr/bin/npm ] && _prepend_path "./node_modules/.bin" # Node.js
[ -d /usr/texbin ] && _prepend_path "/usr/texbin" # LaTex
[ -d $HOME/.cargo/bin ] && _prepend_path "$HOME/.cargo/bin" # Rust
[ -d $HOME/.local/bin ] && _prepend_path "$HOME/.local/bin" # Local bin
[ -d $HOME/bin ] && _prepend_path "$HOME/bin" # ~/bin
[ -d $HOME/dotfiles/bin ] && _prepend_path "$HOME/dotfiles/bin" # Dotfiles bin
[ -d "$COMPOSER_HOME/vendor/bin" ] && _prepend_path "$COMPOSER_HOME/vendor/bin" # PHP Composer
_prepend_path "./vendor/bin"
export PATH
# Colors
@ -69,45 +72,14 @@ NOCOLOR="$(tput sgr0)"
export EDITOR=`which vim`
# Load prompt and aliases
for file in ~/dotfiles/includes/bash_{prompt,aliases,functions,git}.bash; do
for file in ~/dotfiles/includes/bash_*.bash; do
[ -r "$file" ] && source "$file"
done
unset file
# If possible, add tab completion for many commands
[ -f /etc/bash_completion ] && source /etc/bash_completion
# Bash completion (installed via Homebrew; source after `brew` is added to PATH)
command -v brew >/dev/null 2>&1 && [ -r "$(brew --prefix)/etc/bash_completion" ] && source "$(brew --prefix)/etc/bash_completion"
# Add tab completion for SSH hostnames based on ~/.ssh/config, ignoring wildcards
function _ssh_reload_autocomplete() {
[ -e "~/.ssh/config" ] && complete -o "default" -o "nospace" -W "$(grep "^Host" ~/.ssh/config | grep -v "[?*]" | cut -d " " -f2)" scp sftp ssh
}
_ssh_reload_autocomplete
# Grunt completion
command -v grunt >/dev/null 2>&1 && eval "$(grunt --completion=bash)"
# Tamia generator completion
function _tamia_autocomplete() {
# List of subgenerators
local available=$(for file in /usr/local/share/npm/lib/node_modules/generator-tamia/*/index.js; do echo $file | cut -d / -f 9; done)
# The word fragment
local word=${COMP_WORDS[COMP_CWORD]}
# Dont attempt to filter w/`grep` if `$word` is empty
local filtered=$(if [ -z "$word" ]; then echo "$available"; else echo "$available" | grep $word; fi)
COMPREPLY=($filtered)
}
command -v yo >/dev/null 2>&1 && complete -F _tamia_autocomplete tm
# Tell ls to be colourful
export CLICOLOR=1
# Tell grep to highlight matches
export GREP_OPTIONS='--color=auto'
# Make less the default pager, and specify some useful defaults.
less_options=(
# If the entire text fits on one screen, just show it and quit. (Be more
@ -138,3 +110,10 @@ export PAGER='less'
# Load extra (private) settings
[ -f ~/.bashlocal ] && source ~/.bashlocal
# Disable microsoft telemetry
export DOTNET_CLI_TELEMETRY_OPTOUT=1
export BASH_PROFILE_LOADED=1
# Force a green prompt
true

View File

@ -1,3 +1,5 @@
# https://github.com/janmoesen/tilde/blob/master/.bashrc
[ -n "$PS1" ] && source ~/.bash_profile;
[ -n "$BASH_PROFILE_LOADED" ] && source ~/.bash_profile;
[ -n "$PS1" ] && source ~/.bash_profile;

View File

@ -6,39 +6,54 @@
frag = white
old = red bold
new = green bold
[help]
autocorrect = 1
[core]
editor = vim
# Force vim in foreground mode.
editor = vim -f
# http://stackoverflow.com/questions/136178/git-diff-handling-long-lines
# If doesn't work, try: pager = less -+$LESS -FRX
pager = less -r
pager = less -RFX
# pager = diff-highlight | less -RFX
# pager = less -r
autocrlf = false
safecrlf = false
mergeoptions = --no-edit
excludesfile = ~/.gitignore
[alias]
a = add
ua = reset HEAD
ap = add --patch
b = branch
c = commit --verbose
ca = commit -a --verbose
cm = commit -m --verbose
cam = commit -am --verbose
c = commit --verbose --signoff
cm = commit --verbose --signoff --message
co = checkout
d = diff --color-words
s = status -sb
d = diff
ds = diff --staged
l = log --graph --pretty=format:'%C(magenta)%h%C(blue)%d%Creset %s %C(blue bold)- %an, %ar%Creset'
ll = log --stat --abbrev-commit
conflicts = diff --name-only --diff-filter=U
r = rebase
s = status --short --branch
ua = reset HEAD
commerge = commit --no-edit
conflicts = diff --name-only --diff-filter=U
[push]
default = current
default = upstream
# Any GitHub repo with my username should be checked out r/w by default
# http://rentzsch.tumblr.com/post/564806957/public-but-hackable-git-submodules
[url "git@github.com:jacobkiers/"]
insteadOf = "git://github.com/jacobkiers/"
[url "git@bitbucket.org:jacobkiers/"]
insteadOf = "https://bitbucket.org/jacobkiers/"
# URL shorthands
[url "git@bitbucket.org:"]
insteadOf = "bb:"
[url "git@github.com:"]
insteadOf = "gh:"
pushInsteadOf = "github:"
@ -57,11 +72,16 @@
# DiffMerge
[merge]
ff = no
commit = no
tool = diffmerge
[mergetool "diffmerge"]
cmd = diffmerge --merge --result=$MERGED $LOCAL $BASE $REMOTE
trustExitCode = true
[diff]
algorithm = minimal
compationHeuristic = true
renames = true
tool = diffmerge
[difftool "diffmerge"]
cmd = diffmerge $LOCAL $REMOTE
@ -72,3 +92,17 @@
# git config -f ~/.gitlocal user.name "Jacob Kiers"
[include]
path = .gitlocal
[fetch]
prune = true
[init]
templatedir = ~/dotfiles/resources/git-template
[pull]
ff = yes
#[commit]
# gpgSign = true
[tag]
forceSignAnnotated = true
[user]
signingkey = 6652F0F4418231A7

View File

@ -1,3 +1,4 @@
# Python stuff
*.pyc
VENV
@ -22,3 +23,5 @@ bower_components
# IDEs stuff
.idea
atlassian-ide-plugin.xml
.vscode

44
update.sh Executable file
View File

@ -0,0 +1,44 @@
#!/usr/bin/env bash
pushd "$HOME/dotfiles" > /dev/null || exit 1;
CURRENT_HASH=`md5sum update.sh | awk '{ print $1 }'`
echo -n "Pulling changes... "
git pull
NEW_HASH=`md5sum update.sh | awk '{ print $1 }'`
if [ "$CURRENT_HASH" != "$NEW_HASH" ]
then
echo "The update script has changed."
./update
exit
fi
echo "Syncing..."
./sync.py
source "$HOME/.bashrc"
if [ ! -f bin/composer ]
then
echo "Installing composer..."
wget https://getcomposer.org/composer.phar -O bin/composer
chmod +x bin/composer
fi
echo -n "Updating composer and dependencies... "
bin/composer --quiet self-update
#bin/composer --quiet global require \
# fabpot/php-cs-fixer \
# phpmd/phpmd \
# phpunit/phpunit \
# squizlabs/php_codesniffer
echo "Done."
if [ ! -L resources/git-template/hooks ]
then
ln -s $HOME/dotfiles/resources/git-hooks resources/git-template/hooks
fi
popd > /dev/null