Git Product home page Git Product logo

my-utilities's Introduction

Useful Tools

Alias

## Switch Context and Namespace
alias set_context="source ~/.kube/set_context_v2.sh"
alias set_namespace="source ~/.kube/set_namespace_v2.sh"

## Shorthand
alias kubectl="kubectl "
complete -o default -F __start_kubectl k

Gnome extension

Gnome-Extension

Useful commands

  • Area screenshot and send to system clipboard

        gnome-screenshot -acf /tmp/tmp.png
    
  • Switch multi version of a program

        update-alternatives --config java
    
  • Remove empty dirs

    find . -empty -type d -delete
    

Modify terminal behavior

  • Show git branch and k8s context and namespace optionally:

    parse_git_branch() {
        git -C ./ rev-parse 2>/dev/null;
        IS_GIT_REPO=$?;
    
        if [[ $IS_GIT_REPO -eq 0 ]]
        then
            BRANCH="git-[$(git symbolic-ref HEAD --short)]"
            echo $BRANCH 2> /dev/null | sed -e 's/^/ /'
        fi
    }
    
    get_k8s_info() {
        if [[ "$ENABLE_K8S_INFO" = true ]]
        then 
            config_name=$(kubectl config view --minify -o jsonpath='{.current-context}')
            namespace_name=$(kubectl config view --minify -o jsonpath='{..namespace}')
            all_info="k8s-[${config_name}|${namespace_name}]"
            echo $all_info 2> /dev/null | sed -e 's/^/ /'
        fi
    }
    
    get_k8s_info_v2() {
        if [ -n "$K8S_CONTEXT" ] && [ -n "K8S_NAMESPACE" ]
        then
            all_info="k8s-[${K8S_CONTEXT}|${K8S_NAMESPACE}]"
            echo $all_info 2> /dev/null | sed -e 's/^/ /'
        fi
    }
    
    if [ -n "$force_color_prompt" ]; then
        if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
        # We have color support; assume it's compliant with Ecma-48
        # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
        # a case would tend to support setf rather than setaf.)
        color_prompt=yes
        else
        color_prompt=
        fi
    fi
    
    if [ "$color_prompt" = yes ]; then
        PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;32m\]$(parse_git_branch)$(get_k8s_info_v2)\[\033[00m\]\$ '
    else
        PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)$(get_k8s_info)\$ '
    fi
    unset color_prompt force_color_prompt
    
  • Shorten terminal path

    PROMPT_DIRTRIM=2
    
  • Cycling autocompletion

    bind 'TAB:menu-complete'
    bind '"\e[Z":menu-complete-backward'
    

my-utilities's People

Contributors

tbog357 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.