Last active
January 8, 2020 19:20
-
-
Save marceloxp/c39fea5bcc100e332132565a1f4a2297 to your computer and use it in GitHub Desktop.
.bashrc to Docker containers
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
#!/bin/bash | |
xp_true="true" | |
xp_false="false" | |
# String routines | |
xp_str_empty() | |
{ | |
[[ -z "$1" ]] | |
} | |
xp_str_not_empty() | |
{ | |
[[ -n "$1" ]] | |
} | |
xp_str_random() | |
{ | |
local result=$RANDOM$RANDOM$RANDOM$RANDOM | |
echo $result | |
} | |
# Folder routines | |
xls() | |
{ | |
if ( xp_str_empty $1 ) | |
then | |
ls -la | |
else | |
ls $1 -la | |
fi | |
} | |
lss() | |
{ | |
if ( xp_str_empty $1 ) | |
then | |
stat -c '%n %a' * | |
else | |
stat -c '%n %a' $1/* | |
fi | |
} | |
# System | |
xp_reloadbash() | |
{ | |
source ~/.bashrc | |
} | |
xp_bashreload() | |
{ | |
source ~/.bashrc | |
} | |
# User routines | |
user_id() | |
{ | |
echo $(id -u ${USER}) | |
} | |
# Add/Remove Hosts | |
#!/bin/sh | |
function removehost() { | |
# PATH TO YOUR HOSTS FILE | |
ETC_HOSTS=/etc/hosts | |
# DEFAULT IP FOR HOSTNAME | |
IP="127.0.0.1" | |
# Hostname to add/remove. | |
HOSTNAME=$1 | |
if [ -n "$(grep $HOSTNAME /etc/hosts)" ] | |
then | |
echo "$HOSTNAME Found in your $ETC_HOSTS, Removing now..."; | |
sudo sed -i".bak" "/$HOSTNAME/d" $ETC_HOSTS | |
else | |
echo "$HOSTNAME was not found in your $ETC_HOSTS"; | |
fi | |
} | |
function addhost() { | |
# PATH TO YOUR HOSTS FILE | |
ETC_HOSTS=/etc/hosts | |
# DEFAULT IP FOR HOSTNAME | |
IP="127.0.0.1" | |
# Hostname to add/remove. | |
HOSTNAME=$1 | |
HOSTS_LINE="$IP\t$HOSTNAME" | |
if [ -n "$(grep $HOSTNAME /etc/hosts)" ] | |
then | |
echo "$HOSTNAME already exists : $(grep $HOSTNAME $ETC_HOSTS)" | |
else | |
echo "Adding $HOSTNAME to your $ETC_HOSTS"; | |
sudo -- sh -c -e "echo '$HOSTS_LINE' >> /etc/hosts"; | |
if [ -n "$(grep $HOSTNAME /etc/hosts)" ] | |
then | |
echo "$HOSTNAME was added succesfully \n $(grep $HOSTNAME /etc/hosts)"; | |
else | |
echo "Failed to Add $HOSTNAME, Try again!"; | |
fi | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment