question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I get CTRL-D to execute my own function before ViExit?

See original GitHub issue

I’m using this to exit my powershell sessions:

Set-PSReadlineKeyHandler -Key ctrl+d -Function ViExit

But I would like to do something else before exiting, so how can I have another function be executed before ViExit when doing CTRL-d?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
eabasecommented, Oct 15, 2020

@gwojan

Why not bind Ctrl+d to a user defined function

That’s what i wanted to do, but I was under the impression that ...-Function ViExit was internal to PSReadLine and thus could not be replaced by myfun().

I managed to solve this by setting an event handler inside my profile script like this:

Register-EngineEvent PowerShell.Exiting -SupportEvent –Action { 
    Write-Host "`nExiting...`n" -fore Magenta; sleep(3); 
}
Set-PSReadlineKeyHandler -Key ctrl+d -Function ViExit

However, I don’t think this is actually executed before ViExit, but worked for my purposes.

1reaction
gwojancommented, Oct 15, 2020

Why not bind <kbd>Ctrl+d</kbd> to a user defined function that ultimately calls ViExit?

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Doing something before program exit
It will be called if you press Ctrl+C. That simply raises a KeyboardInterrupt exception. – Ned Batchelder. Oct 3, 2010 at 15:11.
Read more >
When pressed ctrl+c only break out of current function and ...
I'm trying to write a script wherein if someone pressed CTRL + C (Keyboard interruption) then it shouldn't exit the entire script, just...
Read more >
2 Ways to Assign Keyboard Shortcuts to Macros
You can easily look up your keyboard shortcuts by by searching the VBA code for the word “onkey.” Use the Find window (...
Read more >
Keyboard shortcuts - Visual Studio (Windows)
Break at function, Ctrl+B, Debug.BreakatFunction ; Break all, Ctrl+Alt+Break, Debug.BreakAll ; Delete all breakpoints, Ctrl+Shift+F9, Debug.
Read more >
Keyboard shortcuts - RStudio IDE
Keyboard shortcuts · Ctrl + Enter · Ctrl + Shift + n · Ctrl + s · Alt + - · Ctrl +...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found