Showing posts with label babun. Show all posts
Showing posts with label babun. Show all posts

Scoop: Command Line Application Installer For Windows

While looking through some Rust stuff, I stumbled upon Scoop, a command line application installer for Windows. While there exists package managers for Windows like Chocolatey, Ninite, CoApp, and Babun (a Windows shell for Cygwin), why the needs of another similar tool? Initial impression after setup the tool indicated that Scoop sits between Chocolatey and Babun. It uses PowerShell to manage the console environment and software installation and let you use *nix softwares in Windows environment. Read the wiki for further justification and differences.

Installation is quite straight forward, just open PowerShell and type this command.
iex (new-object net.webclient).downloadstring('https://get.scoop.sh')

Before we proceed with customization, we must set up the permission so that Microsoft Security Essentials won't slow down our downloads and installation of other softwares.
scoop install sudo
sudo Add-MpPreference -ExclusionPath 'C:\Users\foobar\scoop'

Next, we also need to add additional directory list to the tool. You can see the full list of available software in the `default` and `extra` directory. Get the full list of directories if you want to add more bucket.
scoop bucket add extras

Let's proceed with some customization of the PowerShell console. The default contrast was just too glaring and hurt my eyes. Once you've set this up, restart PowerShell and we will get back the regular *nix terminal prompt (~ $) and Solarized colour theme using concfg, a Windows tool that imports or exports console settings.
scoop install pshazz
scoop install concfg
concfg import solarized-dark

Let's install Git then. It seemed that all the built-in GUI tools were installed as well.
scoop install git
Installing 'git' (2.20.1.windows.1) [64bit]
PortableGit-2.20.1-64-bit.7z.exe (40.3 MB) [======================================] 100%
Checking hash of PortableGit-2.20.1-64-bit.7z.exe ... ok.
Extracting dl.7z ... done.
Linking ~\scoop\apps\git\current => ~\scoop\apps\git\2.20.1.windows.1
Creating shim for 'git'.
Creating shim for 'gitk'.
Creating shim for 'git-gui'.
Creating shim for 'tig'.
Creating shim for 'git-bash'.
Creating shortcut for Git Bash (git-bash.exe)
Running post-install script...
'git' (2.20.1.windows.1) was installed successfully!
......

Let's try to install another software, my dear Perl. Instead of Cygwin's version, it installed the Strawberry Perl instead.
scoop install perl
scoop which perl
C:\Users\foobar\scoop\apps\perl\current\perl\bin\perl.exe

What I like about Scoop? For a start, fast console interface, centralized application installation path (everything in `scroop` folder in your home directory), and you don't need to go to each website and download different Windows installer for any softwares you want to install. Any dislikes? Downloading software packages was quite slow compare to downloading through the web browser.

Setting Git with P4merge in Babun

In previous post, we have discussed on setting up Babun in Windows, the next step was to setup a good merging tool to work with Git. Good and free merging tool is essential when resolving conflict during rebasing or merging. There are several good tools but the one we're comfortable with is P4Merge.

If the `p4merge.exe` binary is not found within the Babun shell, then you've to update the environment variable `$PATH` to append to the exact location of the binary. This can be done through Windows' environment path as well. Since we want our Git configuration file `gitconfig` to be portable with minimum tweaking, we can opt to set direct path.

This is where `cygpath` comes in which will convert path between Unix and Windows.

If we want to find the Windows path to our default Babun installation directory.
$ cygpath -w /
C:\Users\foobar\.babun\cygwin

How about the Unix path for `p4merge.exe` binary.
$ cygpath -u "C:\Program Files\Perforce\p4merge.exe"
/cygdrive/c/Program Files/Perforce/p4merge.exe

To make sure Git can find `p4merge.exe` binary from Babun.
$ cygpath -asm "/cygdrive/c/Program Files/Perforce/p4merge.exe"
C:/PROGRA~1/Perforce/p4merge.exe

Next, set `p4merge` our default merge tool and the direct path to its binary.
$ git config --global merge.tool p4merge
$ git config --global mergetool.p4merge.path C:/PROGRA~1/Perforce/p4merge.exe

