Skip to content

Instantly share code, notes, and snippets.

@ranraj
Last active April 13, 2021 18:54
Show Gist options
  • Save ranraj/fb8360d7b3c6b479dca123f04546395c to your computer and use it in GitHub Desktop.
Save ranraj/fb8360d7b3c6b479dca123f04546395c to your computer and use it in GitHub Desktop.
linux

Beautify XML from the curl out

curl --location --request GET 'localhost:8080/health/check' | xmllint --format -

Beautify Json from the

curl --location --request GET 'localhost:8080/health/check' | python -m json.tool

Find the PID of the running port & kill the process by PID

sudo lsof -i tcp:8080
kill -9 <PID>

switch shell

chsh -s /usr/local/bin/fish

or

chsh -s `which fish`

Add alias by cat

echo "alias projects='cd $PWD'" | cat >> ~/.bash_profile

remove files

find . -type f -mtime +30 -name '*' -execdir rm -- '{}' \;

Java insalled directory in MAC

/usr/local/opt/java/libexec/openjdk.jdk/Contents/Home/lib

get authorization

curl -v --user YYYY:XXXX https://engci-maven-master.cisco.com/artifactory/webex-cca-group 2>&1 | grep Authorization

I am using similar one to Pavel's script, but I am also reusing aliases.

Place this into ~/.config/fish/config.fish and then restart your terminal.

REUSE ALIASES FROM ~/.bash_profile

        set var (echo $e | sed -E "s/^alias ([A-Za-z0-9_-]+)=(.*)\$/\1/")
        set value (echo $e | sed -E "s/^alias ([A-Za-z0-9_-]+)=(.*)\$/\2/")

        # remove surrounding quotes if existing
        set value (echo $value | sed -E "s/^\"(.*)\"\$/\1/")

    # evaluate variables. we can use eval because we most likely just used "$var"
        set value (eval echo $value)

    # set an alias
    alias $var="$value"
end

# REUSE ENVIRONMENT VARIABLES FROM ~/.bash_profile
egrep "^export " ~/.bash_profile | while read e
    set var (echo $e | sed -E "s/^export ([A-Z0-9_]+)=(.*)\$/\1/")
    set value (echo $e | sed -E "s/^export ([A-Z0-9_]+)=(.*)\$/\2/")

    # remove surrounding quotes if existing
    set value (echo $value | sed -E "s/^\"(.*)\"\$/\1/")

    if test $var = "PATH"
        # replace ":" by spaces. this is how PATH looks for Fish
        set value (echo $value | sed -E "s/:/ /g")

        # use eval because we need to expand the value
        eval set -xg $var $value

        continue
    end

    # evaluate variables. we can use eval because we most likely just used "$var"
    set value (eval echo $value)

    #echo "set -xg '$var' '$value' (via '$e')"

    switch $value
            case '`*`';
            # executable
            set NO_QUOTES (echo $value | sed -E "s/^\`(.*)\`\$/\1/")
            set -x $var (eval $NO_QUOTES)
        case '*'
            # default
            set -xg $var $value
        end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment