Files
dotfiles/config/functions

117 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# shell functions
#
# Weather in Tampere, or other city
function weather
{
# https://github.com/chubin/wttr.in#usage
local city="${1:-Tampere}"
curl "http://wttr.in/${city// /+}?2nFQM&lang=fi"
}
# Docker
function ssh-docker
{
docker exec -it "$@" bash
}
# Create a new directory and enter it
function mkd
{
mkdir -p "$@" && cd "$@" || exit
}
# All the dig info
function digga
{
dig +nocmd "$1" any +multiline +noall +answer
}
# Rector project to php version 8.0 by default.
function rector
{
local php="${1:-80}"
docker run -v "$(pwd)":/project rector/rector:latest process \
"/project/$1" \
--set "php${php}" \
--autoload-file /project/vendor/autoload.php
}
# Commit everything
function commit
{
commitMessage="$*"
if [ "$commitMessage" = "" ]; then
commitMessage="Automated commit"
fi
git add .
eval "git commit -a -m '${commitMessage}'"
}
function scheduler
{
while :; do
php artisan schedule:run
echo "Sleeping 60 seconds..."
sleep 60
done
}
function silent
{
"$@" >&/dev/null
}
# Remove directory from the PATH variable
# usage: path_remove ~/.local/bin
function path_remove
{
PATH=$(echo -n "$PATH" | awk -v RS=: -v ORS=: "\$0 != \"$1\"" | sed 's/:$//')
}
# Append directory to the PATH
# usage: path_append ~/.local/bin
function path_append
{
path_remove "$1"
PATH="${PATH:+"$PATH:"}$1"
}
# Prepend directory to the PATH
# usage: path_prepend ~/.local/bin
function path_prepend
{
path_remove "$1"
PATH="$1${PATH:+":$PATH"}"
}
# Defines default antigen bundles
function x-default-antigen-bundles
{
# these should be always available
antigen bundle colored-man-pages
antigen bundle command-not-found
antigen bundle ssh-agent
antigen bundle MichaelAquilina/zsh-you-should-use
antigen bundle Sparragus/zsh-auto-nvm-use
antigen bundle jreese/zsh-titles
antigen bundle unixorn/autoupdate-antigen.zshplugin
antigen bundle zsh-users/zsh-completions
antigen bundle zsh-users/zsh-syntax-highlighting
# these should be available if there's need
hash git 2> /dev/null && antigen bundle git
hash brew 2> /dev/null && antigen bundle brew
hash docker 2> /dev/null && antigen bundle docker
hash docker-compose 2> /dev/null && antigen bundle sroze/docker-compose-zsh-plugin
hash jq 2> /dev/null && antigen bundle reegnz/jq-zsh-plugin
hash nvm 2> /dev/null && antigen bundle nvm
hash php 2> /dev/null && antigen bundle php
hash python 2> /dev/null && antigen bundle MichaelAquilina/zsh-autoswitch-virtualenv
hash rvm 2> /dev/null && antigen bundle unixorn/rvm-plugin
}