Windows-way settings synchronization between systems
Since the powershell week began on the hub , I decided it was time to get the article out of the draft.
At the same time that I was ZverCD, I was experimenting with ubunta and sincerely wondered why they would not make a single repository for windows programs. About 5 years have passed since then, and a package manager has appeared under windows. Well in win10 they did OneGet, but without OneGet, analogues began to appear. A kind of breakthrough was chocolatey
. Actually, with the writing of the chocolatey script, my epic of universal total synchronization and portability began. Each new installation of the operating system, for me, looks like the launch of one script (in an ideal world it is!), With each new installation the truth is more and more extensible. This story is about what software I synchronize under windows with what and how.
Each time you need to move from one computer to another, you need to install the environment familiar to me. This is a set of programs and setting hot keys. At first it was just a bat script, but over time it evolved into a powershell script, with a set of different optional settings and tasks.
To install programs, I use chocolatey and the script starts the initial installation. The first thing we do is download and install chocolatey, although there are plans to do another check on win10 and OneGet.
Info who do not want juzat choco on win10 machine shocolatey repository will have to add to the trusted source, that the packets were not limited maykrosoftovskih repository (in chocolatey at times more packets).
Next, put the software to your taste, here's mine:
Add a little autohotkey hotkeys with a script:
The first one adds win + k to start keepass, the base of which is synchronized via dropbox. And the second hotkey through Ctrl + Alt + Space opens powershell from the admin (without the admin, somehow everything is completely neutered, and I did not find a convenient analogue of sudo). Moreover, if the Explorer window is currently active, then the console will open exactly where it is now open. There is also a convenient extension for Visual Studio that allows you to open ps from a solution window: Open Command Line . Hanselman wrote about him, here Quake Mode Console for Visual Studio - Open a Command Prompt with a hotkey
And in order for this script to work correctly from the admin (again, I repent, a hole, but without the auto-hockey in those applications running under the admin), the easiest way I found is to do a login task, something like this :
Now let's start synchronizing application settings. The first thing we synchronize is Sublime Text. The synchronization process is described well here . tl; dr make a symbolic link to the dropbox folder for the User folder from % AppData% \ Roaming \ Sublime Text 3 \ Packages :
To synchronize the settings of Visual Studio , SQL Management Studio , standard dialogs for uploading and loading settings in the form of xml are used . The main problem is that the generated xml file simply dumps all the specified settings during export, and this is not very usable. I would like to inherit from the standard general configuration, or from c # for the studio, and then redefine my settings. Well, this is solved in 2013 visual studio there they did it through the synchronization of the visual studio online profile (details msdn) But what if we need to synchronize 2010, 2013, 2015, and just keep these settings under control, for this we have to do several different downloads of specific settings (shortcuts, text editor settings), and then compare with the default. Well, pornography in general, not to say otherwise.
Naturally, I want the same shortcodes in Sublime Text and WebStorm, and I have not yet found a standard solution. There is a good plugin for synchronizing color scheme settings, tabs / spaces, and a bunch of other formatting settings, but unfortunately it does not support hotkey synchronization. Nevertheless, it is worth mentioning: EditorConfig ( off site) The plugin is actively developing, and a lot of things the guys saw / finish. Extensions for the studio is also the only synchronization method I have found: save vsix files of extensions and install them through VSIXInstaller. The launch line is this:
But since extensions periodically become obsolete, and the idea of storing binaries in dropbox somehow didn’t impress me, nothing better than going through the list in Evernote and I didn’t find them by hand.
A slight deviation from the topic. In addition to extensions for the studio, now I save scripts for vcmd . Theoretically, I saved them on stackflow, where the developer is very active in answering questions about the visual-studio tag. A couple of examples: A
command to copy the current location in a file
Auto-save files when window focus is lost, Jetbrains-like
To deploy the powershell profile, I wrote this script:
The script itself is the following code
What happens in the profile script: the console’s more disastrous (;)) colors are installed and all scripts and modules from the Dropbox folder are loaded. In these scripts, various snippets, prepared cmdlets and other delights, modules, for example posh-git . Over time, decently already accumulated scripts in this folder, without which I can not imagine effective work with ps. But if you don’t have much experience writing such cmdlets, you can see the Interscripts here: microsoft scriptcenter . Another very convenient scripting tool: Script Browser & Script Analyzer 1.4
A small ps instead of ending. The article itself was written for a couple of years in a paragraph, so some data could be outdated. Of the open question, the synchronization of hot keys, if anyone has a recipe, I will be very grateful. Another scripting issue for the studio is also open, because the extension is excellent, but $ 39 in my opinion is a large enough amount for the extension (the same resharper can be taken for $ 100 on sale). The utility stack offset is still with a bias on the .net stack, because the main working environment. For the same WebStorm, IDEA, as I understand it, they synchronize themselves with some kind of magic on a computer, and I did not bind custom keys.
. Actually, with the writing of the chocolatey script, my epic of universal total synchronization and portability began. Each new installation of the operating system, for me, looks like the launch of one script (in an ideal world it is!), With each new installation the truth is more and more extensible. This story is about what software I synchronize under windows with what and how.
Each time you need to move from one computer to another, you need to install the environment familiar to me. This is a set of programs and setting hot keys. At first it was just a bat script, but over time it evolved into a powershell script, with a set of different optional settings and tasks.
@powershell -NoProfile -ExecutionPolicy unrestricted -Command
"iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))"
&& SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
choco install google-chrome-x64
choco install sublimetext3
choco install dropbox
choco install puntoswitcher
choco install skype
choco install keepass
choco install keepass-keepasshttp
choco install git
choco install sysinternals
choco install kdiff3
choco install gimp
choco install fiddler4
choco install tortoisegit
choco install tortoisesvn
choco install evernote
choco install treesizefree
choco install teamviewerr
schtasks /Create /RU "Domain\Username" /SC ONLOGON /TN "autohotkey" /TR "D:\Dropbox\Apps\Autohotkey\runKeepass.exe" /IT /V1
cd %AppData%\Roaming\Sublime Text 3\Packages\
mklink /D User "d:\Dropbox\Apps\Sublime Text 3\User"
cd /d "D:\Dropbox\Apps\powershell"
@powershell .\copy_to_profile.ps1
To install programs, I use chocolatey and the script starts the initial installation. The first thing we do is download and install chocolatey, although there are plans to do another check on win10 and OneGet.
Set-ExecutionPolicy RemoteSigned -Force
iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
Info who do not want juzat choco on win10 machine shocolatey repository will have to add to the trusted source, that the packets were not limited maykrosoftovskih repository (in chocolatey at times more packets).
Next, put the software to your taste, here's mine:
- google-chrome-x64
- skype
- sublimetext3
- dropbox
- puntoswitcher
- keepass
- keepass-keepasshttp
- sysinternals
- kdiff3
- paint.net
- gimp
- fiddler4
- evernote
- treesizefree
- teamviewer
- git
- tortoisegit
- tortoisesvn
- nodejs
- ant
Add a little autohotkey hotkeys with a script:
#k::
Run "C:\Program Files (x86)\KeePass Password Safe 2\Keepass.exe"
#IfWinActive ahk_class CabinetWClass ; for use in explorer.
^!Space::
ClipSaved := ClipboardAll
Send !d
Sleep 200 ; In some cases timeout settings have to be adjusted
Send ^c
Run, powershell -noexit -command "$exist=Test-Path '%clipboard%'; if($exist){Set-Location '%clipboard%' }else{Set-Location 'c:\'}"
Clipboard := ClipSaved
ClipSaved =
return
#IfWinActive
#IfWinNotActive
^!Space::Run, powershell -noexit -command "Set-Location 'c:\'"
#IfWinNotActive
The first one adds win + k to start keepass, the base of which is synchronized via dropbox. And the second hotkey through Ctrl + Alt + Space opens powershell from the admin (without the admin, somehow everything is completely neutered, and I did not find a convenient analogue of sudo). Moreover, if the Explorer window is currently active, then the console will open exactly where it is now open. There is also a convenient extension for Visual Studio that allows you to open ps from a solution window: Open Command Line . Hanselman wrote about him, here Quake Mode Console for Visual Studio - Open a Command Prompt with a hotkey
And in order for this script to work correctly from the admin (again, I repent, a hole, but without the auto-hockey in those applications running under the admin), the easiest way I found is to do a login task, something like this :
schtasks /Create /RU "Domain\Username" /SC ONLOGON /TN "autohotkey" /TR "D:\Dropbox\Apps\Autohotkey\runAutohotkey.exe" /IT /V1
Now let's start synchronizing application settings. The first thing we synchronize is Sublime Text. The synchronization process is described well here . tl; dr make a symbolic link to the dropbox folder for the User folder from % AppData% \ Roaming \ Sublime Text 3 \ Packages :
cd %AppData%\Roaming\Sublime Text 3\Packages\
mklink /D User "d:\Dropbox\Apps\Sublime Text 3\User"
To synchronize the settings of Visual Studio , SQL Management Studio , standard dialogs for uploading and loading settings in the form of xml are used . The main problem is that the generated xml file simply dumps all the specified settings during export, and this is not very usable. I would like to inherit from the standard general configuration, or from c # for the studio, and then redefine my settings. Well, this is solved in 2013 visual studio there they did it through the synchronization of the visual studio online profile (details msdn) But what if we need to synchronize 2010, 2013, 2015, and just keep these settings under control, for this we have to do several different downloads of specific settings (shortcuts, text editor settings), and then compare with the default. Well, pornography in general, not to say otherwise.
Naturally, I want the same shortcodes in Sublime Text and WebStorm, and I have not yet found a standard solution. There is a good plugin for synchronizing color scheme settings, tabs / spaces, and a bunch of other formatting settings, but unfortunately it does not support hotkey synchronization. Nevertheless, it is worth mentioning: EditorConfig ( off site) The plugin is actively developing, and a lot of things the guys saw / finish. Extensions for the studio is also the only synchronization method I have found: save vsix files of extensions and install them through VSIXInstaller. The launch line is this:
cd "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE" .\VSIXInstaller.exe "D:\Dropbox\Apps\Visual Studio\extensions\VSColorOutput.vsix"
But since extensions periodically become obsolete, and the idea of storing binaries in dropbox somehow didn’t impress me, nothing better than going through the list in Evernote and I didn’t find them by hand.
A slight deviation from the topic. In addition to extensions for the studio, now I save scripts for vcmd . Theoretically, I saved them on stackflow, where the developer is very active in answering questions about the visual-studio tag. A couple of examples: A
command to copy the current location in a file
using EnvDTE;
using EnvDTE80;
public class C : VisualCommanderExt.ICommand
{
public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
{
EnvDTE.TextSelection ts = DTE.ActiveWindow.Selection as EnvDTE.TextSelection;
if (ts == null)
return;
EnvDTE.CodeFunction func = ts.ActivePoint.CodeElement[vsCMElement.vsCMElementFunction]
as EnvDTE.CodeFunction;
if (func == null)
return;
string result = DTE.ActiveWindow.Document.FullName + System.Environment.NewLine +
"Line " + ts.CurrentLine + System.Environment.NewLine +
func.FullName;
System.Windows.Clipboard.SetText(result);
}
}
Auto-save files when window focus is lost, Jetbrains-like
public class E : VisualCommanderExt.IExtension
{
public void SetSite(EnvDTE80.DTE2 DTE_, Microsoft.VisualStudio.Shell.Package package)
{
DTE = DTE_;
System.Windows.Application.Current.Deactivated += OnDeactivated;
}
public void Close()
{
System.Windows.Application.Current.Deactivated -= OnDeactivated;
}
private void OnDeactivated(object sender, System.EventArgs e)
{
try
{
DTE.ExecuteCommand("File.SaveAll");
}
catch (System.Exception ex)
{
}
}
private EnvDTE80.DTE2 DTE;
}
To deploy the powershell profile, I wrote this script:
cd /d " "D:\Dropbox\Apps\powershell"
@powershell .\copy_to_profile.ps1
The script itself is the following code
$scriptRoot = Split-Path $MyInvocation.MyCommand.Path
$profileFileInfo = New-Object System.IO.FileInfo $PROFILE
$profileExist = Test-Path $profile
$modulesFolder = [System.IO.Path]::Combine($profileFileInfo.Directory,"Modules")
if(-not ((Test-Path $profile) -AND (Test-Path $modulesFolder)))
{
Write-Host "Creating directories"
New-Item -ItemType directory -path $profileFileInfo.Directory -ErrorAction SilentlyContinue
New-Item -ItemType directory -path $modulesFolder
}
Copy-Item -Path $scriptRoot\Microsoft.PowerShell_profile.ps1 -Destination $profile
Get-ChildItem Modules -Recurse |%{ Copy-Item $_.FullName -Destination $modulesFolder -Force}
Write-Host "Profile was updated"
What happens in the profile script: the console’s more disastrous (;)) colors are installed and all scripts and modules from the Dropbox folder are loaded. In these scripts, various snippets, prepared cmdlets and other delights, modules, for example posh-git . Over time, decently already accumulated scripts in this folder, without which I can not imagine effective work with ps. But if you don’t have much experience writing such cmdlets, you can see the Interscripts here: microsoft scriptcenter . Another very convenient scripting tool: Script Browser & Script Analyzer 1.4
A small ps instead of ending. The article itself was written for a couple of years in a paragraph, so some data could be outdated. Of the open question, the synchronization of hot keys, if anyone has a recipe, I will be very grateful. Another scripting issue for the studio is also open, because the extension is excellent, but $ 39 in my opinion is a large enough amount for the extension (the same resharper can be taken for $ 100 on sale). The utility stack offset is still with a bias on the .net stack, because the main working environment. For the same WebStorm, IDEA, as I understand it, they synchronize themselves with some kind of magic on a computer, and I did not bind custom keys.