Live data from Hacker News

Ask HN: Best things in your bash_profile/aliases?

news.ycombinator.com

221–230 of 288 posts

Re: Ask HN: Best things in your bash_profile/aliases?

#221
This is the function I use to set PATH:

  function path {
    if [[ -d "$1" ]] ; then
      if [[ -z "$PATH" ]] ; then
        export PATH=$1
      else
        export PATH=$PATH:$1
      fi
    fi
  }

  export PATH=''

  path ~/.homebrew/sbin
  path ~/.homebrew/bin
  path /usr/local/sbin
  path /usr/local/bin
  path /usr/sbin
  path /usr/bin
  path /sbin
  path /bin
It simplifies the syntax.

I also like to keep vim swaps/backups/history in a centralized place (.vimrc):

  set directory=~/.vim/swaps      " centralized swaps
  set backupdir=~/.vim/backups    " centralized backups
  set undodir=~/.vim/undo         " centralized undo history
I don't like leaving ~clutter in random folders.

I also like to alias sl to ls :)

  alias sl='ls'
Other than that, the least you have to configure the better.

You can check my dotfiles here: https://github.com/krmbzds/dotfiles

Re: Ask HN: Best things in your bash_profile/aliases?

#222
I have two programs that open Firefox. I also have some other programs, too.

fav

  #!/bin/bash --
  f0() {
    echo 'select moz_bookmarks.title || '"'"' = '"'"' || url from moz_places, moz_bookmarks on moz_places.id = moz_bookmarks.fk where parent = 2;' | sqlite3 /home/user/.mozilla/firefox/twht79zd.default/places.sqlite
  }
  f1() {
    firefox `echo 'select url from moz_places, moz_bookmarks on moz_places.id = moz_bookmarks.fk where moz_bookmarks.title = '"'$1'"';' | sqlite3 /home/user/.mozilla/firefox/twht79zd.default/places.sqlite`
  }
  f$# $1
wikipedia

  #!/bin/bash --
  firefox 'http://en.wikipedia.org/wiki/Special:Search?search='`node -p 'escape(process.argv[1])' "$1"`
(Maybe there is a better way than calling Node.js to escape the URL)

icanhazip

  #!/bin/bash --
  curl 'http://icanhazip.com/'
repeat

  #!/bin/bash --
  X=$1
  shift
  for X in `seq 1 $X`; do "$@"; done

Re: Ask HN: Best things in your bash_profile/aliases?

#223

My favorite new one that I have been using a lot: function cheat() { curl cht.sh/$1 } It queries the cht.sh cheatsheet of various Unix commands. 'cheat tar' prints: # To extract an uncompressed archive: tar -xvf /path/to/foo.tar # To create an uncompressed archive: tar -cvf /path/to/foo.tar /path/to/foo/ # To extract a .gz archive: tar -xzvf /path/to/foo.tgz # To create a .gz archive: tar -czvf /path/to/foo.tgz /path…

