Ryan Harrison My blog, portfolio and technology related ramblings

Sublime Text 3 SFTP Plugin

Amongst one of the best plugins available for Sublime Text 2 & 3 is the SFTP plugin from wbond (who is known for other great plugins including Alignment, SVN and Package Control itself). The SFTP plugin negates the need for using another dedicated SFTP client such as FileZilla when editing documents on a remote server. From the site, it’s features include:

  • Work off of a server - edit and manipulate files and folders
  • Map a local folder to a remote folder
    • Publish files, folders, or just the changes since your last commit
    • Sync folders - up, down or both directions
    • Diff local vs. remote versions of a file
  • Other operations and options to help you get stuff done
  • Password and SSH key auth with SSH agent support
  • Persistent connections for performance

To install, simply open up Package Control through Ctrl+Shift+P, Select Install Package and select SFTP. You then have to configure the plugin for use on your current project. This is done through the SFTP/FTP context menu on the right click context menu of your root directory. Once configured, a sftp-config.json file will be created. This is where you tell the plugin where to map your local directory to on the remote server. The main changes I make are:

  • Make sure type is SFTP not FTP (we like security)
  • I like to set upload_on_save to true so the most recent copy is pushed to the server whenever I save a file (great timesaver)
  • Change host to point to your remote servers IP/domain
  • Change user to whatever user you have SFTP (SSH) setup for on your server.
  • Change port to whatever port you have SSH running on (you shouldn’t really be running on the default 22)
  • remote_path should point to the directory you want to push changes to on your remote server e.g. /home/<user>/project

Finally, you will want to make sure you are authenticating in some way. You could use a password, but you really should be using public key authentication. As such, change the ssh_key_file property to point to the absolute path to your key file. This caused me some confusion initially as I used the id_rsa OpenSSH key I use for SSH under Cygwin. For *nix systems this should work fine, however on Windows it turns out that Sublime uses PSFTP (PuTTY SFTP) instead, so it expects a PuTTY private key file (.ppk extension). If you get a lot of Connection Refused errors from Sublime and No authentication found errors in the SSH logs, this could be the reason. If all is setup correctly, you should be able to push files to the remote server.

The SFTP/FTP menu also provides some additional options such as Syncing your Remote/Local directories and Browsing your remote. Note that this is the ‘Remote’ workflow whereby you are editing a copy of the files on your local machine. There is also a ‘Server’ workflow which allows you to work directly off the server.

Just like Sublime Text itself, the plugin is not officially free. However, the trial never ends - just prompts you to purchase every so often. For more information on the plugin, visit the official page https://wbond.net/sublime_packages/sftp.

Read More

Cygwin Change Home Directory

In a new installation of Cygwin, your home directory will be in C:/cygwin/home/<user>/, and can be accessed by the usual ~ shortcut. Although this works just fine, it’s often useful to use the utilities provided by Cygwin in your local Windows user area C:/Users/<user>. Manually navigating to your Windows home directory can be a tedious process as you also have to go through cygdrive. By default, to access your Windows area in Cygwin you would navigate to /cygdrive/c/Users/<user>. Alternatively, you can just change your Cygwin home directory to be the same as Windows for easy access to all your files.

There are numerous posts on the Internet about how to accomplish this but the accepted methods always seems to change alongside Cygwin versions. Common solutions tend to involve the mkpasswd command, various environment variables, shortcuts and even registry edits. Thankfully, it seems that in the newer versions of Cygwin, there is a much easier way which requires one simple edit to a configuration file.

Navigate to the /etc/nsswitch.conf file in your installation folder (this should be something like C:/cygwin/etc/nsswitch.conf). Open it up in your favourite text editor and make the following change to the db_home property. This change simply points your Cygwin home to your Windows home using the %H variable. After the change, the file should look like this:

# /etc/nsswitch.conf
#
# Defaults:
# passwd:   files db
# group:    files db
# db_enum:  cache builtin
db_home: /%H
# db_shell: /bin/bash
# db_gecos: <empty>

