Created
February 6, 2024 22:07
-
-
Save navyxliu/f87355bf8a0524a7e3e4185bf02d421d to your computer and use it in GitHub Desktop.
handy scripts on macOS
This file contains 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
; my handy scripts on MacOS | |
function realpath() { | |
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}" | |
} | |
function jdk_select() { | |
if [ -e $1/bin/java ]; then | |
P=$(realpath $1) | |
export JAVA_HOME=$P | |
export PATH=$JAVA_HOME/bin:$PATH | |
echo "choose $P" | |
java -version | |
else | |
echo "can't find valid jdk!" | |
fi | |
} | |
function jdk_replay() { | |
replay=$1 | |
echo "replay file $replay" | |
shift | |
java -XX:+ReplayCompiles -XX:+ReplayIgnoreInitErrors -XX:ReplayDataFile=$replay $* | |
} | |
function dbg_replay() { | |
replay=$1 | |
shift | |
gdb -x $HOME/hotspot.gdb --args java -XX:+ReplayCompiles -XX:+ReplayIgnoreInitErrors -XX:ReplayDataFile=$replay $* | |
} | |
# | |
# SSH tunneling involves in 3 hosts: local/remote, destination, bastion(aka. the ssh server, the only trusted host). | |
# | |
# Here are 2 handy functions to set up SSH tunnels where destination is the same as bastion. | |
# SSH can map different ports between local and destination. for simplicity, those ports are identical in my functions. | |
# reference: https://linuxize.com/post/how-to-setup-ssh-tunneling/ | |
remote_fwd() { | |
PORT=$1 | |
DEST=$2 | |
ssh -R ${PORT}:localhost:$PORT -N -f $DEST | |
} | |
# Local port forwarding allows you to forward a port on the local (ssh client) machine | |
# to a port on the remote (ssh server) machine, which is then forwarded to a port on | |
# the destination machine. | |
local_fwd() { | |
PORT=$1 | |
DEST=$2 | |
ssh -L ${PORT}:localhost:$PORT -N -f $DEST | |
} | |
alias igv_fwd='remote_fwd 4444 dev' | |
alias http_fwd='local_fwd 8888 dev' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment