dotfiles/.custom_bash_scripts

129 lines
2.4 KiB
Plaintext
Raw Normal View History

2021-12-19 06:31:30 +08:00
#!/bin/sh
2022-02-27 20:43:04 +08:00
# 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
}
2021-03-06 22:05:59 +08:00
# cd into config dir
cfdir()
{
cd $HOME/.config/$1
}
2021-03-06 22:05:59 +08:00
# 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
}
2021-03-06 22:05:59 +08:00
# pacman list sizes
pacsizes()
{
pacman -Qi $1 | awk '/^Name/{name=$3} /^Installed Size/{size=$4$5; print size, name;}' | sort -h
}
2021-03-06 22:05:59 +08:00
# 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
}
2022-06-13 22:44:02 +08:00
# view zathura 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
}
wdir()
{
wdir="$PWD/$1"
[ -d "$wdir" ] && echo "$wdir" > "$WDIR_PATH" && echo "set $wdir"
}
pwdir()
{
if [ -f "$WDIR_PATH" ]
then
cat "$WDIR_PATH"
else
echo "Working directory not set."
fi
}
cwdir()
{
if [ -f "$WDIR_PATH" ]
then
rm -f "$WDIR_PATH"
echo "Cleared working directory."
else
echo "Working directory not set."
fi
}