aboutsummaryrefslogtreecommitdiff
path: root/shellrc.d
diff options
context:
space:
mode:
Diffstat (limited to 'shellrc.d')
-rw-r--r--shellrc.d/alias4
-rw-r--r--shellrc.d/desktop59
-rw-r--r--shellrc.d/function4
-rw-r--r--shellrc.d/shortcuts20
-rw-r--r--shellrc.d/ssh23
-rw-r--r--shellrc.d/sway19
-rw-r--r--shellrc.d/xorg14
7 files changed, 141 insertions, 2 deletions
diff --git a/shellrc.d/alias b/shellrc.d/alias
index f9a60e4..f237db5 100644
--- a/shellrc.d/alias
+++ b/shellrc.d/alias
@@ -24,3 +24,7 @@ if pidof systemd >/dev/null 2>/dev/null; then
alias jrn='journalctl'
alias ujrn='jrn --user'
fi
+
+if command -v sdcv 2>/dev/null >&2; then
+ alias sdcv='sdcv -c'
+fi
diff --git a/shellrc.d/desktop b/shellrc.d/desktop
new file mode 100644
index 0000000..f3995d6
--- /dev/null
+++ b/shellrc.d/desktop
@@ -0,0 +1,59 @@
+# vim: ft=sh:
+# This is handy only on desktop and is useless on server
+
+
+# Following section is applicable for any desktop but only for graphics
+# The check is for XOrg but thanks to XWayland it works for Wayland as well.
+[ -z "$DISPLAY" ] && return
+
+alias feh='feh --conversion-timeout 10 -.'
+
+# Clip current HEAD hash to clipboard
+# Optionally you can pass commit as argument
+gitclip() {
+ git rev-parse "${1:-HEAD}"| clip
+}
+# Clip current head message to clipboard
+# Optionally you can pass commit as argument
+gitmclip() {
+ git log --format=%B -n 1 "${1:-HEAD}" | clip
+}
+# NOTE: clip comes either from xorg or sway file
+
+
+# This function should not be called externaly
+# It expects PID of surf instace as first argument and all other arguments should
+# be command to be called before kill is sent.
+__insurf_callback() {
+ local SPID=$1
+ shift
+ "$@"
+ echo "kill $SPID SIGHUP"
+ kill -s SIGHUP "$SPID" || exit 1
+}
+
+# Same as inrun but it opens first argument it founds in surf and then reloads
+# that instance automatically.
+insurf() {
+ (
+ set -e
+ # Run surf
+ surf "$1" &
+ local SPID=$!
+ trap "kill $SPID; trap '' EXIT; exit 0" EXIT INT QUIT TERM ABRT
+ # Insert our callback
+ local ISFIRST=true
+ for ARG in "$@"; do
+ if $ISFIRST; then
+ shift $#
+ ISFIRST=false
+ fi
+ set "$@" "$ARG"
+ if [ "$ARG" = "--" ]; then
+ set "$@" "__insurf_callback" "$SPID"
+ fi
+ done
+ # Run inrun
+ inrun "$@"
+ )
+}
diff --git a/shellrc.d/function b/shellrc.d/function
index 2251726..3035e34 100644
--- a/shellrc.d/function
+++ b/shellrc.d/function
@@ -9,7 +9,7 @@ mcd() {
# Run process in background
tbg() {
mkdir -p /tmp/tbg-log
- nohup "$@" >/dev/null >"/tmp/tbg-log/$0-$(date +%g%m%d%H%M%S%N)" &
+ nohup "$@" >"/tmp/tbg-log/$0-$(date +%g%m%d%H%M%S%N)" &
}
# Generate random password (optionally takes length of password as first argument)
@@ -43,7 +43,7 @@ inrun () {
local tmpfs
tmpfs="$(mktemp --tmpdir inrun.XXXXXXXX)"
trap "rm '\$tmpfs'; trap '' EXIT; exit 0" EXIT INT QUIT TERM ABRT
- while [ $# -gt 0 -a "$1" != "--" ]; do
+ while [ $# -gt 0 ] && [ "$1" != "--" ]; do
echo "$1" >> "$tmpfs"
shift
done
diff --git a/shellrc.d/shortcuts b/shellrc.d/shortcuts
new file mode 100644
index 0000000..93b6283
--- /dev/null
+++ b/shellrc.d/shortcuts
@@ -0,0 +1,20 @@
+# vim: ft=sh:
+# There are desktop specific shortcuts
+
+if [ -d ~/turris ]; then
+ turris() {
+ cd ~/turris/"$1" || return
+ }
+fi
+
+if [ -d ~/projects ]; then
+
+ projects() {
+ cd ~/projects/"$1" || return
+ }
+
+ admin() {
+ projects admin/"$1"
+ }
+
+fi
diff --git a/shellrc.d/ssh b/shellrc.d/ssh
new file mode 100644
index 0000000..e2882c8
--- /dev/null
+++ b/shellrc.d/ssh
@@ -0,0 +1,23 @@
+# vim: ft=sh:
+
+# SSHFS in client mode. In other words it is reverse sshfs mount.
+sshcfs() {
+ local target="$1"
+ local local_dir="$2"
+ local remote_dir="$3"
+ shift 3
+ [[ "$local_dir" = /* ]] || local_dir="$PWD/$local_dir"
+
+ local sftp_server="/usr/lib64/misc/sftp-server"
+ if [ -e /run/current-system/sw/bin/ssh ]; then
+ sftp_server="$(readlink -f /run/current-system/sw/bin/ssh)"
+ sftp_server="${sftp_server%/bin/ssh}/libexec/sftp-server"
+ fi
+
+ ssh "$@" "$target" mkdir -p "$remote_dir"
+ dpipe \
+ "$sftp_server" \
+ = \
+ ssh "$@" "$target" sshfs -o idmap=user -o passive -o allow_other \
+ ":$local_dir" "$remote_dir"
+}
diff --git a/shellrc.d/sway b/shellrc.d/sway
new file mode 100644
index 0000000..4713914
--- /dev/null
+++ b/shellrc.d/sway
@@ -0,0 +1,19 @@
+# vim: ft=sh:
+# These are utility functions loaded when we are running in Sway
+[ "$XDG_CURRENT_DESKTOP" != "sway" ] && return
+
+alias swm='swaymsg'
+
+
+# Clip stdin to clipboard
+clip() {
+ wl-copy --trim-newline
+}
+
+
+sway_outputs() {
+ swaymsg -t get_outputs
+}
+sway_inputs() {
+ swaymsg -t get_inputs
+}
diff --git a/shellrc.d/xorg b/shellrc.d/xorg
new file mode 100644
index 0000000..f55e961
--- /dev/null
+++ b/shellrc.d/xorg
@@ -0,0 +1,14 @@
+# vim: ft=sh:
+# These are utility functions loaded when we are running in Xserver
+
+[ -z "$DISPLAY" ] && return # Ignore if there is no display set
+[ -n "$WAYLAND_DISPLAY" ] && return
+
+alias i='i3-msg'
+
+
+# Clip stdin to clipboard
+clip() {
+ # Note: printf as magic to remove trailing new lines
+ printf %s "$(cat)" | xclip -selection clipboard
+}