macOS

Working with different Git configs

2017-03-10 DSP2017, Git, Linux, macOS No comments

Short introduction

Sometimes people need to specify multiple values for single .gitconfig file or they want to share just part of the configuration between two machines. There are different approaches for that. I can show you mine.

Different configs for different Operating Systems

On my private computer, I use Linux. I use Git for my private projects and I use my private e-mail address there. At the same time, I use Git at work on macOS with exactly the same Git configuration, but with a different e-mail address. How to deal with that?

In my .gitconfig file, I set my private e-mail address, which is used by default. In my .zshrc file, I created two aliases:

alias setupGitPersonal="git config --global user.email \"piotr@wittchen.biz.pl\""
alias setupGitForWork="git config --global user.email \"piotr.wittchen@sap.com\""

Hint: If you want to configure more stuff than just an e-mail, you can do it in the appropriate alias or you can create separate shell scripts for that and place them in /usr/local/bin/ directory.

Then, on Linux, I don’t have to do anything and my private e-mail address is used out-of-the-box.
On macOS, I do the following trick in .zshrc file:

if [ `uname` = "Darwin" ]; then
  setupGitForWork

  # rest of the macOS config goes here...
fi

After that, every time I start terminal on macOS, it automatically sets up my e-mail address to the one I use at work and keeps my .gitconfig file updated.

Hint: If you don’t use zsh, instead of .zshrc file, edit .bashrc file.

Different configs for the same OS on two machines

If you’re using different configs on the different machines with the same OS, you can try another trick. Create configuration file – e.g. .machine_name in your home directory. Setup one name on one machine and another name on a different machine. Next, include this file in your .zshrc or .bashrc file, perform appropriate check and load different settings basing on variable name.

. ~/.machine_name

if [ $machineName = "workMachine" ]; then
  setupGitForWork
else
  setupGitPersonal
fi

Contents of the .machine_name file are simple:

machineName="workMachine"

Different configs on the single machine with one OS

In such case, we are supposed to perform the manual switch. We can use aliases provided above. When we want to have personal settings, we can open terminal and type setupGitPersonal. When we want to apply work settings, then we can type setupGitForWork.

Summary

As we can see, keeping different configs for different machines or operating systems and changing them depending on our needs is not so hard. I hope these ideas will help you to manage your configs.

One year of using Macbook Pro at work as a software developer

2017-01-29 Apple, macOS 3 comments

Introduction

For most of the time, I was MS Windows user. I was using this OS since Windows 95 up to Windows 10 ( the last version really occasionally). About ~3 years ago, I switched to Linux (Ubuntu) on my private computer. I used it before on virtual machine or sometimes in dual boot with Windows. About one year ago, I changed my job and decided to switch to Macbook Pro at work. I also had an option of choosing a laptop with MS Windows, but I was already a bit familiar with Unix, so I decided to learn something new and try Apple stuff. It had OS X El Capitan installed and it was later upgraded to macOS Sierra. I decided to collect my thoughts related to using Macbook in this article.
Below you can see a photo of my current work-station in the office.

In the beginning, it seemed that it’s something different than systems I already used, but it was quite similar to Linux. There’s Unix shell, HUD like in the Unity on Ubuntu. I don’t use Unity on Linux anymore, but I’m familiar with that concept. Settings window also looks similar to Unity or Gnome. Macbook is connected to one monitor via HDMI and to another one via mini-display port. The keyboard is connected via USB and magic mouse is connected wirelessly via Bluetooth. It’s worth mentioning that Macbook doesn’t have RJ45 port, so you need an adapter if you want to be connected to the network via cable. There’s adapter from mini-display port to RJ45 and from USB to RJ45. You can choose one of them. If you need any specific device setup, better check hardware specification, available adapters and their cost.

Configuration as a code

After some time of using Linux, I discovered that I can keep my personal configuration as a code. My config is open-source and you can see it in my dotfiles repo. This is very useful when you want to restore your configuration if you’re installing a system from the scratch or you accidentally lost your data and want to have a backup. Moreover, when you are using two Unix machines like me right now, you can share your configuration between them. On macOS I can use the same stuff like on Linux. E.g. Zsh, Tmux, Vim, etc. Nevertheless, there are differences between Linux and macOS. That’s why in my .zshrc file, I have a separate section for Linux and the separate section for macOS. Moreover, sometimes scripts also need to be customized separately for different systems. Using macOS helped me to make my config more robust and now I can use it easily both on macOS and Linux without huge problems.

Apps

Of course, I needed to find apps, which will be useful for me during daily work and usage of the system. Below you can see what I find useful.

