Created
January 20, 2023 15:24
-
-
Save bravosierrasierra/61924eea742ca01752882a16c6267d15 to your computer and use it in GitHub Desktop.
vterm snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun bss/send-to-vterm (str) | |
(interactive) | |
(let* ((inhibit-read-only t)) | |
(vterm-send-string str nil))) | |
(defhydra hydra-term-snippets (:hint nil :exit nil) | |
" | |
Insert snippets: | |
_a_liases | |
._b_ashrc + .bash_local | |
._t_mux.conf | |
._v_imrc | |
_s_cript template | |
_p_sql prompt with date | |
" | |
("a" (bss/send-to-vterm " | |
alias ldf='df -lh|grep -vE \"/run\|overlay\|shm\|tmpfs\"' | |
alias ll=\"ls -lah --group-directories-first --color\" | |
alias nocomment=\"sed -r '/^\\s*#/d; /^\s*\\$/d'\" | |
alias mydu=\"du -hS * | sort -rh | head -50\" | |
alias mydu2=\"ls -1 |xargs -L 1 -I {} du -skh {}|sort -h\" | |
alias drc='docker image prune -a --filter \"until=24h\" --force' | |
alias dr='docker' | |
alias dc='docker-compose' | |
function base64pack { cat $1 | gzip -f9|base64|sed -r 's/$/NLNLNLNL/g'|tr -d '\n'; } | |
function base64unpack { sed -r 's/NLNLNLNL/\n/g' | base64 -d | gunzip; } | |
# base64pack <file> |base64unpack | |
# copy with netcat. | |
# dest: nc -l 1234 > plugins_test.tar.gz | |
# source: nc -w 3 192.168.1.1 1234 < plugins_test.tar.gz | |
# archive with netcat | |
# source: nc -l 1234 >uploads.tar.bz2 | |
# destination: tar -cvjpf - /data/media/uploads| nc -w 3 192.168.1.1 1234 | |
")) | |
("b" (bss/send-to-vterm " | |
cat <<EOF >.bash_profile | |
export EDITOR=vim | |
export HISTCONTROL=ignoreboth:erasedups | |
export PROMPT_DIRTRIM=2 | |
function base64pack { cat \\$1 | gzip -f9|base64|sed -r 's/\\$/NLNLNLNL/g'|tr -d '\\n'; } | |
function base64unpack { sed -r 's/NLNLNLNL/\\n/g' | base64 -d | gunzip; } | |
alias ldf='df -lh|grep -vE \"/run\|overlay\|shm\|tmpfs\"' | |
alias ll=\"ls -lah --group-directories-first --color\" | |
alias nocomment=\"sed -r '/^\\s*#/d; /^\s*\\$/d'\" | |
alias mydu=\"du -hS * | sort -rh | head -50\" | |
alias dr='docker' | |
alias dc='docker-compose' | |
alias drc='docker image prune -a --filter \"until=24h\" --force' | |
# export a=username && echo \"\\$a ALL=(ALL) NOPASSWD:ALL\" >> /etc/sudoers.d/\\$a ; chmod 0440 /etc/sudoers.d/\\$a ; chmod 0770 /etc/sudoers.d | |
export PS1=\"\\u@\\h \\w \"'\\$( [[ \\${EUID} == 0 ]] && echo \"#\" || echo \"\\\\$\" ) ' | |
export PATH=\"\\${PATH}:/usr/local/bin\" | |
if [[ \"\\${INSIDE_EMACS}\" =~ 'vterm' ]]; then | |
function vterm_printf(){ | |
if [ -n \"\\${TMUX}\" ]; then | |
printf \"\\ePtmux;\\e\\e]%s\\007\\e\\\\\\\" \"\\$1\" | |
elif [ \"\\${TERM%%-*}\" == \"screen\" ]; then | |
printf \"\\eP\\e]%s\\007\\e\\\\\\\" \"\\$1\" | |
else | |
printf \"\\e]%s\\e\\\\\\\" \"\\$1\" | |
fi | |
} | |
function clear(){ | |
vterm_printf \"51;Evterm-clear-scrollback\"; | |
tput clear; | |
} | |
PROMPT_COMMAND='echo -ne \"\\033]0;\\h:\\w\\007\"' | |
function vterm_prompt_end(){ | |
vterm_printf \"51;A\\$(whoami)@\\$(hostname):\\$(pwd)\" | |
} | |
export PS1=\\$PS1'\\$( if [[ \\${EUID} != 0 ]] ; then echo -n \"\\[\" ; vterm_prompt_end ; echo -n \"\\]\" ; fi )' | |
fi | |
[[ -f ~/.bash_local ]] && source ~/.bash_local | |
EOF | |
rm -f .profile | |
ln -s .bash_profile .profile | |
rm -f .bashrc | |
ln -s .bash_profile .bashrc | |
")) | |
("s" (bss/send-to-vterm " | |
#!/usr/bin/env bash | |
set -Eeuo pipefail | |
[[ ! -z \"${DEBUG:-}\" ]] && set -x || true | |
")) | |
;; https://www.postgresql.org/docs/current/app-psql.html#APP-PSQL-PROMPTING | |
("p" (bss/send-to-vterm "\\set PROMPT1 '%`date \"+%Y/%m/%d %H:%M\"` %[%033[1;33;40m%]%n@%/%R%[%033[0m%]%# ' | |
")) | |
("t" (bss/send-to-vterm " | |
cat <<EOF >.tmux.conf | |
set -g prefix C-a | |
bind-key a send-prefix | |
bind h split-window -h | |
bind v split-window -v | |
# set -g mouse on | |
set -g mode-mouse on | |
set -g mouse-resize-pane on | |
set -g mouse-select-pane on | |
set -g mouse-select-window on | |
set -g base-index 1 | |
set -g history-limit 20000 | |
set -g set-titles off | |
set -g allow-rename off | |
set-window-option -g automatic-rename off | |
EOF | |
")) | |
("v" (bss/send-to-vterm " | |
cat <<EOF >.vimrc | |
set sw=2 et paste ai si ts=2 sts=2 ic | |
colorscheme desert | |
\" set mouse=a | |
set nocompatible | |
set ignorecase | |
map j gj | |
map k gk | |
set wrap | |
set linebreak | |
set textwidth=0 | |
set wrapmargin=0 | |
map <f2> <esc>:w!<cr> | |
map <f3> <esc>V | |
map <f10> <esc>:qa!<cr> | |
EOF | |
")) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment