Tahir Hassan's Blog

My Technical Notes

Tuesday, 17 October 2017

PowerShell: Create Email Message with Attachments

A lot of the times, while in PowerShell, you want to email something as an attachment to a colleague without having to open it in Explorer and right-clicking it, and doing `Send to...` → `Mail recipient`. What is needed is a simple function `Email-File` that does this:

Function Email-File([string[]]$Files) {
    $outlook = New-Object -ComObject Outlook.Application;
    $mail = $outlook.CreateItem(0);
    $mail.Subject = 'Email Files';

    $Files | ForEach-Object {


Saturday, 7 October 2017

Installing `adb` (Android Debug Bridge)

To install `adb` you must first download the "Android command line tools" from the Android Studio download page. It is a zip file, not a user friendly installer.

Crate a folder in the root of the `C:\` drive called `android-sdk`, and within it, copy the `tools` folder that is in the zip file.

After that, on the command line, `cd` to the `android-sdk\toosl\bin` folder. Invoke the `sdkmanager.bat` to install the so-called `platform-tools` that contains `adb`:

.\sdkmanager.bat "platform-tools"

After this finishes installing you will have a `platform-tools` folder in the `android-sdk` folder, that contains `adb.exe`. You can simply add this containing folder to the `PATH` environment variable if you wish invoke it from anywhere (or create an "Alias" in PowerShell).

Friday, 6 October 2017

ConEmu redraw problems with Vim

I had the fairly rare (perhaps 2-3 times a day) issue of part of the screen going blank when using Vim inside ConEmu. Apparently, adding this to your `vimrc` file fixes the issue:

set ttyscroll=0

Vim: Loading Fugitive with `Gstatus` opened

I am learning how to use Fugitive, which is a Vim plugin to make it easier to commit to git. I had a use-case where I would be in a directory (while in PowerShell), and I would want to load vim with Fugitive's `Gstatus` run automatically.

In order to do this, I have implemented a simple PowerShell function:

Function vimf {
    vim temp -c 'Gstatus | wincmd j | hide'

It works by calling vim with `temp` as a filename. Because this file name does not exist, all that will happen is that vim will create a swap file for it, but otherwise it will be ignored. `-c` is the command that will be executed once temp is loaded into a buffer. `Gstatus` is called as we wanted to show `git status` output. `wincmd j | hide` will hide the temp buffer.

Wednesday, 4 October 2017

Vim & PowerShell & CTags

Install CTags from the official website. Then define the PowerShell language in `%USERPROFILE%\ctags.cnf`:

--regex-powershell=/^[Ff]unction[\t ]*([a-zA-Z0-9_-]+)/\1/f,function/
--regex-powershell=/^[Ff]ilter[\t ]*([a-zA-Z0-9_-]+)/\1/i,filter/
--regex-powershell=/^[sS]et-[Aa]lias[\t ]*([a-zA-Z0-9_-]+)/\1/a,alias/

After that, run CTags from the command line in the directory you want to generate the CTags for:

ctags -R .

Vim: Using Pathogen

Now using Pathogen to keep plugin files of different plugins in their separate folders.

`:version` tells you where your vim scripts files should be. On Windows, in `~`, you create a `vimfiles` folder, and you place your `vimrc` (no prepending dot or underscore) in this folder.

Friday, 29 September 2017

Vim: Using Control-d to delete a word after Cursor

:imap <C-d> <C-o>dw
  • `imap` will do it for insert mode.
  • `<C-d>` is the shortcut being set-up (Control-d).
  • <C-o> is used in insert mode to perform a single command, after which it will return to insert mode.
  • `dw` deletes a word