diff options
-rw-r--r-- | home/xyz/.bashrc | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/home/xyz/.bashrc b/home/xyz/.bashrc index 31347f31..5adab160 100644 --- a/home/xyz/.bashrc +++ b/home/xyz/.bashrc @@ -43,6 +43,24 @@ for cmd in loop o 'watch -c'; do done unset cmd +# note: the following code pipe to while read will not work, because pipe create subshell +#git -C "$HOME/programs/config_local_arch" branch | awk '{print ($1=="*")?$2:$1}' | grep -v master | while read -r branch; do +# `man bash`: "Each command in a multi-command pipeline, where pipes are created, is executed in a subshell, which is a separate process." +# https://stackoverflow.com/questions/56327528/bash-aliases-set-in-while-loop-not-persisting +# can be tested via $BASHPID, note $$ will not work, because $$ does not show subshell pid +# another way is: echo "$(exec sh -c 'echo "$PPID"')" +# `man bash`: +# > BASHPIP Expands to the process ID of the current bash process. This differs from $$ under certain circumstances, such as subshells that do not require bash to be re-initialized. +# > $ Expands to the process ID of the shell. In a subshell, it expands to the process ID of the current shell, not the subshell. +# https://unix.stackexchange.com/questions/484442/how-can-i-get-the-pid-of-a-subshell +for branch in $(git -C "$HOME/programs/config_local_arch" branch | awk '{print ($1=="*")?$2:$1}' | grep -v master); do + case "$branch" in + master|studio|pp) ;; + *) alias "s$branch"="ssh $branch";; + esac +done +unset branch + # different name alias a=alarm # /dev/ttyACM0 can be in config file, or as environmantal variable, see /usr/share/doc/adafruit-ampy/README.md @@ -77,9 +95,7 @@ alias r='rem -cu+2 -@' # https://askubuntu.com/a/22043 alias s='sudo ' alias sa='ssh-add -l || ssh-add' -alias sca='ssh ca' alias se='sudo -E ' -alias sia='ssh ia' alias sp='ssh pp' alias spd='speedtest; librespeed-cli' alias sst='ssh studio' |