Live data from Hacker News

Ask HN: Best things in your bash_profile/aliases?

news.ycombinator.com

231–240 of 288 posts

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

#231
in .bash_functions with PostgreSQL

  $ age NAME YYYY-MM-DD
to get the age of anybody:

  function age () {
     NAME="$1";
     DATE="$2";
     if [[ $1 && $2 ]]; then
         AGE=$(psql -Stc "SELECT age(date('${DATE}'));");
         echo $NAME: $AGE, was born on $DATE | sed 's/ mon / month /' | sed 's/ mons \| mons,/ months /';
     else
         echo "No name or date supplied";
     fi
  }

  function child () {
     age "My child" "2012-03-12";
  }

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

#233

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…

Cool, but on my Mac it makes flashing text..arggh.

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

#234
Convert any video to webm with specified bitrate:

  $ video2webm 300k myvideo.mp4 othervideo.mpg third.mov

  function video2webm () {
     bitrate=$1;
     shift;
     for file in "$@";
     do out=${file%.*}.webm;
        ffmpeg -y -i "$file" -c:v libvpx-vp9 -b:v $bitrate -pass 1 -speed 4 -c:a libopus -f webm /dev/null && \
            ffmpeg -i "$file" -c:v libvpx-vp9 -b:v $bitrate -pass 2 -speed 1 -c:a libopus "$out";
     done;
 }

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

#235
Quickly find messages in your local Maildirs. Full replacement for Google mail and other centralized spying email systems. It uses https://github.com/djcb/mu and mutt https://www.mutt.org in ~/.bash_functions directly from shell, and displays emails

  function search-messages () {
     /usr/local/bin/mu find --clearlinks --format=links --linksdir=~/Maildir/search "$@" && mutt -f ~/Maildir/search
 }

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

#236
I have the below for cases when I have to make a quick screencast. It needs ffmpeg and I am not sure how well the yt flag works as I don't really use Youtube any longer. Anyway.. first I do 'ffsc sc' and if I want that video to be smaller I do 'ffsc yt '.

## Make screencast or convert to yt

ffsc () {

vid_name="$HOME/Videos/Screencasts/screencast_$(date +'%y%m%d-%H%M%S')"

        case $1 in
                sc) ffmpeg -f x11grab -s 1920x1080 -i $DISPLAY -r 30 -f alsa -i default -preset ultrafast \
                    -c:v ffvhuff -c:a flac ${vid_name}.mkv
                    printf "${vid_name}.mkv" | xsel -i

                    echo
                    echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
                    echo "Output file name: ${vid_name}.mkv"
                    echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
                    echo

                    [ -e /tmp/ffsc.tmp ] && { rm /tmp/ffsc.tmp }
                    printf "${vid_name}.mkv" > /tmp/ffsc.tmp
                ;;
                yt) ffmpeg -i $2 -c:v libx264 -crf 18 -preset slow -pix_fmt rgb24 -c:a copy ${2/scr/yt_scr}
                    yt_name=$(cat /tmp/ffsc.tmp)
                    printf "${yt_name/scr/yt_scr}" | xsel -i

                    echo
                    echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
                    echo "Output file name: ${yt_name/scr/yt_scr}"
                    echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
                    echo
                ;;

                mini) ffmpeg -i $2 -strict -2 -s 1680x1050  -r 60 -c:v libx264 -b:v 164 -crf 22 -preset slow \
                      -pix_fmt yuv420p -c:a copy -an ${2/scr/mini_scr}
                      mini_name=${2/scr/mini_scr}
                      ffmpeg -i ${mini_name} -filter:v "setpts=0.5*PTS" -an ${mini_name/.mkv/.mp4}
                      rm ${mini_name}
                    printf "${mini_name/.mkv/.mp4}" | xsel -i

                    echo
                    echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
                    echo "Output file name: ${mini_name/.mkv/.mp4}"
                    echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
                    echo
                ;;
        esac
}

And another nice one I didn't see here..

# Python as a calculator

pc() { python -c "print($*)"; }

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

#237
post #146

Earlier quoted context omitted.

What would the Google Chrome equivalent look like?

chromium --user-data-dir $(mktemp -d)

Aye, learnt this when I wanted selenium profiles with some Dev plugins available but not my main profile.

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

#238
post #45

I lifted most of this from the guy mentioned in the hn post in the comments below. I don't know what shell/platform he used, but it didn't work from twitter so I tweaked it to work on the linux boxes I typically see. It creates a different history file from each shell session. Most of my shell history goes back about 3 years now. The downside is you can't up arrow or crtl R except for your current history, but you ca…

There may be a typo in in this line

export HISTTIMEFROMAT="%d/%m/%Y-%H:%M:%S"

should HISTTIMEFROMAT be HISTTIMEFORMAT ?

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

#239

Earlier quoted context omitted.

(It works, but..) What are all those backslashes for?

I use them to escape the first character of the command name, which has the effect of using the actual command and not an alias. In looking for a link to give you some background I found out that this is limited to interactive shells so those backslashes are just me not understanding what I do.

Ohh I didn't know that. Well...I've aliased a few programs to use a different version than the default, and redefined a few commands, so just prefixing "\" will get the original one. Very handy, thanks!

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

#240
post #115

Earlier quoted context omitted.

I have a similar command, except it keeps the existing addons from my main profile. Which is useful as I need a proxy for different environments for work.

Please share how you did do that, that sounds awesome!

    #!/bin/sh
    PROFILEDIR=`mktemp -p /tmp -d tmp-fx-profile.XXXXXX.d`
    mkdir -p $PROFILEDIR/extensions 
    cd ~/.mozilla/firefox/yvwc47i0.default/
    cp extensions/* $PROFILEDIR/extensions/
    cp addons.json extensions.json $PROFILEDIR/
    cp -R browser-extension-data $PROFILEDIR/
    cp cert_override.txt $PROFILEDIR/
    #cp prefs.js $PROFILEDIR/
    echo 'user_pref("devtools.selfxss.count", 10);' > $PROFILEDIR/prefs.js
    cd -
    firefox -profile $PROFILEDIR -no-remote -new-instance
    rm -rf $PROFILEDIR
Created this as a script somewhere in my path. You'd need to change `cd ~/.mozilla/firefox/yvwc47i0.default/` to match what yours is.
Post reply on HN