mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-01-26 11:14:08 +00:00
215 lines
5.5 KiB
Bash
Executable File
215 lines
5.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
||
# shellcheck source="../scripts/shared.sh"
|
||
# shellcheck disable=1091,2139
|
||
DOTFILES="$HOME/.dotfiles"
|
||
|
||
# Get installed php versions from brew and setup aliases
|
||
function x-set-php-aliases
|
||
{
|
||
have brew && {
|
||
local php_versions=()
|
||
while IFS="" read -r line; do php_versions+=("$line"); done < <(brew_installed | grep '^php')
|
||
|
||
php_error_reporting='-d error_reporting=22527'
|
||
|
||
for version in "${php_versions[@]}"; do
|
||
# drop the dot from version (8.0 -> 80)
|
||
local php_abbr="${version//\./}"
|
||
# replace "php@" with "p" so "php@80" becomes "p80"
|
||
local php_alias="${php_abbr//php@/p}"
|
||
|
||
# Fetch the exec path once
|
||
php_exec="$(brew --prefix "$version")/bin/php"
|
||
|
||
# Raw PHP without error_reporting flag.
|
||
# shellcheck disable=SC2139
|
||
alias "${php_alias}"r="$php_exec"
|
||
# PHP with error_reporting flag.
|
||
# shellcheck disable=SC2139,SC2140
|
||
alias "$php_alias"="$php_exec $php_error_reporting"
|
||
# Local PHP Server.
|
||
# shellcheck disable=SC2139,SC2140
|
||
alias "${php_alias}s"="$php_exec -S localhost:9000"
|
||
# Use composer with specific PHP and error_reporting flag on.
|
||
# shellcheck disable=SC2139,SC2140
|
||
alias "${php_alias}c"="$php_exec $php_error_reporting $(which composer)"
|
||
done
|
||
}
|
||
}
|
||
|
||
if [[ $(uname) == 'Darwin' ]]; then
|
||
|
||
x-set-php-aliases
|
||
|
||
# Laravel Sail shortcut
|
||
alias sail='[ -f sail ] && bash sail || bash vendor/bin/sail'
|
||
|
||
# Flush Directory Service cache
|
||
alias flushdns="sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder"
|
||
|
||
# Lock the screen
|
||
alias afk="osascript -e 'tell application \"System Events\" to keystroke \"q\" using {command down,control down}'"
|
||
|
||
# Empty the Trash on all mounted volumes and the main HDD
|
||
# Also, clear Apple’s System Logs to improve shell startup speed
|
||
alias emptytrash="sudo rm -rfv /Volumes/*/.Trashes; sudo rm -rfv ~/.Trash; sudo rm -rfv /private/var/log/asl/*.asl"
|
||
fi
|
||
|
||
# Be nice
|
||
alias please="sudo "
|
||
|
||
# Color the grep output
|
||
alias grep='grep --color'
|
||
|
||
! have eza && alias ls='ls --color=auto'
|
||
have eza && {
|
||
alias ls='eza -h -s=type --git --icons --group-directories-first'
|
||
}
|
||
|
||
# Easier navigation: .., ..., ....
|
||
alias ..="cd .."
|
||
alias ...="cd ../.."
|
||
alias ....="cd ../../.."
|
||
|
||
# cd to git root directory
|
||
alias cdgr='cd "$(git root)"'
|
||
|
||
# Shortcuts for listing
|
||
alias ll="ls -la"
|
||
alias l="ls -a"
|
||
|
||
# Prevent common typos
|
||
alias cd..="cd .."
|
||
alias sl="ls"
|
||
|
||
# List only directories
|
||
alias lsd="ls -lF | grep '^d'"
|
||
|
||
# IP addresses
|
||
alias ip="dig +short myip.opendns.com @resolver1.opendns.com"
|
||
alias localip="ipconfig getifaddr en1"
|
||
alias ips="ifconfig -a | grep -o 'inet6\? \(\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\)\|[a-fA-F0-9:]\+\)' | sed -e 's/inet6* //'"
|
||
|
||
# Show/hide hidden files in Finder
|
||
alias show="defaults write com.apple.finder AppleShowAllFiles -bool true; killall Finder"
|
||
alias hide="defaults write com.apple.finder AppleShowAllFiles -bool false; killall Finder"
|
||
|
||
# Pipe public key to clipboard.
|
||
alias pubkey="more ~/.ssh/id_rsa.pub | pbcopy | echo '=> Public key copied to pasteboard.'"
|
||
|
||
# Flush Directory Service cache
|
||
alias flush="dscacheutil -flushcache"
|
||
|
||
# Update locatedb
|
||
alias updatedb="sudo /usr/libexec/locate.updatedb"
|
||
|
||
# Always return full history
|
||
alias history="history 1"
|
||
|
||
# tmux: automatically attach or create session with name 'main'
|
||
alias tmux='tmux new-session -A -s main'
|
||
# tmux: attach or create new session
|
||
alias ta='tmux attach || tmux'
|
||
|
||
# watch with: differences, precise, beep and color
|
||
alias watchx='watch -dpbc'
|
||
# delete .DS_Store files
|
||
alias zapds='find . -name ".DS_Store" -print -delete'
|
||
# Recursively delete `.pyc` files
|
||
alias zappyc="find . -type f -name '*.pyc' -ls -delete"
|
||
# Run all zaps
|
||
alias zapall="zapds && zappyc"
|
||
# tail with follow flag on
|
||
alias t='tail -f'
|
||
# directory usage, return only the total
|
||
alias dn='du -chd1'
|
||
# Mirror site with wget
|
||
alias mirror_site='wget -m -k -K -E -e robots=off'
|
||
# Mirror stdout to stderr, useful for seeing data going through a pipe
|
||
alias peek='tee >(cat 1>&2)'
|
||
|
||
alias code_scanner='docker run
|
||
--env SOURCE_CODE="$PWD"
|
||
--volume "${PWD}":/code
|
||
--volume /var/run/docker.sock:/var/run/docker.sock
|
||
registry.gitlab.com/gitlab-org/ci-cd/codequality:"${CODEQUALITY_VERSION:-latest}"
|
||
/code'
|
||
|
||
alias zedit='$EDITOR ~/.dotfiles'
|
||
|
||
alias irssi="irssi --config=$XDG_CONFIG_HOME/irssi/config --home=$XDG_CONFIG_HOME/irssi"
|
||
|
||
if [[ -f "$HOME/.aliases.local" ]]; then
|
||
# shellcheck disable=SC1091
|
||
source "$HOME/.aliases.local"
|
||
fi
|
||
|
||
alias wget=wget --hsts-file="$XDG_DATA_HOME/wget-hsts"
|
||
alias svn="svn --config-dir $XDG_CONFIG_HOME/subversion"
|
||
|
||
# Alacritty preexec hook to update dynamic title
|
||
preexec()
|
||
{
|
||
print -Pn "\e]0;$1%~\a"
|
||
}
|
||
|
||
# Update dotfiles
|
||
dfu()
|
||
{
|
||
(
|
||
cd "$DOTFILES" && git pull --ff-only && ./install -q
|
||
)
|
||
}
|
||
|
||
# Weather in Tampere, or other city
|
||
weather()
|
||
{
|
||
# https://github.com/chubin/wttr.in#usage
|
||
local city="${1:-Tampere}"
|
||
curl "http://wttr.in/${city// /+}?2nFQM&lang=fi"
|
||
}
|
||
|
||
# Docker
|
||
ssh-docker()
|
||
{
|
||
docker exec -it "$@" bash
|
||
}
|
||
|
||
# All the dig info
|
||
digga()
|
||
{
|
||
dig +nocmd "$1" any +multiline +noall +answer
|
||
}
|
||
|
||
# Rector project to php version 8.2 by default.
|
||
rector()
|
||
{
|
||
local php="${1:-82}"
|
||
docker run -v "$(pwd)":/project rector/rector:latest process \
|
||
"/project/$1" \
|
||
--set "php${php}" \
|
||
--autoload-file /project/vendor/autoload.php
|
||
}
|
||
|
||
# Commit everything
|
||
commit()
|
||
{
|
||
commitMessage="$*"
|
||
|
||
if [ "$commitMessage" = "" ]; then
|
||
commitMessage="Automated commit"
|
||
fi
|
||
|
||
git add .
|
||
eval "git commit -a -m '${commitMessage}'"
|
||
}
|
||
|
||
scheduler()
|
||
{
|
||
while :; do
|
||
php artisan schedule:run
|
||
echo "Sleeping 60 seconds..."
|
||
sleep 60
|
||
done
|
||
}
|