Some useful .bashrc tips

When cleaning up my .bashrc file, I noticed some useful shortcuts that might be useful for others. Here they are:

SSH with .bashrc

Sometimes I need to SSH to a new machine and will need my .bashrc file there. This short function, transfers my local .bashrc file to the remote server and then does the SSH:

function xs() {
if [ "$#" -eq 0 ]; then
    echo "usage: xs user@host other_args"



echo "Setting up remote machine..."
scp $@ ~/.bashrc $host:/tmp/.bashrc_temp > /dev/null

echo "Connecting to $host"
ssh -A -t $@ $host "bash --rcfile /tmp/.bashrc_temp ; rm /tmp/.bashrc_temp"


Alias to invoke Perl debugger and a REPL for running perl code snippets:

alias perld='PERLDB_OPTS="windowSize=20 arrayDepth=300 hashDepth=300 dumpDepth=100" perl -MPerlIO='"'"'via;$DB::deep=9999'"'"' -d $@'
alias repl='PERLDB_OPTS="windowSize=20 arrayDepth=300 hashDepth=300 dumpDepth=5" perl \
-MPerlIO='"'"'via;$DB::deep=9999; \
'"'"' -de0'


This simple function can be piped after an output command and hight a specific keyword. Useful when you are looking for a specific text but want to see the whole context in addition to the keyword:

#highlight the given text in the input (cat log.txt | highlight ERROR)
highlight () {
perl -pe "s/$1/\e[1;31;21m$&\e[0m/g"


Open the last output using vim:

You can use fc -s command to re-execute last command and feed it’s output to vim to open it. This might be useful in cases where you are looking for a file and then want to open it

alias viml='vim $(fc -s)'

Single letter aliases

Due to frequent usage, I have these 3 single-letter aliases:

alias g='git'

alias k='kubectl'

alias d='docker'