Showing posts with label tips. Show all posts
Showing posts with label tips. Show all posts

Thursday, June 7, 2018

Using the VS Code Integrated Terminal with Remote Hosts

I am in the process of writing some server-side scripts on a remote server. There are three things that would make it easier:

1. If I could write the code directly to the server from VS Code
2. If the integrated terminal in VS Code would automatically log me into that server
3. If I could easily toggle between the code window and the terminal window

I am going to describe how to do all of those things.

Writing Code Directly to the Server in VS Code

To write code directly to the server, I am using an SFTP extension I found in the VS Code Marketplace. The extension I am using is simply called sftp.

To configure it, you open the command palette (Cmd+Shift+P) and select SFTP: Config. This will generate a file called sftp.json within the .vscode directory of your workspace. You can check out the full config options, but basically you just need to specify the host, username, and remote path. So that my code is automatically saved to the server, I set the uploadOnSave option to true in the sftp.json file.

And so that I don't have to log in every time, I am using the privateKeyPath option as well. I won't go into the details here of how to set up SSH for auto login without a password but it is definitely a time saver.


Automatically Logging into the Remote Server

The next thing I wanted to accomplish was automatically logging into the remote server in the integrated terminal. To do that I need to update my workspace settings.

To start I select Code ▶ Preferences ▶ Settings to open the Workspace Settings. Then within the settings, I add some JSON to tell it to call the ssh command with an argument of the server name.


Also, because I like to color code my terminal windows, I found the workbench.colorCustomizations setting which allows me to set a value for terminal.background.

For this change to take effect, I have to restart VS Code. A security feature prompts me to make sure this is what I really want to do. This only happens the first time.


I have to restart VS Code one more time. This time when I open the terminal, it automatically logs me into the remote server so that I can test my scripts.

Toggling Between the Code Window and the Terminal Window

While I like having the terminal window integrated into my IDE, I don't like having to use the mouse to click back and forth between the two windows. Fortunately, someone on Stack Overflow had already solved that problem.

This time I go to Code ▶ Preferences ▶ Keyboard Shortcuts. To make the change, I first have to click on the keybindings.json link:


Then I can paste in the code for my settings.


Now after I save my code, I simply press Ctrl+` to switch to the terminal window, test my code, and then press Ctrl+` again to return back to my code.

Wednesday, April 5, 2017

Clipboard Managers

I do a lot of copying and pasting. A lot. One of the things that often happens is that I copy a piece of information, paste it, copy something else, paste it, then need to go back to that previous information I copied. Or maybe I need to copy two (or more) pieces of information from one source before switching to the other source. The best way to handle this is with a clipboard manager. These tools allow you to keep a history of everything you have copied (up to a limit) and the refer back to them. Here are a couple that I have used in my job:

ClipMenu for MacOX (Updated 12/06/18 with new link)
Ditto for Windows

Tuesday, April 10, 2012

Outlook Messages with Word Attachments

I hate getting emails at work with Word attachments. It just takes too long to open the attachment especially when the content could have been easily included in the message. Let's make a pact that any time we have a meeting agenda, job posting, etc. that has minimal formatting, we will copy and paste it into the message instead. Outlook is smart enough to know what to do with it (most of the time) and it will save everybody some time.

Thursday, April 5, 2012

Using Color to Prevent Accidents

We are all familiar with the use of color for keeping our attention: stop lights, construction signs, warning labels, etc. To try to minimize the number of mistakes I make, I color code my terminal sessions.

On Windows I use PuTTY for creating a secure shell session into the servers that I need to access. One of the options it to set a background color for the session.


For production I set the background color to red and for development I set the background to green. The red color is a warning to myself: "You are on the production server. Don't screw things up!" Then for each server I log into, I save a session, and create a shortcut to it. In PuTTY the syntax is putty.exe -load "session_name". For example:

c:\putty.exe -load "dev"
c:\putty.exe -load "prod"

Color can't fix my stupid mistakes, but it has helped me to stay focused.

On the topic of color, I just read this article on Wired.com about how red keeps you focused and blue makes you more creative. Next step is to use Firefox Personas to color code my Firefox windows: red for coding and blue for designing.

Tuesday, February 7, 2012

Paperless Billing

One of my goals for 2012 has been to get better organized and get a better grip on my finances. And one way that I've done that is to switch to paperless billing for some of my accounts. I have tried this in the past but it never worked because I would lose the bill in my inbox. But I have come up with a solution that seems to work better this time.


The first thing I did was to download Mozilla Thunderbird onto my desktop and put it in my Startup folder. Then I created a new email called statements@my-domain-name-dot-com and configured Thunderbird to check it. Next I created a second email called bills@my-domain-name-dot-com that forwards all incoming mail to the statements account as well as the email account I check on my iPhone. That way when I get a bill, I get a reminder on my phone AND on my desktop computer at home. Lastly, I used the filtering capabilities of Thunderbird to move the various bills and statements into folders for each company I do business with.
 
Blogger Templates