Debugging Bash, using VSCode

Sean Reifschneider jafo00 at gmail.com
Wed Jan 26 19:22:26 MST 2022


I've never really gotten comfortable with VSCode.  I don't spend much time
programming, so most of my editing is Ansible files, text, logfiles, and
most of the programming I do is single file source rather than whole
projects.  VSCode just doesn't really seem comfortable to me, for those
uses.

But I've looked longingly at all the enhanced features you get in VSCode.
I've tried a variety of things to get vim to do fancy things, and ended up
with a barely functional mess.

So I started looking at other options to building my own set of plugins.
Onivim2, kakoune, I forget what else.

I've ended up landing on LunarVim and have been pretty dog gone happy with
it.

It's a set of configs and plugins for NeoVim, with opinionated defaults,
and integrations with TreeSitter and LSP to get all sorts of advance syntax
highlighting, code intelligence, formatting...  It's a pretty great
experience!

https://www.lunarvim.org/

I did make some changes in the default ~/.config/lvim/config.lua:

-- Sean's settings
vim.opt.cursorline = false
vim.opt.scrolloff = 0
vim.opt.wrap = true
vim.opt.relativenumber = true
lvim.keys.normal_mode["<S-h>"] = false
lvim.keys.normal_mode["<S-l>"] = false
lvim.keys.normal_mode["<A-l>"] = ":BufferNext<cr>"
lvim.keys.normal_mode["<A-h>"] = ":BufferPrevious<cr>"
lvim.keys.insert_mode["<A-j>"] = false
lvim.keys.insert_mode["<A-k>"] = false
lvim.keys.normal_mode["<A-j>"] = false
lvim.keys.normal_mode["<A-k>"] = false
lvim.keys.visual_block_mode["<A-j>"] = false
lvim.keys.visual_block_mode["<A-k>"] = false
lvim.colorscheme = "industry"

In English:

Don't highlight the line the cursor is on.
Don't keep 5 lines of context above/below the cursor when I scroll.
Don't make me scroll left/right.
Have the line numbers it shows be relative to the current line, nice for if
I want to go to a specific line, I know I need "35k" because it's 35 above
where I am.
IIRC, H and L would switch between "tabs" or buffers, but I use H all the
time to go to the top of the screen and L for the bottom.
But, the H/L switch tabs is nice, so I put it on Alt H/L.
By default, ESC+j/k very quickly would move the current line you are on up
or down a line.  I can see the use for that, but I would often end up
moving a line by accident when I was typing quickly, so shut it off.
A different color scheme.

Been using it a few months now, and very happy with it.

On Sat, Jan 22, 2022 at 2:14 PM Brian Sturgill <bsturgill at ataman.com> wrote:

> Visual Studio Code (VSCode) is an open source editor based on electron and
> nodejs.
> It is probably the best open source editor available, with wide support by
> many, many projects.
> It works equally well on Linux, Windows and MacOS. I use it routinely on
> all three platforms.
> One such project is the Bash Debugger Project and is a great way to get
> started.
>
> This is a quick start guide:
>
> Install VSCode: https://code.visualstudio.com/Download
> Click on the 4 box icon at the left (the top left box is raised away from
> the other three).
> Use the Search box at the top of the list of extensions list to find:
> (I also just discovered Bash Extension, which installs all three plus
> more).
>     Bash Debug
> You might also want to install:
>     Bash Beautify
>     Bash IDE
>     sudo apt install python-is-python3  # My version of Linux has only
> version 3 installed.
>
> IMPORTANT: Exit VSCode!
>
> Create a directory somewhere using your shell and then cd to it and type:
>     code .
>
> Click the "explorer" button at the top left (looks like two sheets of
> paper).
> Now move your mouse near the name of the directory and click the new file
> button...
> Create a file.
> #!/bin/bash
> for f in /proc/*; do
>    echo $f
> done
>
> If you installed Bash Beautify you'll see it with syntax coloring.
> To the left of line 3 single click twice (pause between)... this will set
> a breakpoint.
> A red "led" will appear there.
>
> From the "Run" menu select "Add Configuration..."
> Choose "Bash Debug".
> You'll be placed into the file "launch.json".
> Switch back to your bash file.
> From "Run" menu select "Start Debugging".
> You'll stop at first line of code.
> Select "continue" from debug controls at top.
> You'll stop at line 3.
> Hover over "$f"... you'll see it's value.
> Add $f in the watch expressions at the left.
> Hit "continue" a few times.
>
> By now, you'll have a good idea of how the debugging works.
> Hit the red square button to stop debugging.
>
>
> --
>
> Brian
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.nclug.org/pipermail/nclug/attachments/20220126/cf37fabd/attachment.htm>


More information about the NCLUG mailing list