dotfiles/.custom_bash_scripts
2022-02-27 20:43:04 +08:00

102 lines
2.1 KiB
Bash

#!/bin/sh
# init for dotfiles.
initdots()
{
config='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
config checkout HEAD
source $HOME/.bashrc
}
# nnn
# for nnn file manager
n ()
{
# Block nesting of nnn in subshells
if [ -n $NNNLVL ] && [ "${NNNLVL:-0}" -ge 1 ]; then
echo "nnn is already running"
return
fi
# The default behaviour is to cd on quit (nnn checks if NNN_TMPFILE is set)
# To cd on quit only on ^G, remove the "export" as in:
# NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd"
# NOTE: NNN_TMPFILE is fixed, should not be modified
export NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd"
# Unmask ^Q (, ^V etc.) (if required, see `stty -a`) to Quit nnn
# stty start undef
# stty stop undef
# stty lwrap undef
# stty lnext undef
nnn -A -x "$@"
if [ -f "$NNN_TMPFILE" ]; then
. "$NNN_TMPFILE"
rm -f "$NNN_TMPFILE" > /dev/null
fi
}
# cd into config dir
cfdir()
{
cd $HOME/.config/$1
}
# sshfs into newnumyspace
nnms_fs()
{
dir_name="newnumyspace"
path="${HOME}/dev"
if [ ! -d $path/$dir_name ]
then
mkdir $path/$dir_name
echo "Created new directory $dir_name at $path"
fi
sshfs unn_w19014537@newnumyspace.co.uk:/home/unn_w19014537/ $path/$dir_name/
if [ $? -eq 0 ]
then
echo "Mounted at $path/$dir_name."
fi
}
# pacman list sizes
pacsizes()
{
pacman -Qi $1 | awk '/^Name/{name=$3} /^Installed Size/{size=$4$5; print size, name;}' | sort -h
}
# view markdown files in zathura
viewmd()
{
[ -z $1 ] && return
[ ! -f $1 ] && return
pdfname=$(basename $1 .md).pdf
echo $pdfname
if [ -f $pdfname ]; then
zathura $pdfname
else
pandoc -t pdf $1 | zathura -
fi
}
# generate markdown files from markdown
makemd()
{
[ -z $1 ] && return
[ ! -f $1 ] && return
pandoc -t pdf $1 -o $(basename $1 .md).pdf
}
# view zathrua in tabbed
tzathura()
{
# rm tabbbed.xid if not running
! pgrep -f tabbed && rm /tmp/tabbed.xid
if [ ! -f /tmp/tabbed.xid ]; then
tabbed -c -d > /tmp/tabbed.xid
fi
zathura "$@" -e $(</tmp/tabbed.xid) & disown
}