Last active
June 10, 2024 05:58
-
-
Save opplatek/8c2def14b02ad4c80eac87fd90f3d260 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alias 'h'='head' | |
alias haed="head" # My most common typo | |
alias 'gitl'='git log -p' | |
alias 'p'='pwd' | |
alias 'dockeri'='docker images' | |
alias 'cleanswap'='sudo swapoff -a; sudo swapon -a' | |
alias 'python3.8unit'='python3.8 -m unittest' | |
function gitreset() { | |
local git_branch_name=$(git rev-parse --abbrev-ref HEAD) | |
git fetch origin | |
git reset --hard origin/${git_branch_name} | |
} | |
function gitgetlsf() { | |
git lfs pull --include "$1" | |
} | |
function gitlisttracked() { | |
if [ $# -eq 0 ]; then | |
local gitbranch=$(gitb) | |
else | |
local gitbranch=$1 | |
fi | |
echo "Git tracked files for ${gitbranch}:" | |
git ls-tree -r ${gitbranch} --name-only | |
} | |
function gitlsflisttracked() { | |
git lfs ls-files | |
} | |
function tardir() { | |
local dir="${1%%/}" | |
tar czf "${dir}".tar.gz "$dir" | |
} | |
function coverage_py() { | |
coverage run -m unittest $1 | |
coverage report -m | |
coverage html -d coverage_html | |
} | |
function formatpy() { | |
isort -l 120 --sl --profile black $1 | |
black -l 120 $1 | |
} | |
function formatjson() { | |
python3 -m json.tool $1 | |
} | |
function gitb() { | |
local git_branch_name=$(git rev-parse --abbrev-ref HEAD) | |
echo $git_branch_name | |
} | |
function gitc() { | |
local git_branch_name=$(basename $(git rev-parse --abbrev-ref HEAD)) | |
local git_commit_message="$1" | |
echo "git commit -m '${git_branch_name} ${git_commit_message}'" | |
} | |
function up() { | |
cd $(printf '../%.0s' $(seq 1 $1)) | |
} | |
function hgrep() { | |
history | grep $1 | |
} | |
function tab2xls() { | |
if [ "${1##*.}" == "tsv" ] || [ "${1##*.}" == "tab" ] || [ "${1##*.}" == "csv" ]; then | |
local rnd=$RANDOM | |
if [ "${1##*.}" == "tsv" ] || [ "${1##*.}" == "tab" ]; then | |
cat $1 \ | |
| sed 's/,/;/g' \ | |
| sed 's/\t/,/g' \ | |
> ${1%.*}.${rnd}-tmp.csv | |
else | |
cp $1 ${1%.*}.${rnd}-tmp.csv | |
fi | |
unix2dos ${1%.*}.${rnd}-tmp.csv | |
unoconv --format xls ${1%.*}.${rnd}-tmp.csv && mv ${1%.*}.${rnd}-tmp.xls ${1%.*}.xls | |
rm ${1%.*}.${rnd}-tmp.csv | |
else | |
echo "Unknown format. Please use on of the: csv, tsv, tab." | |
fi | |
} | |
function zhead { | |
if [ "$#" -gt 2 ]; then | |
echo "Too many arguments, use only gz input and, optionaly, number of lines." | |
elif [ "$#" -eq 2 ]; then | |
zcat $1 | head -n $2 | |
else | |
zcat $1 | head | |
fi | |
} | |
function dockerun() { | |
if (( $# == 0 )); then | |
local dockerid=$(dockeri | grep -v "^REPOSITORY" | head -1 | sed 's/ */ /g' | cut -d' ' -f3) | |
else | |
local dockerid=$1 | |
fi | |
if (( $# > 1 )); then | |
docker run -v "$2" -it --rm $dockerid /bin/bash | |
else | |
docker run -it --rm $dockerid /bin/bash | |
fi | |
} | |
function dockerbuild() { | |
if [ "$#" -eq 1 ]; then | |
local name=$1 | |
else | |
local name=$(basename $(pwd)) | |
fi | |
local name=$(tr '[:upper:]' '[:lower:]' <<< $name) | |
docker build -t $name . | |
} | |
function dockerexec() { | |
docker exec -it $1 bash | |
} | |
function dockerprune() { | |
docker system prune -a | |
} | |
# Get only unique values - much faster than sort | uniq | |
function sortu() { | |
awk '!a[$0]++' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment