Add SQL Shell (psql) (postgres) to Windows Terminal - psql

I'm trying to add a new terminal Postgres shell (psql) to the Windows Terminal. I want to add it to the profiles list in the settings.
This is the windows terminal.
In the settings file, we can add a list of profiles. In that list, I have Windows PowerShell, Command prompt, and Azure Cloud Shell.
How do I add psql shell on that list?
{
"guid": "{some guid}",
"hidden": false,
"name": "SQL Shell (psql)",
"source": ?
}
I looked up various articles on this, but none of them has a working solution.
Can anyone help me with this?

I somehow figured it out!
The profile settings are:
{
"commandline" : "\"%PROGRAMFILES%\\PostgreSQL\\12\\scripts\\runpsql.bat\" -i -l",
"hidden": false,
"name": "PostgreSQL",
"icon" : "PostgreSQL.png*",
"background" : "#1b364d",
"cursorShape" : "vintage"
}
I also searched for the guid for some time, and then I remembered that I had added Git Bash to Windows Terminal. So I copied that executable, replaced the value with psql batch file address, and voilà!
*PostgreSQL.png

you can get the guid down below if you want, i got it from here:
https://www.postgresql.org/docs/8.3/datatype-uuid.html
"guid": "{a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11}",
"name" : "SQL psql",
"commandline": "%PROGRAMFILES%/PostgreSQL/13/scripts/runpsql.bat -i -l",
"hidden": false,
"icon": "%SystemDrive%/PROGRA~1/PostgreSQL/13/scripts/images/pg-psql.ico",

Related

How does nix-env knows the store path in advance?

If I query for available packages for Go:
nix-env -qa go -b --put-path --json
I get:
{
"nixpkgs.go_1_16": {
"name": "go-1.16.15",
"pname": "go",
"version": "1.16.15",
"system": "x86_64-linux",
"outputs": {
"out": "/nix/store/nqi39ksavkfrxkrz3d0797n5wmzi9r30-go-1.16.15"
}
},
"nixpkgs.go": {
"name": "go-1.17.7",
"pname": "go",
"version": "1.17.7",
"system": "x86_64-linux",
"outputs": {
"out": "/nix/store/3v2l94h7pllq6za9km3388cyd5agrln7-go-1.17.7"
}
},
"nixpkgs.go_1_18": {
"name": "go-1.18",
"pname": "go",
"version": "1.18",
"system": "x86_64-linux",
"outputs": {
"out": "/nix/store/7jyfpb96xv3hr8dpfhnbb0f7zscwm7sr-go-1.18"
}
}
}
I'm curios, how does nix-env knows the store path in advance? As far as I'm aware, the store path is generated by nix on build time, but nix-env already knows it without building(i see nothing gets downloaded from network for example).
The build process doesn't directly take .nix code (as downloaded from channels like https://nixos.org/channels/nixos-21.11) as inputs. Instead, it takes derivations as inputs; those derivations are generated by evaluating code written in the Nix language, and then are written into the Nix store as .drv files (which can be readily decoded to JSON for reading; see nix show-derivation). These .drv files are what is used as input by the actual build process (run by the nixbld sandboxed user accounts).
Those derivations fully specify what the build process will do -- all its inputs, and all its outputs. Because the outputs (except for those of fixed-output derivations) are addressed by the hash of the build process used to generate them, it's not necessary to actually run a build before the hash is known.
The exception I mentioned above is a fixed-output derivation; these are used for downloading resources that will be used by the build process off the network. For a Nix build step to be allowed network access, it needs to assert ahead-of-time what the output of that build step will be -- and the step is considered failed if it produces any output that does not match what was stated. In these, the hash of the content itself is used for the store location, so changes to the download process don't require re-downloading content.
The ability to predict the output location pre-build is critical because packages are pulled down from the Hydra binary cache by their hashes. If we didn't know the hashes until we had already built the package, the cache would be useless: We wouldn't know what name to look for the binary under unless we already had that binary in our posession! (And similarly, we wouldn't be able to plan more than one step ahead if we didn't know the names and hashes of our inputs without actually building them).
Let's take a practical example. Take it as given that as of the time that I'm writing this, I don't have GCC installed via Nix.
$ nix repl
Welcome to Nix version 2.3.16. Type :? for help.
nix-repl> :l <nixpkgs>
Added 15472 variables.
nix-repl> gcc8
«derivation /nix/store/9fpas3flqf424g46b8ldkbz7sgd9r7qk-gcc-wrapper-8.5.0.drv»
nix-repl> :b gcc8
...and either a download or a long build process runs here.
Notice how evaluating gcc8 gives us a /nix/store/*-gcc*.drv file. That file contains a plan describing how Nix would build gcc 8 if we wanted it to.
We can demonstrate that that plan includes the output location:
$ nix show-derivation /nix/store/9fpas3flqf424g46b8ldkbz7sgd9r7qk-gcc-wrapper-8.5.0.drv | jq '.[].outputs'
{
"info": {
"path": "/nix/store/znasm5jz3pp57ivspw5ahgn7rzfk791w-gcc-wrapper-8.5.0-info"
},
"man": {
"path": "/nix/store/j46y5mrppjw7nw9g8ckd3h438k8jjvkr-gcc-wrapper-8.5.0-man"
},
"out": {
"path": "/nix/store/v9pv2w7qiw1cpbjn4wjdkxkzld7pfki4-gcc-wrapper-8.5.0"
}
}

OPA policy to allow docker exec

I've deployed the OPA docker plugin as per instruction. And everything was fine until I've tried to create custom docker API permissions for docker exec.
I've added following section to authz.rego file:
allow {
user_id := input.Headers["Authz-User"]
users[user_id].readOnly
input.path[0] == "/v1.41/containers/busybox/exec"
input.Method == "POST"
}
But it still gives me error when I try to run following bash command: docker exec -it busybox sh under Bob test user as per instruction.
journalctl -u docker.service provides following error:
level=error msg="AuthZRequest for POST /v1.41/containers/busybox/exec returned error: authorization denied by plugin openpolicyagent/opa-docker-authz-v2:0.4: request rejected by administrative policy"
The funny thing is when I comment out input.path section it works as full RW user so the rule works but the strict mention of API path - does not. Maybe I'm specifying it in a wrong way?
Tried different variations like:
input.path == ["/v1.41/containers/busybox/exec"]
input.path = ["/v1.41/containers/busybox/exec"]
input.path = ["/v1.41*"]
input.path = ["/v1.41/*"]
input.path = ["/v1.41%"]
input.path = ["/v1.41/%"]
Also would appreciate advice on how to allow exec operations for any container not only the specified one.
Thanks in advance!
Looking at the input map provided to OPA, you should find both input.Path, input.PathPlain and input.PathArr:
input := map[string]interface{}{
"Headers": r.RequestHeaders,
"Path": r.RequestURI,
"PathPlain": u.Path,
"PathArr": strings.Split(u.Path, "/"),
"Query": u.Query(),
"Method": r.RequestMethod,
"Body": body,
"User": r.User,
"AuthMethod": r.UserAuthNMethod,
}
There's no lowercase input.path available, but using any of the other alternatives should work.

How can I limit the recources available to Docker Engine in the command line?

I.e., one can change it in Docker's settings picture (i.e., using GUI). Can I limit the memory using the command line instead using OSX?
The problem is that after I set its memory limit to 10GB I cannot start Docker anymore and it just hangs.
Update:
I did read this question, but I believe it doesn't apply to me since I don't have a virtual box.
Docker for mac use hyperkit vm just like hyperv on windows10, the settings could be in some place like next:
/Users/<username>/Library/Group Containers/group.com.docker/settings.json
The default value is:
{
"dockerAppLaunchPath" : "/Applications/Docker.app",
"proxyHttpMode" : "system",
"buildNumber" : "31259",
"cpus" : 2,
"diskSizeMiB" : 61035,
"version" : "2.0.0.3",
"settingsVersion" : 1,
"channelID" : "stable",
"memoryMiB" : 2048,
"displayedWelcomeMessage" : true,
"displayedWelcomeWhale" : true,
"linuxDaemonConfigCreationDate" : "2019-06-26 02:32:30 +0000",
"diskPath" : "Library/Containers/com.docker.docker/Data/vms/0/Docker.qcow2"
}
So, you can use command to modify the value you want to change, next is an example to change memory to 3072M, or just use any editor to directly modify the value:
sed -i 's/"memoryMiB".*/"memoryMiB" : 3072,/g' /Users/`id -un`/Library/Group\ Containers/group.com.docker/settings.json
Finally, in command restart the docker as next:
osascript -e 'quit app "Docker"' && open -a Docker

How to install application as windows service using NSIS script

How to install application as windows service using NSIS script?
I used this command in the script Exec '"sc.exe" but after installation i couldn't find any service in windows services related to it so help me thanks.
Maybe that the NSIS Simple Service plugin can help you. The syntax is as simple as
SimpleSC::InstallService "MyService" "My Service Display Name" "16" "2" "C:\MyPath\MyService.exe" "" "" ""
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
Here the example install the service as ServiceType own process + StartType automatic + NoDependencies + Logon as System Account.
Please refer to the accompanying help for the meaning of the magic numbers.
The wiki shows the 5 other methods to handle services with NSIS.
There are multiple plugins out there as stated on NSIS website
For me it seemed to be unnecessary complicated, so I ended up using sc tool directly. A command is quite simple:
!define appName "theApp.exe"
!define displayName "My Awesome Service"
!define serviceName "MyAwesomeService"
ExecWait 'sc create ${serviceName} error= "severe" displayname= "${displayName}" type= "own" start= "auto" binpath= "$INSTDIR\${appName}"'
A full list of sc create arguments available here
Below is the scripts which first stops service, uninstalls previous version, remove form registry and then installs fresh copy.
Section "Mobile Interface"
SimpleSC::StopService "MobileInterface" "1" "60"
SimpleSC::RemoveService "MobileInterface"
DeleteRegKey /ifempty HKLM "MobileInterface"
RMDIR /r "$INSTDIR\MobileInterface\"
SetOutPath "$INSTDIR\MobileInterface"
# define what to install and place it in the output path
File "D:\NCS.Sentinel\NCS.Sentinel.MobileWebSvc\bin\Release\"
SimpleSC::InstallService "MobileInterface" "MobileInterface" "16" "2" "$INSTDIR\MobileInterface\NCS.Sentinel.MobileWebSvc.exe" "" "" ""
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
SimpleSC::StartService "MobileInterface" "" "100"
#WriteRegStr HKLM "D:\NCS.Sentinel\NCS.Sentinel.MobileWebSvc\bin\Release\NCS.Sentinel.MobileWebSvc.exe"
WriteUninstaller "$INSTDIR\Uninstall.exe"
; Store installation folder
;WriteRegStr HKCU "Software\Mobile Interface" "" $INSTDIR
SectionEnd

Sublime Text 2: custom PATH and PYTHONPATH

I'm using brew which installs python (2.7.2) in /usr/local/bin/
However, the default system python (2.7.1) is executed instead at /usr/bin/, which seems to be because it doesn't obey any of the bash PATH environment variables.
Also, it can't find my modules, as they are installed at /usr/local/lib/python:/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages.
I've been trying the following with Python.sublime-settings, but it doesn't work:
{
"path": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",
"env": ["PYTHONPATH", "/usr/local/lib/python:/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages"],
"cmd": ["python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
How can I make Sublime Text obey these environment variables?
env needs to be a JSON object, or dictionary if you will, like this:
"env":
{
"PYTHONPATH":"/usr/local/lib/python:/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages"
},
I got it by setting my paths system wide by doing the following:
## PATH
export PATH=/usr/local/bin:/usr/local/share/python:$PATH
## PYTHON
export PYTHONPATH=/usr/local/lib/python:$PYTHONPATH
# make systemwide
launchctl setenv PATH $PATH
launchctl setenv PYTHONPATH $PYTHONPATH
Edit:
Damn, this doesn't work for python, just for PYTHONPATH, when I try it, it still gives the wrong python. Code used to check python binary location:
import sys, os
print os.path.dirname(sys.executable)
Edit2:
Fixed this by hardlinking to the right python binary in Python.sublime-build:
{
"cmd": ["/usr/local/bin/python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
Edit 3:
Debugging PYTHONPATH variable issues can be made easier by also printing os.environ at the top of your script. Sublime Text 2 variable names apparently do NOT work for 'env'.
Sorry to bump an old post but if people land on this page looking for a way to make sublime2 use a custom $PATH so plugins (e.g a shell plugin) use your current systems $PATH this worked for me:
Create a file (plugin):
~/Library/Application Support/Sublime Text 2/Packages/User/Any_ol_name.py
Then paste this code in:
import os
# Tweak line below as needed for your $PATH
LOCAL = '/usr/local/bin:/usr/local/sbin'
# Sublime's default path is
# /usr/bin:/bin:/usr/sbin:/sbin
# it'll be prepended to your custom one
os.environ['PATH'] += ':'
os.environ['PATH'] += LOCAL
print 'PATH = ' + os.environ['PATH']
Post with the original code here..
This plugin will load when you start Sublime Text 2, I personnally used it to run shell commands like I would from terminal and to fix a few plugins that werent loading due to bad path variable.
This is a super old post but I landed here looking for this solution for Sublime Text 3. Just in case people land here as well, the quick solution is to go into Preferences.sublime-settings and add:
"additional_path_items": [
"/path/to/add/1",
"/path/to/add/2",
],

Resources