Saturday, March 12, 2016

What should go into your .profile?

What's your profile like?

I have always had this issue after a fresh installation of Ubuntu. Bring back all my alias from my previous installations, my custom commands, then my terminal setup, etc. You can always say, why not have a better backup strategy. Sure, it does work that way too. But sometimes I go crazy and try different LINUX flavors too. So just a backup strategy won't help.

What I did was to put in some of those common environment setup into a file so that I can always bring it back wherever needed. Many a occasion my colleagues at office and my friends were curious to know what my profile setup looks like. I will be honest, I have not done all of this myself. Over time, I looked out for solutions for my pain points and to horn my lethargy. 7 years of work, did help me collect a lot of dust. Time to share. Feel free to take a look and use what makes sense to you


 
#  ---------------------------------------------------------------------------
#
#  Description:  This file holds all my BASH configurations and aliases
#
#  Sections:
#  1.   Environment Configuration
#  2.   Make Terminal Better (remapping defaults and adding functionality)
#  3.   File and Folder Management
#
#  ---------------------------------------------------------------------------

#   -------------------------------
#   1.  ENVIRONMENT CONFIGURATION
#   -------------------------------

#   Change Prompt
#   ------------------------------------------------------------
    export PS1="________________________________________________________________________________\n| \w @ \h (\u) \n| => "
    export PS2="| => "

#   Set Paths
#   ------------------------------------------------------------
    export PATH="$PATH:/usr/local/bin/"
    export PATH="/usr/local/git/bin:/sw/bin/:/usr/local/bin:/usr/local/:/usr/local/sbin:/usr/local/mysql/bin:$PATH"

#   Set Default Editor (change 'Nano' to the editor of your choice)
#   ------------------------------------------------------------
    export EDITOR=/usr/bin/nano

#   Set default blocksize for ls, df, du
#   from this: http://hints.macworld.com/comment.php?mode=view&cid=24491
#   ------------------------------------------------------------
    export BLOCKSIZE=1k

#   Add color to terminal
#   (this is all commented out as I use Mac Terminal Profiles)
#   from http://osxdaily.com/2012/02/21/add-color-to-the-terminal-in-mac-os-x/
#   ------------------------------------------------------------
#   export CLICOLOR=1
#   export LSCOLORS=ExFxBxDxCxegedabagacad


#   -----------------------------
#   2.  MAKE TERMINAL BETTER
#   -----------------------------

alias cp='cp -iv'                           # Preferred 'cp' implementation
alias mv='mv -iv'                           # Preferred 'mv' implementation
alias mkdir='mkdir -pv'                     # Preferred 'mkdir' implementation
alias ll='ls -FGlAhp'                       # Preferred 'ls' implementation
alias less='less -FSRXc'                    # Preferred 'less' implementation
cd() { builtin cd "$@"; ll; }               # Always list directory contents upon 'cd'
alias cd..='cd ../'                         # Go back 1 directory level (for fast typers)
alias ..='cd ../'                           # Go back 1 directory level
alias ...='cd ../../'                       # Go back 2 directory levels
alias .3='cd ../../../'                     # Go back 3 directory levels
alias .4='cd ../../../../'                  # Go back 4 directory levels
alias .5='cd ../../../../../'               # Go back 5 directory levels
alias .6='cd ../../../../../../'            # Go back 6 directory levels
alias edit='subl'                           # edit:         Opens any file in sublime editor
#alias f='open -a Finder ./'                 # f:            Opens current directory in MacOS Finder
alias ~="cd ~"                              # ~:            Go Home
alias c='clear'                             # c:            Clear terminal display
alias which='type -all'                     # which:        Find executables
alias path='echo -e ${PATH//:/\\n}'         # path:         Echo all executable Paths
alias show_options='shopt'                  # Show_options: display bash options settings
alias fix_stty='stty sane'                  # fix_stty:     Restore terminal settings when screwed up
alias cic='set completion-ignore-case On'   # cic:          Make tab-completion case-insensitive
mcd () { mkdir -p "$1" && cd "$1"; }        # mcd:          Makes new Dir and jumps inside

#   lr:  Full Recursive Directory Listing
#   ------------------------------------------
alias lr='ls -R | grep ":$" | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/   /'\'' -e '\''s/-/|/'\'' | less'