Basics

  • Homebrew – Missing package manager for macOS; it’s obvious thing for Linux systems, but on macOS you need additional software for that.
  • iTerm2 – Terminal emulator with possibility of searching, creating tabs, creating panes horizontally and vertically. It’s better than default Terminal app.
  • Spectacle – An app for resizing and moving windows. On macOS for me it’s very annoying that when you resize the window to the full-screen, it hides top menu (HUD) and dock and jumps into separate workspace. We can solve that problem by installing spectacle and with appropriate shortcuts you can resize window without hiding anything. It has also a few additional features regarding windows resizing. Moreover, it’s good to remember to disable shortcuts, which conflicts with iTerm2 shortcuts for splitting the panes if you are using them like me.

Development Tools

Here are my basics apps I use for development. I also use terminal tools, but I mentioned them earlier in this article. All of them works pretty the same as on other platforms. Docker for Mac was improved so we can use Docker as easy as on Linux right now.

Messengers

We also have basic messengers. It’s no difference comparing the to other systems. Maybe Skype is simpler than Windows version. Linux version of Skype is also quite simple because they probably stopped developing it. It’s strange because it’s good and bad at the same time.

Menu indicators

I like the concept of menu indicators in HUD. It’s similar to Gnome Classic and Gnome 3 desktop environment for Linux.

  • Caffeine. It’s the same as on Linux. It’s an indicator, which prevents screen lock.
  • Menu meters. It’s similar to Linux indicator. You can measure CPU, Memory and network usage.
  • Degrees. It’s an indicator for checking weather and temperature in your city.

Additional apps

There are also a few additional apps I use…

  • Commander One – “Total Commander”-like app for macOS. Total Commander is one of the apps I really miss on non-MS systems, because its replacements are never as good as the original app.
  • Default Mail and Calendar app
  • MS Outlook – the newest version looks much better after update, nevertheless notifications are still not consistent with macOS UI (at least they look a bit better) and closing app means killing it like on Windows, but it’s uncommon behavior for macOS.
  • MS Office apps
  • Evernote
  • Simplenote
  • Wunderlist
  • Spotify

What’s different?

There are things, which are slightly different on macOS and I needed to get used to them during the time.

  • Apps are not closed until you explicitly close them. Apps behaves a bit like on Android. They go to the background and you can wake them up. If you want to kill the app explicitly you have to use Command+Q shortcut or choose “Quit” option from the context menu.
  • Keyboard and shortcuts. The keyboard is different. We have additional Command key, which replaces Windows Key and a few additional keys. System shortcuts are also different. There’s no “Print Screen” key, but there’s a shortcut for that. Moreover, IntelliJ shortcuts are also different than on Windows and Linux, but I learned them during the time without any shortcuts re-mapping like some people do. In my opinion, it’s a better approach than re-mapping, because we have different keyboard and opportunity to train our brain a little bit.
  • Workspaces. This functionality became a standard in the latest versions of OS X and Windows. Nevertheless, it was available on Linux Desktop Environments long time ago.
  • Dividing screen. This is similar to Windows and Linux, but with a few differences. When we divide the screen and share it between two windows, this view goes to a separate workspace without HUD and Dock. I don’t like it. Additionally, we can grab a dividing line and adjust space of one window or another by dragging like in Tmux. This is really cool feature, which is not available on Windows and Linux DEs as far as I know.
  • Head Up Display and Dock. As I mentioned earlier in this article HUD is a concept similar to the Unity DE from Ubuntu, but I suppose Apple was first with that idea. I’m not a fan of Dock. Its functionality is more or less the same as a bottom bar from Windows, but with a bit different UI/UX. It’s hard to say, which one is better.
  • Hiding and showing hidden files. I haven’t found an option of showing hidden files like I can do on Windows or Linux. I had to do a trick and create an alias in my .zshrc file to show and hide hidden files. Commander One app is able to show and hide hidden files via GUI, but it’s third party app.
  • Spotlight. The Spotlight is a useful feature, which you can use for launching apps. You can also use it for other things like searching mail, calendar, places and so on, but I don’t really use these additional things.
  • Siri. Siri is an assistant with voice recognition. It was available on iPhone earlier. In macOS they brought it to the desktop. It’s cool, you can ask it about weather or launch an app with voice command, but I don’t really use it in daily work.

Observations

Here are a few of my observations I made while using Mac.

  • It doesn’t work exactly the same as Linux, but it’s in the same Unix family. We can use nice terminal, Zsh, Vim, Tmux and stuff similar to Linux, but sometimes we need to adjust things to Mac and not all commands, which are valid for Linux are also valid for Mac.
  • It’s more stable than Linux. I don’t remember if I encountered any crashes or problems related to system itself on Mac. Maybe system hanged once or twice in a year.
  • It’s less customizable than Linux. On Mac you cannot change the desktop environment and do a lot of customizations like on Linux. Luckily UI of macOS is nice, although Gnome UI is, in my opinion, a bit more minimalistic, what I actually like.
  • It’s simpler than MS Windows. From my perspective macOS is simpler than MS Windows. In MS Windows they tend to change everything in the successive releases and UI gets more complicated. In macOS they try to keep everything simple and consistent with their standards.
  • Software vendors care about macOS users. Every popular app has an official macOS version (e.g. Evernote, Wunderlist, Photoshop, etc.). You cannot say that about Linux.
  • Almost every dummy app is not free. I’m not against buying software and I use licensed commercial software. Nevertheless, in App Store almost every dummy app for doing one simple thing is paid, what can be annoying especially if you are using Mac at work and don’t want to connect it with your personal payment cards.

Design & Hardware

We can discuss software issues, but there are things, which Apple makes the best and leaves the competition behind.
These things are design & hardware. Macbook’s touchpad is the best touchpad I’ve ever used. It’s smooth easy to use and is integrated with the system in a very convenient way. Page scrolling is really smooth and natural. There are gestures for switching workspaces, scattering windows, zooming, etc. Retina display screen is very clear, has high resolution and it’s much better than displays of the other laptops. Speakers are incredibly clear and music sounds better than in regular laptops. A lot of people complain about the necessity of using adapters. I haven’t really had such problems. The only adapter I needed was USB to RJ45 adapter for a wired network. I could connect one external screen via mini-display port and another one via HDMI port. I think an issue with adapters can be serious for people who use a lot of specific external devices. The battery in the Macbook works fine, but it’s getting worse as long as you’re using a laptop. If you start energy consuming services and apps it can be drained in less than 8 hours now. I think it was better in the beginning of the usage (one year ago). The thing, which I really like in Macbook is the design. It’s very clean & simple. It’s also made from high-quality materials and looks really well. People who care about aesthetics will appreciate that.

Summary

To sum up, I can tell that Macbook is really nice & expensive piece of hardware. I could recommend such device to people, who can afford and want to spend more money than usual on their computer. I would also recommend this device to people who travel a lot and need to work with laptop screen and touchpad because Apple made them better than the competition. I can also recommend this device to people who don’t want to spend too much time on configuration & customization of the software.
I wouldn’t recommend this device to people who want to save money. You can get a laptop with similar specs in about 30% of the Macbook’s price. E.g. Thinkpad device. I also wouldn’t recommend it to people who use external devices quite often. If you are using the external screen, mouse & keyboard lack of Apple touchpad and retina display shouldn’t be a deal-breaker for you. I also wouldn’t recommend it to people who use a lot of specific external devices. In the case of choosing Macbook, probably you’ll need a lot of adapters and some stuff may not work fine for you. In addition, if you like to customize your system, probably you should get a Thinkpad device & install Linux. Moreover, you need to remember that Macbook Pro is not a gaming laptop. In my opinion, macOS is better than Windows for the type of programming I do (recently Java, Bash & Python). Nevertheless, I don’t think it’s better for that than Linux.

As you see, using a Macbook Pro has pros and cons.
You need to remember that choosing of the device should be dictated by logic and pragmatism. Not by marketing and fashion.

Setting up Android Studio on OS X

2016-07-05 Android, Apple, macOS, OS X No comments

Setting up Android Studio on OS X can be tricky. I had a strange problem with tools.jar file and I am not the only one.

After installation of Android Studio, when I started it up, I got an error, which looked like that:

'tools.jar' seems to be not in Android Studio classpath.  
Please ensure JAVA_HOME points to JDK rather than JRE.

jdk_required_screenshot

Luckilly, I fixed this problem and set up Android studio in the following way in my .zshrc file.

If you are not using ZSH, you should set it up in your .bashrc or .bash_profile file.

  # android
  export STUDIO_JDK=/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk
  export ANDROID_HOME=$HOME/Library/Android/sdk
  export PATH=$ANDROID_HOME:$PATH
  export PATH=$ANDROID_HOME/tools:$PATH
  export PATH=$ANDROID_HOME/platform-tools:$PATH
  alias runAndroidStudio="/Applications/Android\ Studio.app/Contents/MacOS/studio"

Please, remember to set your version of JDK. If you have a different version than me, you need to change STUDIO_JDK variable respectively.

Complete source of my .zshrc file can be found here: https://github.com/pwittchen/dotfiles/blob/master/.zshrc

Then, I need to start Android Studio with the following command from terminal:

$ runAndroidStudio

Unfortunately, opening it via Spotlight or from Applications menu doesn’t work properly in my case. If you know, how to fix it, leave a comment below this article!

That’s it! With that setup, I can finally use Android Studio on Mac OS X.