Cool bash hack(s)

  1. This hack ensures that when you log on to a server/pc it will execute a screen session which minimizes the risks of you losing your work in case of network disruptions . Just copy command to your bashrc file and source it.
    #Best used when you have to work on a different server via ssh.

    if [ "$TERM" != "screen" ]; then
      screen -xRR
  2. This hack enables mouse scrolling and scrollbar history scrolling. Just copy command to your ~/.screenrc file and restart your shell.
    # Enable mouse scrolling and scroll bar history scrolling
    defscrollback 5000
    termcapinfo xterm* ti@:te@
  3. Ever gotten to a point where, you can’t remember a certain command you executed and when you try to grep it from history it suddenly disappeared well, this hack fixes that. Copy and paste following codes to ~/.bashrc and source it.
    It creates a file named ‘command_log’ and logs all executed commands as well as timestamp. Nifty!! very Nifty

    # log every command typed and when
    if [ -n "${BASH_VERSION}" ]; then
        trap "caller >/dev/null || \
    printf '%s\\n' \"\$(date '+%Y-%m-%dT%H:%M:%S%z')\
     \$(tty) \${BASH_COMMAND}\" 2>/dev/null >>~/.command_log" DEBUG

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s