Last active
November 13, 2020 15:15
-
-
Save Voronenko/1eb8d9da0b0385d19eaf684764a3091b to your computer and use it in GitHub Desktop.
Quite funny shell selection one liner - from best to ugly
This file contains hidden or 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
sh -c zsh; if [ "$?" -eq "127" ]; then bash; if [ "$?" -eq "127" ]; then ash; if [ "$?" -eq "127" ]; then sh; fi; fi; fi |
This file contains hidden or 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
de () { | |
__docker_pre_test | |
if [ $? -eq 0 ] | |
then | |
local name=$(docker ps --format '{{.Names}}' | fzf) | |
if [ ! -z "$name" ] | |
then | |
local command="$1" | |
if [ -z "$command" ] && [ -f "$HOME/.docker-fuzzy-search-exec" ] | |
then | |
command=$($HOME/.docker-fuzzy-search-exec "$name") | |
fi | |
if [ -z "$command" ] | |
then | |
local imageName=$(docker inspect --format '{{.Config.Image}}' $name | sed -e 's/:.*$//g') | |
case "$imageName" in | |
("mysql" | "bitnami/mysql" | "mysql/mysql-server" | "percona" | centos/mysql*) command='mysql -uroot -p$MYSQL_ROOT_PASSWORD' ;; | |
("mongo" | "circleci/mongo") command='if [ -z "$MONGO_INITDB_ROOT_USERNAME" ]; then mongo; else mongo -u "$MONGO_INITDB_ROOT_USERNAME" -p "$MONGO_INITDB_ROOT_PASSWORD"; fi' ;; | |
("bitnami/mongodb") command='if [ -z "$MONGODB_USERNAME" ]; then mongo; else mongo -u "$MONGODB_USERNAME" -p "$MONGODB_PASSWORD" "$MONGODB_DATABASE"; fi' ;; | |
(centos/mongodb*) command='mongo -u "admin" -p "$MONGODB_ADMIN_PASSWORD" --authenticationDatabase admin' ;; | |
("redis" | "circleci/redis" | "bitnami/redis" | centos/redis*) command='echo -n "Enter DB Number to connect to (^[1-9][0-9]?$): " && read dbNum && redis-cli -n $dbNum' | |
if [[ "$imageName" == "bitnami/redis" ]] || [[ "$imageName" == "centos/redis"* ]] | |
then | |
command="if [ -z \$REDIS_PASSWORD ]; then $command; else $command -a \"\$REDIS_PASSWORD\"; fi" | |
fi ;; | |
(*) command='sh' | |
command=" ash; if [ \"\$?\" -eq \"127\" ]; then $command; fi" | |
command="bash; if [ \"\$?\" -eq \"127\" ]; then $command; fi" | |
command=" zsh; if [ \"\$?\" -eq \"127\" ]; then $command; fi" ;; | |
esac | |
command="sh -c '$command'" | |
fi | |
eval "docker exec -it $name $command" | |
fi | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment