Once the powershell week began in Habré , then I decided it’s time to get an article from the draft.
At the very time when ZverCD was, I experimented 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, OneGet was made, but even without OneGet, analogs began to appear. A kind of breakthrough was
chocolatey . Actually from writing a script under chocolatey, my epic on 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 expandable. This story is about what software I synchronize under windows than and how.
Every time when it is necessary to move from one computer to another, installation of the environment familiar to me is required. This is a set of programs and customization of hot keys. At first it was just a bat script, but over time it evolved into a powershell script, with a set of various 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 the programs, I use chocolatey and the script starts the initial installation. The first thing we do is download and install chocolatey, although the plans are to make another check on win10 and OneGet.
Set-ExecutionPolicy RemoteSigned -Force iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
Info who doesn’t want to use choco on a win10 machine, with the chocolate addy repository will have to be added to the trusted source so that the packages are not limited to the Microsoft repository (there are more packages in chocolatey).
')
Next, put the software to your taste, here is my:
- 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 hot key
autohotkey skrpitom:
#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 keepass launch, the base of which is synchronized via the dropbox. And the second hot key via 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). And if the explorer window is now active, the console will open exactly where it is now open. There is also a handy extension for
Visual Studio that allows you to open ps from the solution window:
Open Command Line . Hanselman wrote about him, here is
Quake Mode Console for Visual Studio - Open a Command Prompt with a hotkeyAnd in order for this script to work correctly and from under the admin (again I repent, there is a hole, but without the admin, the autoshots in those applications that are running under the admin) do not work, then the simplest way I found is to do a login task, like :
schtasks /Create /RU "Domain\Username" /SC ONLOGON /TN "autohotkey" /TR "D:\Dropbox\Apps\Autohotkey\runAutohotkey.exe" /IT /V1
Now let's start syncing application settings. The first thing we sync 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 uses standard dialogs for uploading and loading settings as
xml . The main problem is that the generated xml file simply dumps all the specified settings upon 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. This is well solved in 2013 visual studio did it there by synchronizing the profile of visual studio online (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 uploads of specific settings (shortcuts, text editor settings), and then compare them with the default settings. Well, in general, pornography is not to say otherwise.
I also naturally want the same shortcomings to be found in Sublime Text and in WebStorm, and I haven’t yet found a standard solution. There is a good plugin for synchronizing color scheme settings, tabs / spaces, and a bunch of other formatting options, but unfortunately it does not support synchronization of hot keys. Nevertheless, it is worth mentioning:
EditorConfig (
off.site ). The plugin is actively developing, and a lot of things the guys are sawing / finishing. Studio extensions are also the only synchronization method I found: save vsix extension files, and install them through VSIXInstaller. The launch string is:
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 a dropbox somehow did not impress me, nothing better than to go through the list in Evernote, and download them with my own hands, I did not find.
Slight deviation from the topic. Besides the extensions for the studio, now I also save scripts for
vcmd . Theoretically, I have them saved on the glassflow flow, where the
developer is very actively answering questions on the visual-studio tag. A couple of examples:
The command to copy the current location in the 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); } }
Autosaving of files at loss of focus of a window, 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 expand 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: install more trunny (;)) console colors and load all scripts and modules from the Dropbox folder. In these scripts, various snippets, prepared cmdlets and other delights, modules, for example,
posh-git . Over time, this folder has already accumulated decently scripts, without which I can’t imagine effective work with ps. But if you do not have much experience writing such cmdlets, then you can see the interesting scripts here:
microsoft scriptcenter . Another very handy
script for scripting:
Script Browser & Script Analyzer 1.4A small ps instead of ending. The article itself was written for a couple of years in a paragraph, so some of the data could be outdated. Of the open question is the synchronization of hot keys, if anyone has a recipe, I will be very grateful. Another scripting issue for the studio is also open, since The expansion is excellent, but in my opinion a large enough amount for expansion is $ 39 (the same resharper can be taken for $ 100 at a sale). Shifting the utility stack all the same with a bias on the .net stack, because the main working environment. For the same WebStorm, IDEA, I understand they themselves are somehow synchronized on a computer, and I did not bind the custom keys.