If you don't like the tab ordering of the merging windows, customize to your liking.
$ git config --global mergetool.p4merge.cmd \
    "C:/PROGRA~1/Perforce/p4merge.exe" $BASE $LOCAL $REMOTE $MERGED

Additionally, `cygpath` also have built-ins options to access default system paths in Windows.
$ cygpath
......
System information:

  -A, --allusers        use `All Users' instead of current user for -D, -O, -P
  -D, --desktop         output `Desktop' directory and exit
  -H, --homeroot        output `Profiles' directory (home root) and exit
  -O, --mydocs          output `My Documents' directory and exit
  -P, --smprograms      output Start Menu `Programs' directory and exit
  -S, --sysdir          output system directory and exit
  -W, --windir          output `Windows' directory and exit
  -F, --folder ID       output special folder with numeric ID and exit

You can access these path directly with Windows Explorer using `cygstart`.
$ cygstart `cygpath -D`

`cygstart` is a tool is used open almost anything. For example, web URL but you must prepend it with `http`.
$ cygstart http://google.com

Development with Docker Toolbox and Babun

For those stuck with or prefer Windows environment, Docker Toolbox is the painless and simplest way to have a consistent development environment using Docker. While we can duplicate the same environment through actual virtualization or Window Subsystem For Linux (WSL), the time taken to configure and setup the environment does not worth the effort. Furthermore, Docker still not quite works for WSL yet.

While the Git Bash for Windows works well for its basic features, a Bash prompt with some *nix utilities, there are still several console apps solely missed like rsync and wget, which will not be bundled together unless you install these separately. Furthermore, you have to waste time to customize the console prompt to your liking (optional).

This is where Babun, a Windows shell over Cygwin, comes in. The sensible default settings provided by  oh-my-zsh with wide range of extensible plugins is good enough without much tweaking.

Babun Docker
Since we're using Docker Toolbox, we also need to make sure it works with Docker Toolbox through Babun Docker.

Go to the Docker QuickStart Terminal and stop the Docker Machine.
$ docker-machine stop default

Open Babun shell and install Babun Docker.
$ curl -s https://raw.githubusercontent.com/tiangolo/babun-docker/master/setup.sh | source /dev/stdin
$ babun-docker-update
$ docker-machine start default

Always load the Docker Machine settings on new opened terminal session.
$ echo "# Docker Machine stuff\n eval \$(docker-machine env default --shell zsh)" >> ~/.zshrc

Zsh and tmux
Next, which is quite crucial for me was to auto load tmux every time Babun or Zsh start.
$ pact install tmux

In your `.zshrc`, enable the tmux plugin and set it to autoload.
# Enable this before the plugin
ZSH_TMUX_AUTOSTART=true

plugins = (git tmux)

The next step is to download my own tmux configuration file and reload the Zsh shell to reflect the changes. You can also close and re-open the Babun shell. There was an issue where the Babun shell cannot start properly due to unknown error. Update your Babun installation (which actually is Cygwin) should fix the issue.
$ wget https://raw.githubusercontent.com/kianmeng/dotfiles/master/.tmux.conf
$ source $HOME/.zshrc

Slowness
Depending on the number of plugins enabled and theme selected, Babun shell can be quite slow. Keep your enabled plugins to a minimum, pick less resource intensive theme, use a Zsh framework to manage these plugins, or optimize Cygwin instead. Nevertheless, one way to check if your shell prompt is slow, run this command.
$ babun check

This Week I Learned - 2016 Week 42

Last week post or the whole series.

Interesting week indeed. It has been a while since I last encountered so many different type of personalities who want or don't want to be a developer.

As usual, what have I learned this week? The usual stuff.

If you're running on GNU/Linux and want a way to manage different Windows OS through Vagrant, you can try this Vagrantfile. Installation and setup is pretty much straightforward, just make sure the Vagrantfile is downloaded. Unfortunately, the login still fail to work.
$ sudo install virtualbox vagrant
$ vagrant plugin install winrm winrm-fs

$ mkdir vagrant_win
$ cd vagrant_win
$ wget https://goo.gl/ATpaEY
$ IE=Win7IE8 vagrant up

Sanic, Python 3.5+ asynchronous web server. The discussion at HN seems rather interesting. While this is nothing new, asynchronous database layer like asyncpg seems rather userful to improve your DB query speed.

