# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi

# User specific environment
if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]
then
    PATH="$HOME/.local/bin:$HOME/bin:$PATH"
fi
export PATH

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions
 
# alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'

# eye^W finger candy
#
export HISTCONTROL=ignoreboth

# https://users.aalto.fi/~ltuuri/apu/bin/external-hdd-poweroff.bash
external-hdd-poweroff() {
  [ "$1" != '' ] &&  udisksctl power-off -b $1  ||  lsblk -o NAME,FSTYPE,MOUNTPOINT,HOTPLUG | grep 1$
}

# https://users.aalto.fi/~ltuuri/apu/bin/ipa.html
ipa() {
  /sbin/ip a | /usr/bin/perl -Mstrict -wane '
    BEGIN { printf "%s\n", "="x26 }
    printf "%-15s %10s\n%s\n", $&, $F[-1], "-"x26  if  /\d{1,3}(\.\d{1,3}){3}/ '
}

# https://users.aalto.fi/~ltuuri/apu/bin/m.sh
m() {
  if [ "$1" = "-n" ]
  then
    mount | sort -n | perl -ane 'printf "%-38s %-30s %5s\n", $F[0], $F[2], $F[4] if $F[4]=~/nfs.?$/'
  else
    mount -l -t btrfs,fat,exfat,ext2,ext4,iso9660,ntfs3,ufs,vfat,xfs,zfs
  fi
}

# https://users.aalto.fi/~ltuuri/apu/bin/Tee-Ram-Levy.command
ramdisk() {
  [ -z "$1" ] && echo "usage: ${FUNCNAME[0]} <ramdisk-size in GB> # mounts in /mnt !"  || mount -t tmpfs -o size=${1}g tmpfs /mnt
}

# https://users.aalto.fi/~ltuuri/apu/bin/ican.html
my-ip() {
  printf " %s \n %s \n" $(curl -s icanhazip.com) $(curl -s ifconfig.me)
}
