Compare commits

...

2 Commits

3 changed files with 54 additions and 46 deletions

21
.local/bin/cidr2mask Executable file
View File

@ -0,0 +1,21 @@
#!/bin/bash
cidr2mask() {
local i mask=""
local full_octets=$(($1 / 8))
local partial_octet=$(($1 % 8))
for ((i = 0; i < 4; i += 1)); do
if [ $i -lt $full_octets ]; then
mask+=255
elif [ $i -eq $full_octets ]; then
mask+=$((256 - 2 ** (8 - partial_octet)))
else
mask+=0
fi
test $i -lt 3 && mask+=.
done
echo $mask
}
cidr2mask "$@"

20
.local/bin/mask2cidr Executable file
View File

@ -0,0 +1,20 @@
#!/bin/bash
mask2cidr() {
local mask=$1
# In RFC 4632 netmasks there's no "255." after a non-255 byte in the mask
local left_stripped_mask=${mask##*255.}
local len_mask=${#mask}
local len_left_stripped_mask=${#left_stripped_mask}
local conversion_table=0^^^128^192^224^240^248^252^254^
local number_of_bits_stripped=$(((len_mask - len_left_stripped_mask) * 2))
local signifacant_octet=${left_stripped_mask%%.*}
local right_stripped_conversion_table=${conversion_table%%$signifacant_octet*}
local len_right_stripped_conversion_table=${#right_stripped_conversion_table}
local number_of_bits_from_conversion_table=$((len_right_stripped_conversion_table / 4))
echo $((number_of_bits_stripped + number_of_bits_from_conversion_table))
}
mask2cidr "$@"

59
.zshrc
View File

@ -16,43 +16,6 @@ gbranch() {
echo -e "$(git branch "$@")"
}
mask2cidr() {
local mask=$1
# In RFC 4632 netmasks there's no "255." after a non-255 byte in the mask
local left_stripped_mask=${mask##*255.}
local len_mask=${#mask}
local len_left_stripped_mask=${#left_stripped_mask}
local conversion_table=0^^^128^192^224^240^248^252^254^
local number_of_bits_stripped=$((($len_mask - $len_left_stripped_mask) * 2))
local signifacant_octet=${left_stripped_mask%%.*}
local right_stripped_conversion_table=${conversion_table%%$signifacant_octet*}
local len_right_stripped_conversion_table=${#right_stripped_conversion_table}
local number_of_bits_from_conversion_table=$((len_right_stripped_conversion_table / 4))
echo $(($number_of_bits_stripped + $number_of_bits_from_conversion_table))
}
cidr2mask() {
local i mask=""
local full_octets=$(($1 / 8))
local partial_octet=$(($1 % 8))
for ((i = 0; i < 4; i += 1)); do
if [ $i -lt $full_octets ]; then
mask+=255
elif [ $i -eq $full_octets ]; then
mask+=$((256 - 2 ** (8 - $partial_octet)))
else
mask+=0
fi
test $i -lt 3 && mask+=.
done
echo $mask
}
[ -f /etc/gentoo-release ] && export ZSH="/usr/share/zsh/site-contrib/oh-my-zsh"
[ -f /etc/centos-release ] && export ZSH="$HOME/.oh-my-zsh"
[ -f /etc/debian_version ] && export ZSH="$HOME/.oh-my-zsh"
@ -130,10 +93,12 @@ fi
alias ansible-lint-work='GIT_SSH_COMMAND="ssh -i ~/.ssh/work/id_rsa" ansible-lint'
alias ansible-galaxy-work='GIT_SSH_COMMAND="ssh -i ~/.ssh/work/id_rsa" ansible-galaxy'
alias ssh-work="ssh -i ~/.ssh/work/id_rsa"
alias gwork='GIT_SSH_COMMAND="ssh -i ~/.ssh/work/id_rsa" git'
alias rsyncwork="rsync -h --progress -e 'ssh -i ~/.ssh/work/id_rsa'"
alias gcommitw="git commit --author='Marcin Woźniak <marcin.wozniak@wundermanthompson.com>'"
alias git-work='GIT_SSH_COMMAND="ssh -i ~/.ssh/work/id_rsa" git'
alias gwork=git-work
alias gitwork=gwork
alias gcommitw="git commit --author='Marcin Woźniak <marcin.wozniak@wundermanthompson.com>'"
alias git-commit-work=gcommitw
alias gitcommitwork=gcommitw
alias gitworkcommit=gcommitw
@ -210,9 +175,6 @@ if [[ "$(uname)" == "Darwin" ]]; then
sort |
tail -n1)
export PATH=$PATH:/opt/homebrew/Cellar/tfenv/$TFENVVERSION/versions/$TFVERSION/
# Project
alias meraki="cd $HOME/git/ansible_collections/cisco/meraki/"
fi
# Setting the right editor
@ -246,7 +208,8 @@ alias myip="curl ipinfo.io/ip"
alias changefont="figlet"
# Git
alias gexclude="git update-index --assume-unchanged"
alias git-exclude="git update-index --assume-unchanged"
alias gexclude=git-exclude
alias gmaster="git checkout master; git checkout main"
alias gmain="git checkout master; git checkout main"
alias gcommit="git commit --author='Marcin Woźniak <y0rune@aol.com>' -s"
@ -259,15 +222,19 @@ alias gch="git checkout"
alias gst="git status -s"
alias gdiff="git --no-pager diff"
alias glog="git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an - %ae>%Creset' --abbrev-commit --branches"
alias gshow="git --no-pager show --color --pretty=format:%b"
alias gd=gshow
alias guntrackfile="git update-index --assume-unchanged"
alias git-show="git --no-pager show --color --pretty=format:%b"
alias gshow=git-show
alias gd=git-show
alias git-untrack-file="git update-index --assume-unchanged"
alias guntrackfile=git-untrack-file
# Others
alias channel-check='sudo iwlist wlan0 scan | egrep -i "essid|frequency"'
alias newswork="newsboat --url=$HOME/.config/newsboat/urlswork"
alias aria2c="aria2c --seed-time=0 --disable-ipv6 --max-upload-limit=1k"
alias irc="ssh mikrus -t 'screen -r'"
# GoLang
alias go-mod="go mod edit -go $(go version | grep -oE 'go[0-9]*\.[0-9]*\.[0-9]*' | sed 's/go//g'); go get -u; go mod verify; go get -x -v; go mod verify; go mod tidy"
# Resolve problem with - zsh: no matches found