Keep only last n commits--
git fetch --depth=<n-1> . <branch>
abs_path(){ | |
# Transforms any path, including windows paths, given as parameter, to absolute path. | |
# Expands ~, ~-, \ etc. | |
# Exitcode: 0 (output to stdout) if path exists, 1 (outout to stderr) otherwise. | |
local path="${1}" | |
# Windows to Unix path [if operand is Unix path, then wslpath outputs to stderr] | |
local buffer=$(wslpath -u "${path}" 2>/dev/null); path="${buffer:-"${path}"}" | |
eval path="${path}" # Remove backslash, Tilde expansion etc. | |
[[ "${path}" != /* ]] && path="${PWD}/${path}" |
The readline prompt [read -p] is sent to stderr | |
The prompt for interactive bash is also sent to stderr. See POSIX mandate below | |
Source : https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html | |
PS1 :: Each time an interactive shell is ready to read a command, the value of this | |
variable shall be subjected to parameter expansion and written to standard error. | |
NOTE (source- Bash reference manual): |
# This function dumps the input stream to the path given as parameter. | |
# If PATH gets unlinked by another (cooperative) process, it creates a new file at PATH and continues dump | |
# Provide a lockfile as the 2nd positional parameter. This is needed so that another process doesn't remove PATH | |
# when it is being written to. | |
stream_dump(){ | |
declare -x path="${1}" | |
local lock="${2}" | |
local timeout="1" # Interval for polling $path | |
declare -x line |
# First run the following 2 lines in your interactive bash attached to a controlling terminal | |
export bashpidfile="/tmp/bashpid" # File that stores the bash pid | |
export PROMPT_COMMAND='echo $$ > $bashpidfile' # Or, replace $$ with $BASHPID | |
# From another terminal do the following | |
### TPGID gives fg proc group on the tty the process is connected to, or -1 if the process is not connected to a tty | |
fgpg=$(ps --pid $(awk NR==1 $bashpidfile) -o tpgid=) | |
# Send signal SIG to all foreground processes to emulate user Ctrl- inputs | |
# Ctrl-C: INT, Ctrl-Z: TSTP, Ctrl-\: QUIT |
### Source me | |
readline_cword(){ | |
# Gives current word of Bash readline, viz. the word where the insertion point/cursor is currently at | |
set -- ${READLINE_LINE} | |
local length=${#1} | |
while ((length < READLINE_POINT)); do | |
shift | |
length+=${#1} | |
done | |
echo -n "${1}" |
Useful for accessing a computer that does not have a public IP address, over the internet. The machine can be behind multiple firewalls and NATs.
Sign-up (email is not verified!)
./ngrok authtoken
Push based workflow is more efficient than repeated pulls (polling). Thankfully, there is currently a free service for the same which is easy to use : https://streambin.pbedat.de/. There is also emitter.io and free, public MQTT brokers such as broker.hivemq.com (list).
Create a unique channel-key - it may be the hash of your email id or the hash of your MAC address, or may even be the fingerprint of freshly generated private-public keypair.
url="https://streambin.pbedat.de/streams/${channel_key}"
while num=$(read -re -p "type: "|& tee /dev/tty|fold -w "$(tput cols)"|wc -l); do tput cuu $num;tput ed; done |