This is awesome, I ALWAYS have to google for how to untar an archive (I don't do it often enough to commit to memory) thank you!

There are man pages though, but still I suppose that might be useful to you.

Anyways, the only options for tar that I commonly use are "c", "x", and "t"; I will use other programs for decompression, and for extracting into a directory, will use cd.

Re: Ask HN: Best things in your bash_profile/aliases?

#224
Some of aliases in my bash profile

#Git Aliases alias gc="git checkout" alias gp="git pull" alias gp="git pull --rebase" alias gb="git branch" alias gs="git status" alias gd="git diff" alias gl="git log --oneline" alias gu="git ls-files --others --exclude-standard"

#HDFS Alias alias hls="hdfs dfs -ls" alias hcat="hdfs dfs -cat" alias hrm="hdfs dfs -rm" alias hrmf="hdfs dfs -rm -r -f" alias hmd="hdfs dfs -mkdir"

Re: Ask HN: Best things in your bash_profile/aliases?

#225

Earlier quoted context omitted.

This is awesome, I ALWAYS have to google for how to untar an archive (I don't do it often enough to commit to memory) thank you!

There are man pages though, but still I suppose that might be useful to you. Anyways, the only options for tar that I commonly use are "c", "x", and "t"; I will use other programs for decompression, and for extracting into a directory, will use cd.

If the man pages had useful examples the “cheat sheets” would not be needed. So “duh use man pages” is a wrong and annoying answer in this context.

Re: Ask HN: Best things in your bash_profile/aliases?

#226

I have a bunch of project/location specific environment preparing handles in my .aliases file. Stuff like: alias @projectName="cd $project && alias java='/some/specific/version' && export SOME_VAR=value" or alias @untrustedWifi="tor && torbrowser && set up an SSH tunnel to access mail etc" I can't really share the actual contents, because they depend on a boatload of scripts in my ~/bin dir and they're all pretty spe…

I do this plus set the prompt accordingly to remind me in which state it is

Re: Ask HN: Best things in your bash_profile/aliases?

#227
post #224

Some of aliases in my bash profile #Git Aliases alias gc="git checkout" alias gp="git pull" alias gp="git pull --rebase" alias gb="git branch" alias gs="git status" alias gd="git diff" alias gl="git log --oneline" alias gu="git ls-files --others --exclude-standard" #HDFS Alias alias hls="hdfs dfs -ls" alias hcat="hdfs dfs -cat" alias hrm="hdfs dfs -rm" alias hrmf="hdfs dfs -rm -r -f" alias hmd="hdfs dfs -mkdir"

I also have aliases for git, only I noticed gs starts Ghostscript on places where I don't have these set, so I changed all my git aliases to gg:

  ggs -> git status
  ggco -> git checkout
  ggd -> git diff
  ggap -> git add --patch

Re: Ask HN: Best things in your bash_profile/aliases?

#228
post #3

Since I'm working in git repos the majority of the time, I type these hundreds of times per day: alias s="git status" alias d="git diff" I prefer looking at this stuff in a terminal rather than an IDE. Reducing them to a single character just feels so good. Note: not a git alias like "git s", literally just the single character "s" in Bash itself. And coming in third: alias ..="cd .."

I have one that takes an optional numeric arg for the number of times to repeat. Surprisingly useful, but I still keep meaning to get round to making a nicer interactive one with fzf or something.

   $ alias ..
    ..=up
    $ type -f up
    up () {
        local tmp_path=''
        for i in $(seq 1 ${1:-1})
        do
            tmp_path+='../'
        done
        cd "$tmp_path"
    }

Re: Ask HN: Best things in your bash_profile/aliases?

#229
In ~/.bash_functions

  $ loz QUERY
will give the password from the ~/.passwords flat text database, last password is valid one.

  $ lozinka
will ask for questions and enter it into ~/.passwords

I suggest chattr +a ~/.passwords so that file cannot be deleted, only appended.

  function loz () {
            PASSWORDS=~/.passwords;
            if [[ "$1" ]]; then
                /bin/grep -i --color=auto "$1" $PASSWORDS;
            else
                echo "No query given."
            fi
   }

  function lozinka () {
       passwords=~/.passwords
       echo -n "Hostname:"; read hostname;
       echo -n "Service:"; read service;
       echo -n "Username:"; read username;
     echo -n "Email:"; read email;
     password=$(pwgen -n -n -n -s 20 1)
     echo -n "Password (${password}):"; read password1;
     if [[ $password1 ]]; then
         password=$password1
     fi
     if [[ ( $username || $email ) && $password ]]; then
         line=$(join_by : $hostname $service $username $email $password);
         echo $line >> $passwords;
         tail -n1 $passwords;
     else
         echo "Nothing recorded as there is no username or email";
     fi
   }

Re: Ask HN: Best things in your bash_profile/aliases?

#230
post #84

Not strictly an alias, but autojump has been a huge productivity booster for me. Installing it sets up an alias of `j` which guesses the best directory to cd to based on your cd history. So instead of having to type `cd ~/Projects/someproject` you could just type `j some` and it'll end up there. https://github.com/wting/autojump

There's a static version of this built into bash, btw:

    # allow directory variables
    shopt -s cdable_vars
    
    # set a directory variable
    export some=~/Projects/someproject
You can then say `cd some` from anywhere and end up in `~/Projects/someproject`.
Post reply on HN