#   mans:   Search manpage given in agument '1' for term given in argument '2' (case insensitive)
#           displays paginated result with colored search terms and two lines surrounding each hit.             Example: mans mplayer codec
#   --------------------------------------------------------------------
    mans () {
        man $1 | grep -iC2 --color=always $2 | less
    }

#   showa: to remind yourself of an alias (given some part of it)
#   ------------------------------------------------------------
    showa () { /usr/bin/grep --color=always -i -a1 $@ ~/Library/init/bash/aliases.bash | grep -v '^\s*$' | less -FSRXc ; }


#   -------------------------------
#   3.  FILE AND FOLDER MANAGEMENT
#   -------------------------------

zipf () { zip -r "$1".zip "$1" ; }          # zipf:         To create a ZIP archive of a folder
alias numFiles='echo $(ls -1 | wc -l)'      # numFiles:     Count of non-hidden files in current dir
alias make1mb='mkfile 1m ./1MB.dat'         # make1mb:      Creates a file of 1mb size (all zeros)
alias make5mb='mkfile 5m ./5MB.dat'         # make5mb:      Creates a file of 5mb size (all zeros)
alias make10mb='mkfile 10m ./10MB.dat'      # make10mb:     Creates a file of 10mb size (all zeros)

#   cdf:  'Cd's to frontmost window of MacOS Finder
#   ------------------------------------------------------
    cdf () {
        currFolderPath=$( /usr/bin/osascript <

Feel free to share your thoughts and additions to these.

Now comes one of the more difficult questions. There are so many places where you can have these. Should I add these in .bashrc, .profile, .bash_profile. Of course, if you have other shells, there can be variations of the same too. To answer this question, we may have to go to the fundamentals and roots of how LINUX works

The main difference with shell config files is that some are only read by "login" shells (eg. when you login from another host, or login at the text console of a local unix machine). These are the ones called, say, .login or .profile or .zlogin (depending on which shell you're using)

Then you have config files that are read by "interactive" shells (as in, ones connected to a terminal (or pseudo-terminal in the case of, say, a terminal emulator running under a windowing system). these are the ones with names like .bashrc, .tcshrc, .zshrc, etc.

.bashrc is only read by a shell that's both interactive and non-login.

.profile is simply the login script filename originally used by /bin/sh. bash, being generally backwards-compatible with /bin/sh, will read .profile if one exists.

If you do man bash, here's what you are going to see, which explains a lot more

 
/bin/bash
       The bash executable
/etc/profile
       The systemwide initialization file, executed for login shells
~/.bash_profile
       The personal initialization file, executed for login shells
~/.bashrc
       The individual per-interactive-shell startup file
~/.bash_logout
       The individual login shell cleanup file, executed when a login shell exits
~/.inputrc
       Individual readline initialization file


What you need to do after you install Ubuntu


What you need to do on a fresh installation of Ubuntu

First and foremost, here's what you want to do if you install any version of debian OS
sudo apt-get update && sudo apt-get upgrade

Most of what I have is common to all of the debian system. I am not sure if arc-theme is available for Mint. I guess, its more specific for Ubuntu. I can check on the same and get back to you folks, if the behavior is any different

I have gone through a lot of websites to collect this information, some of which are my own. Every time I do a fresh installation of LINUX, I have to go over this laborious process of installing these one after the other. Being the programmer I am (and you are), I am sure you agree with the fact, we all hate mundane repetitive activities. Hence I came up with a easier manual that will help me set things up in 3 or 4 steps. May be soon enough, I'll create this as an application and have it as a single step installation.. For the moment, though these following applications will be installed


  1. Oracle Java 
  2. eclipse 
  3. vlc 
  4. node 
  5. npm 
  6. git 
  7. git-flow 
  8. git-cola 
  9. vim 
  10. ssh 
  11. clementine 
  12. unity-tweak-tool 
  13. gnome-tweak-tool 
  14. ubuntu-make 
  15. virtualbox 
  16. arc-theme 
  17. gcolor2
  18. SWIFT 2.2
  19. MongoDB


Add the following PPA, if you want to install Oracle JAVA

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update

Install NodeJS

curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -

Install Brackets from Adobe

sudo add-apt-repository ppa:webupd8team/brackets
sudo apt-get update

To install umake that will help you install AndroidStudio, Webstorm through umake command

sudo add-apt-repository ppa:ubuntu-desktop/ubuntu-make
sudo apt-get update

To install arc-theme, please add this repository(Check the version number before you install)

wget http://download.opensuse.org/repositories/home:Horst3180/xUbuntu_15.10/Release.key
sudo apt-key add - < Release.key

sudo sh -c "echo 'deb http://download.opensuse.org/repositories/home:/Horst3180/xUbuntu_15.10/ /' >> /etc/apt/sources.list.d/arc-theme.list"
sudo apt-get update

sudo apt-get install -y sublime-text-installer nodejs oracle-java9-installer eclipse vlc git git-flow git-cola vim ssh clementine unity-tweak-tool gnome-tweak-tool ubuntu-make virtualbox arc-theme gcolor2 lib32z1 lib32ncurses5 lib32stdc++6 clang libicu-dev mongodb brackets

Installing Wireshark

sudo apt-get install -y wireshark nmap
sudo usermod -a -G wireshark YOUR_USER_NAME
sudo chgrp wireshark /usr/bin/dumpcap
sudo chmod 750 /usr/bin/dumpcap
sudo setcap cap_net_raw,cap_net_admin=eip /usr/bin/dumpcap
sudo getcap /usr/bin/dumpcap

Why arc-theme?

Arc-Theme is the best theme out there for Ubuntu. It provides a great lot of theme collections that you can choose from in addition to what Ubuntu does. From the time I tried it, I have never looked back. I am sure, the experience will be the same for you too.

How to remove a PPA you added

sudo add-apt-repository --remove ppa:webupd8team/brackets

How to remove applications you installed

sudo apt-get remove brackets

Why Ubuntu make?

umake, makes it easy for you to install some of other developer applications for your day time job like Androidstudio, webstorm, pycharm.....with a single command.



umake android
umake swift
umake go
umake ide webstorm
umake ide pycharm
umake ide visual-studio-code
umake ide sublime-text
umake ide atom

Refer to https://wiki.ubuntu.com/ubuntu-make for more information

Why Oracle Java ?

With Android 6 getting a lot of support on Java8, I think it makes sense for us to adopt Oracle's Java8. It's less buggy, more secure and if there are vulnearabilities Oracle has been fast enough to respond on them. I have nothing against Open JDK. feel free to use that, if you have a strong opinion on it.

Check to see if MongoDB is installed fine


sudo service mongodb start

You should hear back that the service is started and running correctly on port (usually) 15251. In some cases you don't get to hear back. You are still fine.


 
krishnan@ubuntukrishnan:~$ sudo service mongodb start
krishnan@ubuntukrishnan:~$ mongo
MongoDB shell version: 2.6.10
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
    http://docs.mongodb.org/
Questions? Try the support group
    http://groups.google.com/group/mongodb-user
> show dbs
admin  (empty)
local  0.078GB
> exit
bye

In addition to developers requirements, there's plenty of essentials to turn your Ubuntu into a full-fledged system fo all practical purposes - From email system to video editing

Peek - Video Editor
sudo add-apt-repository ppa:peek-developers/stable
sudo apt-get update
sudo apt-get install -y peek

Nylas mail client
ThunderBird and evolution has long been the best mail client. Here's a new entrant that will make other mail clinet myopic

Few more


  • A simple weather indicator 
  • Hiri a simple client for MS products
  • GitBook Editor Perfect to get started with writing a book in Git
  • Google desktop Music player - A common music player between your android device and desktop. Share your audio, video, purchases all from one app
  • OpenPics - Building a web application or a photo collection album needs perfection. You need professional tools to shape your picture the way it needs to be before you publish it to the market. OpenPics is a great open source tool that can help you in the ride


Stacer

wget https://github.com/oguzhaninan/Stacer/releases/download/v1.0.4/Stacer_1.0.4_amd64.deb
sudo dpkg --install Stacer_1.0.4_amd64.deb


Gdebi package installer - Alternative to software center

sudo apt-get install gdebi

Install Snapd

There are not that many video editors that can be as good as Snapd.
sudo apt install snapd


Adobe flash-plugin is not something you want in your laptop. They are power hungry and cause lot of crashes. But if you still need them, here you go

  1. Open Software & Updates
  2. Switch to ‘Other Software‘ tab
  3. Click/check the ‘Canonical Partners’  repository
  4. Refresh your software sources when prompted.

sudo apt install adobe-flashplugin