And that’s it. Fire up a new Cygwin terminal and you should see that the default directory is now your Windows home directory. As expected, ~ also now points to your Windows home area.

Read More

Open Cygwin Here Shortcut

After frequently using the ‘Open command window here shortcut’ in Windows Explorer to open up a command prompt window in the current directory, I found it cumbersome not to have the option to open a Cygwin (or Bash) prompt as well, especially considering how I now find myself using Cygwin more and more often.

There are registry edits that you can do to get similar functionality, but it’s much easier to just use one of the packages bundled with Cygwin. Open up the Cygwin installer and select the chere package under Shells. It’s a very small package and so should install relatively quickly.

After that it’s just one command to add the new entry to the right-click context menu in Windows Explorer. Open up a new Cygwin terminal as administrator (this is important!) and run:

chere -i -t mintty

This will add a new entry to open up a mintty (bash) shell at the current directory. There are also options to specify the shell to open (-s zsh etc) and the text in the shortcut (-e "Custom text" etc). If completed successfully, you should see a new ‘Bash Prompt Here’ context menu entry:

Bash Prompt Here Entry

Read More

New Environment Variable Editor in Windows 10

The old environment variable editor in Windows has never been the best in terms of user experience. The main editor window was not resizeable and the two listboxes showing user and system environment variables were both small - making it awkward to manage a lot of variables. The problem got even worth when editing the PATH environment variable, which can often grow to become a rather large and unwieldy string. Previously, again the variable editor itself was not resizeable, forcing you to scroll through a small textbox to read or make changes to your PATH.

Old Windows Environment Variable Editor

Thankfully, in the new November Update for Windows 10 (build 10586), which includes enhancements to the Edge browser, Cortana, Start Menu and more, Microsoft have finally updated the Environment Variable manager.

New Windows Environment Variable Editor

The main editor window is now resizeable, making it much easier to navigate through your list of variables. The real magic however happens when editing the PATH variable, which now gets it’s own dedicated editor. Each path in the variable is now listed separately in a convenient listview, allowing you to quickly add or delete entries or change the order without having to scroll the whole string or worry about any semi-colon separators.

This new enhancement hasn’t had much attention in the latest update, but is definitely welcome nonetheless. Hopefully Microsoft will continue to update similar areas in Windows which haven’t seen any attention in years.

Read More

Spotify - Fix Repeating Radio

Spotify Logo

I tend to use the radio in Spotify quite a bit. It’s never been the best of implementations out there, but recently it’s been more annoying than usual in terms of repeating. The radio has always liked to repeat some songs over and over again, but it has now decided to repeat entire sequences of songs.

For example, if I start a new radio I will get a sequence of songs as usual. If however I listen to something else (perhaps a random song or playlist etc) and then go back to the same radio station, I will be greeted with the exact same sequence of songs as before. As you can imagine, this has gotten annoying really quickly. Initially you can keep skipping until you get to something new, but eventually that gets way too long-winded.

A quick search on the support forums show multiple users with the same kind of issues as me, but none are recent and there are no real solutions. Thankfully, after snooping through the AppData files for Spotify, I was able to come up with a solution:

  1. Navigate to the Local AppData folder for Spotify. This should be at C:/Users/<user>/AppData/Local/Spotify
  2. Locate to the Local Storage directory inside the Browser directory. At this point you should be in AppData/Local/Spotify/Browser/Local Storage
  3. There should be two files starting with http_radio. For me they are http\_radio.app.spotify.com\_0.localstorage and http\_radio.app.spotify.com\_0.localstorage-journal. Delete both of these files
  4. Restart Spotify and the radio’s should be reset

This might just be an issue for me, or might be a bug that will be fixed at some point. If it’s a design decision they need to rethink their priorities. At least I have this relatively easy fix however. I’ve put it all into a batch file and tend to run it just before I start Spotify.

Read More