Issue with Babun's memory conflict after Windows updates? Try rebasing, not that Git rebasing thought. Cygwin still is the better and prefered choice for Unix experience in Windows. Yes, I know there is Bash on Windows.
1) Exit babun.
2) cmd /c %SYSTEMDRIVE%\Users\%USERNAME%\.babun\cygwin\bin\dash.exe -c '/usr/bin/rebaseall -v'

Customozing HTML's file inputs. Probably the most comprensive guide on different techniques to change the default behavour.

Web framework benchmarks. The Round 10 has one of the best humourous write-up.
The project returns with significant restructuring of the toolset and Travis CI integration. Fierce battles raged between the Compiled Empire and the Dynamic Rebellion and many requests died to bring us this data. Yes, there is some comic relief, but do not fear—the only jar-jars here are Java.
What happens when you rename a branch in Git? Plenty of things. First, you rename it locally. Next, you rename it remotely (is the same as remove the old branch and add a new branch). After that, either you update your upstream URL or checkout a fresh copy of the said new branch. Lastly, you may needs to batch update your commit messages.
$ git branch -m new_name
$ git branch -m old_name new_name
$ git push origin :old_name
$ git push --set-upstream origin new_name
$ git filter-branch -f --msg-filter 'sed "s/foo/bar/"' master..HEAD

The database schema for StackOverflow is publically accessible. I was surprised that it's such a straight forward design and nothing fancy at all. Well, is just a CRUD app with some additional tweaks here and there. However, the ranking formulae is far more interesting when compare to different algorithms used by other popular forum-like sites.

So may ways to iterate through the Perl's array. Implementation 1, 4, and 5 is what I normally used but the 5th method is still my favourite.

Source code syntax higlighter through Javascript? Just found out today, besides highlight.js, there is also Prism.js. The former seems to have more languages support but the later is used for quite a few popular projects.

NBA season going to start soon, maybe is time for me to learn some Statistics through certain API? Can't wait what surprises the 2016/2017 season will give us.

This Week I Learned - 2016 Week 14

Last week post or the whole series.

#1 Replace Git Bash with MinTTY. Even though you can run Bash on Ubuntu in Windows right now, the most acceptable way (without using the dreadful Windows Command line) before this is through Cygwin and MinTTY. Don't like MinTTY? Well you've Babun and MSYS2, both are based on Cygwin. But still, nothing beat a Vagrant emulated environment.

#2 12 years, 12 lessons working at ThoughtWorks. (HN thread, Reddit thread) Some beg to differ. His retrospective team approach, especially the four key questions, should be applied by any software team. Note that ThoughtWorks is both a software house and a consulting firm.

#3 BPF Compiler Collection. Efficient Linux kernel tracing and performance analysis. You can read the docs and try it out. Only for Linux kernel 4.1 and above though. Compliment to the Brendan Gregg's Linux performance material but at different approach.

#4 Brett Victor's bookshelf. Some people are just prolific book reader. I always love his idea of reactive documents, an implementation of his concept of Explorable Explanations.

#5 Startups in MontrĂ©al. E14N is the only one I'm aware of. Anyway, the discussion at HN is far more interesting regarding the place. Language racism is true and alive there, culturally and systematically forced upon you.

#6 Effective code review or faults finding and blames? Why do you need code review in the first place if trivial matter such as coding convention still cannot be properly enforced? Note that there are tools exists to fix most of these issues and is a no-brainer to rectify this (is just a command away). Root cause is still there is lack of healthy culture that values quality but instead more towards faster delivery.  Or maybe because the software industry itself does not promote integrity (Lobsters thread)?  Or maybe we applied the wrong approach?

#7 perlootut - Object-Oriented Programming in Perl Tutorial. Holy Macaroni! I've never realized that Perl's built-in Object-Oriented feature is so limited. In other words, object in Perl is a glorified hashes. Yes, you have to write your own classes from scratch!

#8 How to start gnome-terminal in fullscreen. Nobody bother to add or enable this feature as sensible default and you have to resort to multiple ways to get it to work. While I can understand of reducing the UI clutters (or dumbing down)in GNOME, but nobody actually use the gnome-terminal in fullscreen mode? It seems that GKH also have issue with gnome-terminal itself.