diff --git a/.config/alacritty/alacritty.yml b/.config/alacritty/alacritty.yml index bfb0d213..cf91f4d8 100644 --- a/.config/alacritty/alacritty.yml +++ b/.config/alacritty/alacritty.yml @@ -186,8 +186,8 @@ draw_bold_text_with_bright_colors: true colors: # Default colors primary: - background: "#1d1f21" - foreground: "#c5c8c6" + background: '#1d1f21' + foreground: '#c5c8c6' # Bright and dim foreground colors # @@ -195,8 +195,8 @@ colors: # present. If the bright foreground color is not set, or # `draw_bold_text_with_bright_colors` is `false`, the normal foreground # color will be used. - dim_foreground: "#828482" - bright_foreground: "#eaeaea" + dim_foreground: '#828482' + bright_foreground: '#eaeaea' # Cursor colors # @@ -232,8 +232,8 @@ colors: # background: '#000000' bar: - background: "#282828" - foreground: "#EBEBE9" + background: '#282828' + foreground: '#EBEBE9' # Keyboard regex hints hints: @@ -242,16 +242,16 @@ colors: # Allowed values are CellForeground/CellBackground, which reference the # affected cell, or hexadecimal colors like #ff00ff. start: - foreground: "#1d1f21" - background: "#e9ff5e" + foreground: '#1d1f21' + background: '#e9ff5e' # All characters after the first one in the hint label # # Allowed values are CellForeground/CellBackground, which reference the # affected cell, or hexadecimal colors like #ff00ff. end: - foreground: "#e9ff5e" - background: "#1d1f21" + foreground: '#e9ff5e' + background: '#1d1f21' # Line indicator # @@ -275,39 +275,39 @@ colors: # Normal colors normal: - black: "#313539" - red: "#b02626" - green: "#40a62f" - yellow: "#f1e635" - blue: "#314ad0" - magenta: "#b30ad0" - cyan: "#32d0fc" - white: "#acadb1" + black: '#313539' + red: '#b02626' + green: '#40a62f' + yellow: '#f1e635' + blue: '#314ad0' + magenta: '#b30ad0' + cyan: '#32d0fc' + white: '#acadb1' # Bright colors bright: - black: "#717174" - red: "#b02626" - green: "#40a62f" - yellow: "#f1e635" - blue: "#314ad0" - magenta: "#b30ad0" - cyan: "#32d0fc" - white: "#acadb1" + black: '#717174' + red: '#b02626' + green: '#40a62f' + yellow: '#f1e635' + blue: '#314ad0' + magenta: '#b30ad0' + cyan: '#32d0fc' + white: '#acadb1' # Dim colors # # If the dim colors are not set, they will be calculated automatically based # on the `normal` colors. dim: - black: "#676f78" - red: "#b55454" - green: "#78a670" - yellow: "#faf380" - blue: "#707fd0" - magenta: "#c583d0" - cyan: "#8adaf1" - white: "#e0e3e7" + black: '#676f78' + red: '#b55454' + green: '#78a670' + yellow: '#faf380' + blue: '#707fd0' + magenta: '#c583d0' + cyan: '#8adaf1' + white: '#e0e3e7' # Indexed Colors # diff --git a/.config/awesome/desktop/rc.lua b/.config/awesome/desktop/rc.lua index e57bd7bc..9298db2b 100644 --- a/.config/awesome/desktop/rc.lua +++ b/.config/awesome/desktop/rc.lua @@ -30,23 +30,27 @@ require("awful.hotkeys_popup.keys") -- OpenWeather API -- !Create file ~/.config/awesome/weather and paste API from OpenWeather, latitude and longitude, each on separate lines -local weather_file = '/home/kristofers/.config/awesome/weather' -- absolute path to `weather` file +local weather_file = "/home/kristofers/.config/awesome/weather" -- absolute path to `weather` file -- see if the file exists local function file_exists(file) - local f = io.open(file, "rb") - if f then f:close() end - return f ~= nil + local f = io.open(file, "rb") + if f then + f:close() + end + return f ~= nil end -- get all lines from a file, returns an empty -- list/table if the file does not exist local function lines_from(file) - if not file_exists(file) then return {} end - local lines = {} - for line in io.lines(file) do - lines[#lines + 1] = line - end - return lines + if not file_exists(file) then + return {} + end + local lines = {} + for line in io.lines(file) do + lines[#lines + 1] = line + end + return lines end local weather_output = lines_from(weather_file) @@ -54,29 +58,34 @@ local API = weather_output[1] local latitude = tonumber(weather_output[2]) local longitude = tonumber(weather_output[3]) - -- {{{ Error handling -- Check if awesome encountered an error during startup and fell back to -- another config (This code will only ever execute for the fallback config) if awesome.startup_errors then - naughty.notify({ preset = naughty.config.presets.critical, - title = "Oops, there were errors during startup!", - text = awesome.startup_errors }) + naughty.notify({ + preset = naughty.config.presets.critical, + title = "Oops, there were errors during startup!", + text = awesome.startup_errors, + }) end -- Handle runtime errors after startup do - local in_error = false - awesome.connect_signal("debug::error", function(err) - -- Make sure we don't go into an endless error loop - if in_error then return end - in_error = true + local in_error = false + awesome.connect_signal("debug::error", function(err) + -- Make sure we don't go into an endless error loop + if in_error then + return + end + in_error = true - naughty.notify({ preset = naughty.config.presets.critical, - title = "Oops, an error happened!", - text = tostring(err) }) - in_error = false - end) + naughty.notify({ + preset = naughty.config.presets.critical, + title = "Oops, an error happened!", + text = tostring(err), + }) + in_error = false + end) end -- }}} @@ -99,42 +108,49 @@ modkey = "Mod4" -- Table of layouts to cover with awful.layout.inc, order matters. awful.layout.layouts = { - awful.layout.suit.tile, - awful.layout.suit.spiral.dwindle, - awful.layout.suit.spiral, - --awful.layout.suit.floating, - --awful.layout.suit.tile.left, - --awful.layout.suit.tile.bottom, - --awful.layout.suit.tile.top, - awful.layout.suit.fair, - --awful.layout.suit.fair.horizontal, - --awful.layout.suit.max, - --awful.layout.suit.max.fullscreen, - --awful.layout.suit.magnifier, - --awful.layout.suit.corner.nw, - --awful.layout.suit.corner.ne, - --awful.layout.suit.corner.sw, - --awful.layout.suit.corner.se, + awful.layout.suit.tile, + awful.layout.suit.spiral.dwindle, + awful.layout.suit.spiral, + --awful.layout.suit.floating, + --awful.layout.suit.tile.left, + --awful.layout.suit.tile.bottom, + --awful.layout.suit.tile.top, + awful.layout.suit.fair, + --awful.layout.suit.fair.horizontal, + --awful.layout.suit.max, + --awful.layout.suit.max.fullscreen, + --awful.layout.suit.magnifier, + --awful.layout.suit.corner.nw, + --awful.layout.suit.corner.ne, + --awful.layout.suit.corner.sw, + --awful.layout.suit.corner.se, } -- }}} -- {{{ Menu -- Create a launcher widget and a main menu myawesomemenu = { - { "hotkeys", function() hotkeys_popup.show_help(nil, awful.screen.focused()) end }, - { "manual", terminal .. " -e man awesome" }, - { "edit config", editor_cmd .. " " .. awesome.conffile }, - { "restart", awesome.restart }, - { "quit", function() awesome.quit() end }, + { + "hotkeys", + function() + hotkeys_popup.show_help(nil, awful.screen.focused()) + end, + }, + { "manual", terminal .. " -e man awesome" }, + { "edit config", editor_cmd .. " " .. awesome.conffile }, + { "restart", awesome.restart }, + { + "quit", + function() + awesome.quit() + end, + }, } -mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon }, - { "open terminal", terminal } -} -}) +mymainmenu = + awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon }, { "open terminal", terminal } } }) -mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon, - menu = mymainmenu }) +mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon, menu = mymainmenu }) -- Menubar configuration menubar.utils.terminal = terminal -- Set the terminal for applications that require it @@ -148,380 +164,406 @@ menubar.utils.terminal = terminal -- Set the terminal for applications that requ mytextclock = wibox.widget.textclock() local cw = calendar_widget({ - theme = 'nord', - placement = "top_right", - previous_month_button = 4, - next_month_button = 5, + theme = "nord", + placement = "top_right", + previous_month_button = 4, + next_month_button = 5, }) -mytextclock:connect_signal("button::press", - function(_, _, _, button) - if button == 1 then cw.toggle() end - end) +mytextclock:connect_signal("button::press", function(_, _, _, button) + if button == 1 then + cw.toggle() + end +end) -- Create a wibox for each screen and add it local taglist_buttons = gears.table.join( - awful.button({}, 1, function(t) t:view_only() end), - awful.button({ modkey }, 1, function(t) - if client.focus then - client.focus:move_to_tag(t) - end - end), - awful.button({}, 3, awful.tag.viewtoggle), - awful.button({ modkey }, 3, function(t) - if client.focus then - client.focus:toggle_tag(t) - end - end), - awful.button({}, 4, function(t) awful.tag.viewnext(t.screen) end), - awful.button({}, 5, function(t) awful.tag.viewprev(t.screen) end) + awful.button({}, 1, function(t) + t:view_only() + end), + awful.button({ modkey }, 1, function(t) + if client.focus then + client.focus:move_to_tag(t) + end + end), + awful.button({}, 3, awful.tag.viewtoggle), + awful.button({ modkey }, 3, function(t) + if client.focus then + client.focus:toggle_tag(t) + end + end), + awful.button({}, 4, function(t) + awful.tag.viewnext(t.screen) + end), + awful.button({}, 5, function(t) + awful.tag.viewprev(t.screen) + end) ) local tasklist_buttons = gears.table.join( - awful.button({}, 1, function(c) - if c == client.focus then - c.minimized = true - else - c:emit_signal( - "request::activate", - "tasklist", - { raise = true } - ) - end - end), - awful.button({}, 3, function() - awful.menu.client_list({ theme = { width = 250 } }) - end), - awful.button({}, 4, function() - awful.client.focus.byidx(1) - end), - awful.button({}, 5, function() - awful.client.focus.byidx(-1) - end)) + awful.button({}, 1, function(c) + if c == client.focus then + c.minimized = true + else + c:emit_signal("request::activate", "tasklist", { raise = true }) + end + end), + awful.button({}, 3, function() + awful.menu.client_list({ theme = { width = 250 } }) + end), + awful.button({}, 4, function() + awful.client.focus.byidx(1) + end), + awful.button({}, 5, function() + awful.client.focus.byidx(-1) + end) +) local function set_wallpaper(s) - -- Wallpaper - if beautiful.wallpaper then - local wallpaper = beautiful.wallpaper - -- If wallpaper is a function, call it with the screen - if type(wallpaper) == "function" then - wallpaper = wallpaper(s) - end - gears.wallpaper.maximized(wallpaper, s, true) - end + -- Wallpaper + if beautiful.wallpaper then + local wallpaper = beautiful.wallpaper + -- If wallpaper is a function, call it with the screen + if type(wallpaper) == "function" then + wallpaper = wallpaper(s) + end + gears.wallpaper.maximized(wallpaper, s, true) + end end -- Re-set wallpaper when a screen's geometry changes (e.g. different resolution) screen.connect_signal("property::geometry", set_wallpaper) awful.screen.connect_for_each_screen(function(s) - -- Wallpaper - set_wallpaper(s) + -- Wallpaper + set_wallpaper(s) - -- Each screen has its own tag table. - awful.tag({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, s, awful.layout.layouts[1]) + -- Each screen has its own tag table. + awful.tag({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, s, awful.layout.layouts[1]) - -- Create a promptbox for each screen - s.mypromptbox = awful.widget.prompt() - -- Create an imagebox widget which will contain an icon indicating which layout we're using. - -- We need one layoutbox per screen. - s.mylayoutbox = awful.widget.layoutbox(s) - s.mylayoutbox:buttons(gears.table.join( - awful.button({}, 1, function() awful.layout.inc(1) end), - awful.button({}, 3, function() awful.layout.inc(-1) end), - awful.button({}, 4, function() awful.layout.inc(1) end), - awful.button({}, 5, function() awful.layout.inc(-1) end))) - -- Create a taglist widget - s.mytaglist = awful.widget.taglist { - screen = s, - filter = awful.widget.taglist.filter.all, - buttons = taglist_buttons - } + -- Create a promptbox for each screen + s.mypromptbox = awful.widget.prompt() + -- Create an imagebox widget which will contain an icon indicating which layout we're using. + -- We need one layoutbox per screen. + s.mylayoutbox = awful.widget.layoutbox(s) + s.mylayoutbox:buttons(gears.table.join( + awful.button({}, 1, function() + awful.layout.inc(1) + end), + awful.button({}, 3, function() + awful.layout.inc(-1) + end), + awful.button({}, 4, function() + awful.layout.inc(1) + end), + awful.button({}, 5, function() + awful.layout.inc(-1) + end) + )) + -- Create a taglist widget + s.mytaglist = awful.widget.taglist({ + screen = s, + filter = awful.widget.taglist.filter.all, + buttons = taglist_buttons, + }) - -- Create a tasklist widget - s.mytasklist = awful.widget.tasklist { - screen = s, - filter = awful.widget.tasklist.filter.currenttags, - buttons = tasklist_buttons - } + -- Create a tasklist widget + s.mytasklist = awful.widget.tasklist({ + screen = s, + filter = awful.widget.tasklist.filter.currenttags, + buttons = tasklist_buttons, + }) - -- Create the wibox - s.mywibox = awful.wibar({ position = "top", screen = s }) + -- Create the wibox + s.mywibox = awful.wibar({ position = "top", screen = s }) - -- Add widgets to the wibox - s.mywibox:setup { - layout = wibox.layout.align.horizontal, - { -- Left widgets - layout = wibox.layout.fixed.horizontal, - --mylauncher, - s.mytaglist, - s.mypromptbox, - }, - s.mytasklist, -- Middle widget - { -- Right widgets - layout = wibox.layout.fixed.horizontal, - wibox.widget.systray(), - cpu_widget(), - ram_widget(), - net_speed_widget(), - spotify_widget({ - dim_when_paused = true, - dim_opacity = 0.5, - max_lenght = -1, - }), - weather_widget({ - api_key = API, - coordinates = { latitude, longitude }, - show_daily_forecast = true, - }), - --volume_widget{ - --widget_type = 'arc', - --mixer_cmd = 'pulsemixer', - --}, - -- logout_menu_widget(), - mytextclock, - s.mylayoutbox, - }, - } + -- Add widgets to the wibox + s.mywibox:setup({ + layout = wibox.layout.align.horizontal, + { -- Left widgets + layout = wibox.layout.fixed.horizontal, + --mylauncher, + s.mytaglist, + s.mypromptbox, + }, + s.mytasklist, -- Middle widget + { -- Right widgets + layout = wibox.layout.fixed.horizontal, + wibox.widget.systray(), + cpu_widget(), + ram_widget(), + net_speed_widget(), + spotify_widget({ + dim_when_paused = true, + dim_opacity = 0.5, + max_lenght = -1, + }), + weather_widget({ + api_key = API, + coordinates = { latitude, longitude }, + show_daily_forecast = true, + }), + --volume_widget{ + --widget_type = 'arc', + --mixer_cmd = 'pulsemixer', + --}, + -- logout_menu_widget(), + mytextclock, + s.mylayoutbox, + }, + }) end) -- }}} -- {{{ Mouse bindings root.buttons(gears.table.join( - awful.button({}, 3, function() mymainmenu:toggle() end), - awful.button({}, 4, awful.tag.viewnext), - awful.button({}, 5, awful.tag.viewprev) + awful.button({}, 3, function() + mymainmenu:toggle() + end), + awful.button({}, 4, awful.tag.viewnext), + awful.button({}, 5, awful.tag.viewprev) )) -- }}} -- {{{ Key bindings globalkeys = gears.table.join( - awful.key({}, "Pause", function() awful.spawn.with_shell("playerctl -a play-pause") end, - { description = "pause/play", group = "media controls" }), + awful.key({}, "Pause", function() + awful.spawn.with_shell("playerctl -a play-pause") + end, { description = "pause/play", group = "media controls" }), - awful.key({ "Control" }, "Pause", function() awful.spawn.with_shell("playerctl -a pause") end, - { description = "pause all", group = "media controls" }), + awful.key({ "Control" }, "Pause", function() + awful.spawn.with_shell("playerctl -a pause") + end, { description = "pause all", group = "media controls" }), - awful.key({}, "#117", function() awful.spawn.with_shell("playerctl next") end, - { description = "play next", group = "media controls" }), + awful.key({}, "#117", function() + awful.spawn.with_shell("playerctl next") + end, { description = "play next", group = "media controls" }), - awful.key({}, "#112", function() awful.spawn.with_shell("playerctl previous") end, - { description = "play previous", group = "media controls" }), + awful.key({}, "#112", function() + awful.spawn.with_shell("playerctl previous") + end, { description = "play previous", group = "media controls" }), - --awful.key( {}, "#123", function () volume_widget:inc(5) end ), -- increase volume - --awful.key( {}, "#122", function () volume_widget:dec(5) end ), -- decrease volume - --awful.key( {}, "#121", function () volume_widget:toggle() end ), -- mute + --awful.key( {}, "#123", function () volume_widget:inc(5) end ), -- increase volume + --awful.key( {}, "#122", function () volume_widget:dec(5) end ), -- decrease volume + --awful.key( {}, "#121", function () volume_widget:toggle() end ), -- mute + awful.key({}, "#123", function() + awful.spawn.with_shell("pulsemixer --change-volume +5") + end), -- increase volume + awful.key({}, "#122", function() + awful.spawn.with_shell("pulsemixer --change-volume -5") + end), -- decrease volume + awful.key({}, "#121", function() + awful.spawn.with_shell("pulsemixer --toggle-mute") + end), -- mute + awful.key({}, "#171", function() + awful.spawn.with_shell("playerctl next") + end), -- play next + awful.key({}, "#173", function() + awful.spawn.with_shell("playerctl previous") + end), -- play previous + awful.key({}, "#174", function() + awful.spawn.with_shell("playerctl -a stop") + end), -- stop + awful.key({}, "#172", function() + awful.spawn.with_shell("playerctl -a play-pause") + end), -- play/pause - awful.key({}, "#123", function() awful.spawn.with_shell("pulsemixer --change-volume +5") end), -- increase volume - awful.key({}, "#122", function() awful.spawn.with_shell("pulsemixer --change-volume -5") end), -- decrease volume - awful.key({}, "#121", function() awful.spawn.with_shell("pulsemixer --toggle-mute") end), -- mute - awful.key({}, "#171", function() awful.spawn.with_shell("playerctl next") end), -- play next - awful.key({}, "#173", function() awful.spawn.with_shell("playerctl previous") end), -- play previous - awful.key({}, "#174", function() awful.spawn.with_shell("playerctl -a stop") end), -- stop - awful.key({}, "#172", function() awful.spawn.with_shell("playerctl -a play-pause") end), -- play/pause + awful.key({ "Control" }, "#107", function() + awful.spawn.with_shell("flameshot gui") + end, { description = "take region screenshot", group = "launcher" }), -- take region screenshot - awful.key({ "Control" }, "#107", function() awful.spawn.with_shell("flameshot gui") end, - { description = "take region screenshot", group = "launcher" }), -- take region screenshot + awful.key({ modkey }, "s", hotkeys_popup.show_help, { description = "show help", group = "awesome" }), + awful.key({ modkey }, "Left", awful.tag.viewprev, { description = "view previous", group = "tag" }), + awful.key({ modkey }, "Right", awful.tag.viewnext, { description = "view next", group = "tag" }), + awful.key({ modkey }, "Escape", awful.tag.history.restore, { description = "go back", group = "tag" }), - awful.key({ modkey, }, "s", hotkeys_popup.show_help, - { description = "show help", group = "awesome" }), - awful.key({ modkey, }, "Left", awful.tag.viewprev, - { description = "view previous", group = "tag" }), - awful.key({ modkey, }, "Right", awful.tag.viewnext, - { description = "view next", group = "tag" }), - awful.key({ modkey, }, "Escape", awful.tag.history.restore, - { description = "go back", group = "tag" }), + awful.key({ modkey }, "j", function() + awful.client.focus.byidx(1) + end, { description = "focus next by index", group = "client" }), + awful.key({ modkey }, "k", function() + awful.client.focus.byidx(-1) + end, { description = "focus previous by index", group = "client" }), + awful.key({ modkey }, "w", function() + mymainmenu:show() + end, { description = "show main menu", group = "awesome" }), - awful.key({ modkey, }, "j", - function() - awful.client.focus.byidx(1) - end, - { description = "focus next by index", group = "client" } - ), - awful.key({ modkey, }, "k", - function() - awful.client.focus.byidx(-1) - end, - { description = "focus previous by index", group = "client" } - ), - awful.key({ modkey, }, "w", function() mymainmenu:show() end, - { description = "show main menu", group = "awesome" }), + -- Layout manipulation + awful.key({ modkey, "Shift" }, "j", function() + awful.client.swap.byidx(1) + end, { description = "swap with next client by index", group = "client" }), + awful.key({ modkey, "Shift" }, "k", function() + awful.client.swap.byidx(-1) + end, { description = "swap with previous client by index", group = "client" }), + awful.key({ modkey, "Control" }, "j", function() + awful.screen.focus_relative(1) + end, { description = "focus the next screen", group = "screen" }), + awful.key({ modkey, "Control" }, "k", function() + awful.screen.focus_relative(-1) + end, { description = "focus the previous screen", group = "screen" }), + awful.key({ modkey }, "u", awful.client.urgent.jumpto, { description = "jump to urgent client", group = "client" }), + awful.key({ modkey }, "Tab", function() + awful.client.focus.history.previous() + if client.focus then + client.focus:raise() + end + end, { description = "go back", group = "client" }), - -- Layout manipulation - awful.key({ modkey, "Shift" }, "j", function() awful.client.swap.byidx(1) end, - { description = "swap with next client by index", group = "client" }), - awful.key({ modkey, "Shift" }, "k", function() awful.client.swap.byidx(-1) end, - { description = "swap with previous client by index", group = "client" }), - awful.key({ modkey, "Control" }, "j", function() awful.screen.focus_relative(1) end, - { description = "focus the next screen", group = "screen" }), - awful.key({ modkey, "Control" }, "k", function() awful.screen.focus_relative(-1) end, - { description = "focus the previous screen", group = "screen" }), - awful.key({ modkey, }, "u", awful.client.urgent.jumpto, - { description = "jump to urgent client", group = "client" }), - awful.key({ modkey, }, "Tab", - function() - awful.client.focus.history.previous() - if client.focus then - client.focus:raise() - end - end, - { description = "go back", group = "client" }), + -- Standard program + awful.key({ modkey }, "Return", function() + awful.spawn(terminal) + end, { description = "open a terminal", group = "launcher" }), + awful.key({ modkey, "Control" }, "r", awesome.restart, { description = "reload awesome", group = "awesome" }), + -- awful.key({ modkey, "Control" }, "q", awesome.quit, + -- {description = "quit awesome", group = "awesome"}), + awful.key({ modkey }, "b", function() + awful.spawn("firefox") + end, { description = "open firefox", group = "launcher" }), + awful.key({ modkey }, "n", function() + awful.spawn("spacefm") + end, { description = "open spacefm", group = "launcher" }), - -- Standard program - awful.key({ modkey, }, "Return", function() awful.spawn(terminal) end, - { description = "open a terminal", group = "launcher" }), - awful.key({ modkey, "Control" }, "r", awesome.restart, - { description = "reload awesome", group = "awesome" }), - -- awful.key({ modkey, "Control" }, "q", awesome.quit, - -- {description = "quit awesome", group = "awesome"}), - awful.key({ modkey, }, "b", function() awful.spawn("firefox") end, - { description = "open firefox", group = "launcher" }), - awful.key({ modkey, }, "n", function() awful.spawn("spacefm") end, - { description = "open spacefm", group = "launcher" }), + awful.key({ modkey }, "l", function() + awful.tag.incmwfact(0.05) + end, { description = "increase master width factor", group = "layout" }), + awful.key({ modkey }, "h", function() + awful.tag.incmwfact(-0.05) + end, { description = "decrease master width factor", group = "layout" }), + awful.key({ modkey, "Shift" }, "h", function() + awful.tag.incnmaster(1, nil, true) + end, { description = "increase the number of master clients", group = "layout" }), + awful.key({ modkey, "Shift" }, "l", function() + awful.tag.incnmaster(-1, nil, true) + end, { description = "decrease the number of master clients", group = "layout" }), + awful.key({ modkey, "Control" }, "h", function() + awful.tag.incncol(1, nil, true) + end, { description = "increase the number of columns", group = "layout" }), + awful.key({ modkey, "Control" }, "l", function() + awful.tag.incncol(-1, nil, true) + end, { description = "decrease the number of columns", group = "layout" }), + awful.key({ modkey }, "space", function() + awful.layout.inc(1) + end, { description = "select next", group = "layout" }), + awful.key({ modkey, "Shift" }, "space", function() + awful.layout.inc(-1) + end, { description = "select previous", group = "layout" }), - awful.key({ modkey, }, "l", function() awful.tag.incmwfact(0.05) end, - { description = "increase master width factor", group = "layout" }), - awful.key({ modkey, }, "h", function() awful.tag.incmwfact(-0.05) end, - { description = "decrease master width factor", group = "layout" }), - awful.key({ modkey, "Shift" }, "h", function() awful.tag.incnmaster(1, nil, true) end, - { description = "increase the number of master clients", group = "layout" }), - awful.key({ modkey, "Shift" }, "l", function() awful.tag.incnmaster(-1, nil, true) end, - { description = "decrease the number of master clients", group = "layout" }), - awful.key({ modkey, "Control" }, "h", function() awful.tag.incncol(1, nil, true) end, - { description = "increase the number of columns", group = "layout" }), - awful.key({ modkey, "Control" }, "l", function() awful.tag.incncol(-1, nil, true) end, - { description = "decrease the number of columns", group = "layout" }), - awful.key({ modkey, }, "space", function() awful.layout.inc(1) end, - { description = "select next", group = "layout" }), - awful.key({ modkey, "Shift" }, "space", function() awful.layout.inc(-1) end, - { description = "select previous", group = "layout" }), + -- Prompt + awful.key({ modkey }, "r", function() + awful.screen.focused().mypromptbox:run() + end, { description = "run prompt", group = "launcher" }), - -- Prompt - awful.key({ modkey }, "r", function() awful.screen.focused().mypromptbox:run() end, - { description = "run prompt", group = "launcher" }), - - awful.key({ modkey }, "x", - function() - awful.prompt.run { - prompt = "Run Lua code: ", - textbox = awful.screen.focused().mypromptbox.widget, - exe_callback = awful.util.eval, - history_path = awful.util.get_cache_dir() .. "/history_eval" - } - end, - { description = "lua execute prompt", group = "awesome" }), - -- Menubar - awful.key({ modkey }, "p", function() menubar.show() end, - { description = "show the menubar", group = "launcher" }) + awful.key({ modkey }, "x", function() + awful.prompt.run({ + prompt = "Run Lua code: ", + textbox = awful.screen.focused().mypromptbox.widget, + exe_callback = awful.util.eval, + history_path = awful.util.get_cache_dir() .. "/history_eval", + }) + end, { description = "lua execute prompt", group = "awesome" }), + -- Menubar + awful.key({ modkey }, "p", function() + menubar.show() + end, { description = "show the menubar", group = "launcher" }) ) clientkeys = gears.table.join( - awful.key({ modkey, }, "f", - function(c) - c.fullscreen = not c.fullscreen - c:raise() - end, - { description = "toggle fullscreen", group = "client" }), - awful.key({ modkey, "Shift" }, "q", function(c) c:kill() end, - { description = "close", group = "client" }), - awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle, - { description = "toggle floating", group = "client" }), - awful.key({ modkey, "Control" }, "Return", function(c) c:swap(awful.client.getmaster()) end, - { description = "move to master", group = "client" }), - awful.key({ modkey, }, "o", function(c) c:move_to_screen() end, - { description = "move to screen", group = "client" }), - awful.key({ modkey, }, "t", function(c) c.ontop = not c.ontop end, - { description = "toggle keep on top", group = "client" }), - awful.key({ modkey, }, "n", - function(c) - -- The client currently has the input focus, so it cannot be - -- minimized, since minimized clients can't have the focus. - c.minimized = true - end, - { description = "minimize", group = "client" }), - awful.key({ modkey, }, "m", - function(c) - c.maximized = not c.maximized - c:raise() - end, - { description = "(un)maximize", group = "client" }), - awful.key({ modkey, "Control" }, "m", - function(c) - c.maximized_vertical = not c.maximized_vertical - c:raise() - end, - { description = "(un)maximize vertically", group = "client" }), - awful.key({ modkey, "Shift" }, "m", - function(c) - c.maximized_horizontal = not c.maximized_horizontal - c:raise() - end, - { description = "(un)maximize horizontally", group = "client" }) + awful.key({ modkey }, "f", function(c) + c.fullscreen = not c.fullscreen + c:raise() + end, { description = "toggle fullscreen", group = "client" }), + awful.key({ modkey, "Shift" }, "q", function(c) + c:kill() + end, { description = "close", group = "client" }), + awful.key( + { modkey, "Control" }, + "space", + awful.client.floating.toggle, + { description = "toggle floating", group = "client" } + ), + awful.key({ modkey, "Control" }, "Return", function(c) + c:swap(awful.client.getmaster()) + end, { description = "move to master", group = "client" }), + awful.key({ modkey }, "o", function(c) + c:move_to_screen() + end, { description = "move to screen", group = "client" }), + awful.key({ modkey }, "t", function(c) + c.ontop = not c.ontop + end, { description = "toggle keep on top", group = "client" }), + awful.key({ modkey }, "n", function(c) + -- The client currently has the input focus, so it cannot be + -- minimized, since minimized clients can't have the focus. + c.minimized = true + end, { description = "minimize", group = "client" }), + awful.key({ modkey }, "m", function(c) + c.maximized = not c.maximized + c:raise() + end, { description = "(un)maximize", group = "client" }), + awful.key({ modkey, "Control" }, "m", function(c) + c.maximized_vertical = not c.maximized_vertical + c:raise() + end, { description = "(un)maximize vertically", group = "client" }), + awful.key({ modkey, "Shift" }, "m", function(c) + c.maximized_horizontal = not c.maximized_horizontal + c:raise() + end, { description = "(un)maximize horizontally", group = "client" }) ) -- Bind all key numbers to tags. -- Be careful: we use keycodes to make it work on any keyboard layout. -- This should map on the top row of your keyboard, usually 1 to 9. for i = 1, 9 do - globalkeys = gears.table.join(globalkeys, - -- View tag only. - awful.key({ modkey }, "#" .. i + 9, - function() - local screen = awful.screen.focused() - local tag = screen.tags[i] - if tag then - tag:view_only() - end - end, - { description = "view tag #" .. i, group = "tag" }), - -- Toggle tag display. - awful.key({ modkey, "Control" }, "#" .. i + 9, - function() - local screen = awful.screen.focused() - local tag = screen.tags[i] - if tag then - awful.tag.viewtoggle(tag) - end - end, - { description = "toggle tag #" .. i, group = "tag" }), - -- Move client to tag. - awful.key({ modkey, "Shift" }, "#" .. i + 9, - function() - if client.focus then - local tag = client.focus.screen.tags[i] - if tag then - client.focus:move_to_tag(tag) - end - end - end, - { description = "move focused client to tag #" .. i, group = "tag" }), - -- Toggle tag on focused client. - awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9, - function() - if client.focus then - local tag = client.focus.screen.tags[i] - if tag then - client.focus:toggle_tag(tag) - end - end - end, - { description = "toggle focused client on tag #" .. i, group = "tag" }) - ) + globalkeys = gears.table.join( + globalkeys, + -- View tag only. + awful.key({ modkey }, "#" .. i + 9, function() + local screen = awful.screen.focused() + local tag = screen.tags[i] + if tag then + tag:view_only() + end + end, { description = "view tag #" .. i, group = "tag" }), + -- Toggle tag display. + awful.key({ modkey, "Control" }, "#" .. i + 9, function() + local screen = awful.screen.focused() + local tag = screen.tags[i] + if tag then + awful.tag.viewtoggle(tag) + end + end, { description = "toggle tag #" .. i, group = "tag" }), + -- Move client to tag. + awful.key({ modkey, "Shift" }, "#" .. i + 9, function() + if client.focus then + local tag = client.focus.screen.tags[i] + if tag then + client.focus:move_to_tag(tag) + end + end + end, { description = "move focused client to tag #" .. i, group = "tag" }), + -- Toggle tag on focused client. + awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9, function() + if client.focus then + local tag = client.focus.screen.tags[i] + if tag then + client.focus:toggle_tag(tag) + end + end + end, { description = "toggle focused client on tag #" .. i, group = "tag" }) + ) end clientbuttons = gears.table.join( - awful.button({}, 1, function(c) - c:emit_signal("request::activate", "mouse_click", { raise = true }) - end), - awful.button({ modkey }, 1, function(c) - c:emit_signal("request::activate", "mouse_click", { raise = true }) - awful.mouse.client.move(c) - end), - awful.button({ modkey }, 3, function(c) - c:emit_signal("request::activate", "mouse_click", { raise = true }) - awful.mouse.client.resize(c) - end) + awful.button({}, 1, function(c) + c:emit_signal("request::activate", "mouse_click", { raise = true }) + end), + awful.button({ modkey }, 1, function(c) + c:emit_signal("request::activate", "mouse_click", { raise = true }) + awful.mouse.client.move(c) + end), + awful.button({ modkey }, 3, function(c) + c:emit_signal("request::activate", "mouse_click", { raise = true }) + awful.mouse.client.resize(c) + end) ) -- Set keys @@ -531,136 +573,141 @@ root.keys(globalkeys) -- {{{ Rules -- Rules to apply to new clients (through the "manage" signal). awful.rules.rules = { - -- All clients will match this rule. - { rule = {}, - properties = { border_width = beautiful.border_width, - border_color = beautiful.border_normal, - focus = awful.client.focus.filter, - raise = true, - keys = clientkeys, - -- buttons = clientbuttons, - screen = awful.screen.preferred, - --placement = awful.placement.no_overlap+awful.placement.no_offscreen - } - }, + -- All clients will match this rule. + { + rule = {}, + properties = { + border_width = beautiful.border_width, + border_color = beautiful.border_normal, + focus = awful.client.focus.filter, + raise = true, + keys = clientkeys, + -- buttons = clientbuttons, + screen = awful.screen.preferred, + --placement = awful.placement.no_overlap+awful.placement.no_offscreen + }, + }, - -- Floating clients. - { rule_any = { - instance = { - "DTA", -- Firefox addon DownThemAll. - "copyq", -- Includes session name in class. - "pinentry", - }, - class = { - "Arandr", - "Blueman-manager", - "Gpick", - "Kruler", - "MessageWin", -- kalarm. - "Sxiv", - "Tor Browser", -- Needs a fixed window size to avoid fingerprinting by screen size. - "Wpa_gui", - "veromix", - "xtightvncviewer" }, + -- Floating clients. + { + rule_any = { + instance = { + "DTA", -- Firefox addon DownThemAll. + "copyq", -- Includes session name in class. + "pinentry", + }, + class = { + "Arandr", + "Blueman-manager", + "Gpick", + "Kruler", + "MessageWin", -- kalarm. + "Sxiv", + "Tor Browser", -- Needs a fixed window size to avoid fingerprinting by screen size. + "Wpa_gui", + "veromix", + "xtightvncviewer", + }, - -- Note that the name property shown in xprop might be set slightly after creation of the client - -- and the name shown there might not match defined rules here. - name = { - "Event Tester", -- xev. - }, - role = { - "AlarmWindow", -- Thunderbird's calendar. - "ConfigManager", -- Thunderbird's about:config. - "pop-up", -- e.g. Google Chrome's (detached) Developer Tools. - } - }, properties = { floating = true, beautiful.useless } }, + -- Note that the name property shown in xprop might be set slightly after creation of the client + -- and the name shown there might not match defined rules here. + name = { + "Event Tester", -- xev. + }, + role = { + "AlarmWindow", -- Thunderbird's calendar. + "ConfigManager", -- Thunderbird's about:config. + "pop-up", -- e.g. Google Chrome's (detached) Developer Tools. + }, + }, + properties = { floating = true, beautiful.useless }, + }, - -- Add titlebars to normal clients and dialogs - { rule_any = { type = { "normal", "dialog" } - }, properties = { titlebars_enabled = false } - }, + -- Add titlebars to normal clients and dialogs + { rule_any = { type = { "normal", "dialog" } }, properties = { titlebars_enabled = false } }, - { - rule_any = { - class = { "discord", "TelegramDesktop", "Ripcord" } - }, properties = { screen = 2, tag = "8" } - }, - - { - rule_any = { - class = { "spotify", "Spotify" }, - name = { "Spotify" } - }, properties = { screen = 2, tag = "9" } - }, + { + rule_any = { + class = { "discord", "TelegramDesktop", "Ripcord" }, + }, + properties = { screen = 2, tag = "8" }, + }, + { + rule_any = { + class = { "spotify", "Spotify" }, + name = { "Spotify" }, + }, + properties = { screen = 2, tag = "9" }, + }, } -- {{{ Signals -- Signal function to execute when a new client appears. client.connect_signal("manage", function(c) - -- Set the windows at the slave, - -- i.e. put it at the end of others instead of setting it master. - -- if not awesome.startup then awful.client.setslave(c) end + -- Set the windows at the slave, + -- i.e. put it at the end of others instead of setting it master. + -- if not awesome.startup then awful.client.setslave(c) end - if awesome.startup - and not c.size_hints.user_position - and not c.size_hints.program_position then - -- Prevent clients from being unreachable after screen count changes. - awful.placement.no_offscreen(c) - end + if awesome.startup and not c.size_hints.user_position and not c.size_hints.program_position then + -- Prevent clients from being unreachable after screen count changes. + awful.placement.no_offscreen(c) + end end) -- Add a titlebar if titlebars_enabled is set to true in the rules. client.connect_signal("request::titlebars", function(c) - -- buttons for the titlebar - local buttons = gears.table.join( - awful.button({}, 1, function() - c:emit_signal("request::activate", "titlebar", { raise = true }) - awful.mouse.client.move(c) - end), - awful.button({}, 3, function() - c:emit_signal("request::activate", "titlebar", { raise = true }) - awful.mouse.client.resize(c) - end) - ) + -- buttons for the titlebar + local buttons = gears.table.join( + awful.button({}, 1, function() + c:emit_signal("request::activate", "titlebar", { raise = true }) + awful.mouse.client.move(c) + end), + awful.button({}, 3, function() + c:emit_signal("request::activate", "titlebar", { raise = true }) + awful.mouse.client.resize(c) + end) + ) - awful.titlebar(c):setup { - { -- Left - awful.titlebar.widget.iconwidget(c), - buttons = buttons, - layout = wibox.layout.fixed.horizontal - }, - { -- Middle - { -- Title - align = "center", - widget = awful.titlebar.widget.titlewidget(c) - }, - buttons = buttons, - layout = wibox.layout.flex.horizontal - }, - { -- Right - awful.titlebar.widget.floatingbutton(c), - awful.titlebar.widget.maximizedbutton(c), - awful.titlebar.widget.stickybutton(c), - awful.titlebar.widget.ontopbutton(c), - awful.titlebar.widget.closebutton(c), - layout = wibox.layout.fixed.horizontal() - }, - layout = wibox.layout.align.horizontal - } + awful.titlebar(c):setup({ + { -- Left + awful.titlebar.widget.iconwidget(c), + buttons = buttons, + layout = wibox.layout.fixed.horizontal, + }, + { -- Middle + { -- Title + align = "center", + widget = awful.titlebar.widget.titlewidget(c), + }, + buttons = buttons, + layout = wibox.layout.flex.horizontal, + }, + { -- Right + awful.titlebar.widget.floatingbutton(c), + awful.titlebar.widget.maximizedbutton(c), + awful.titlebar.widget.stickybutton(c), + awful.titlebar.widget.ontopbutton(c), + awful.titlebar.widget.closebutton(c), + layout = wibox.layout.fixed.horizontal(), + }, + layout = wibox.layout.align.horizontal, + }) end) -- Enable sloppy focus, so that focus follows mouse. client.connect_signal("mouse::enter", function(c) - c:emit_signal("request::activate", "mouse_enter", { raise = false }) + c:emit_signal("request::activate", "mouse_enter", { raise = false }) end) -client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end) -client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end) +client.connect_signal("focus", function(c) + c.border_color = beautiful.border_focus +end) +client.connect_signal("unfocus", function(c) + c.border_color = beautiful.border_normal +end) -- }}} - - -- Autostart Applications awful.spawn.with_shell("picom --experimental-backends") awful.spawn.with_shell("setxkbmap lv") diff --git a/.config/awesome/json.lua b/.config/awesome/json.lua index 223c0a80..d8ee08eb 100644 --- a/.config/awesome/json.lua +++ b/.config/awesome/json.lua @@ -31,103 +31,101 @@ local json = { _version = "0.1.2" } local encode local escape_char_map = { - ["\\"] = "\\", - ["\""] = "\"", - ["\b"] = "b", - ["\f"] = "f", - ["\n"] = "n", - ["\r"] = "r", - ["\t"] = "t", + ["\\"] = "\\", + ['"'] = '"', + ["\b"] = "b", + ["\f"] = "f", + ["\n"] = "n", + ["\r"] = "r", + ["\t"] = "t", } local escape_char_map_inv = { ["/"] = "/" } for k, v in pairs(escape_char_map) do - escape_char_map_inv[v] = k + escape_char_map_inv[v] = k end - local function escape_char(c) - return "\\" .. (escape_char_map[c] or string.format("u%04x", c:byte())) + return "\\" .. (escape_char_map[c] or string.format("u%04x", c:byte())) end local function encode_nil(val) - return "null" + return "null" end local function encode_table(val, stack) - local res = {} - stack = stack or {} + local res = {} + stack = stack or {} - -- Circular reference? - if stack[val] then error("circular reference") end + -- Circular reference? + if stack[val] then + error("circular reference") + end - stack[val] = true + stack[val] = true - if rawget(val, 1) ~= nil or next(val) == nil then - -- Treat as array -- check keys are valid and it is not sparse - local n = 0 - for k in pairs(val) do - if type(k) ~= "number" then - error("invalid table: mixed or invalid key types") - end - n = n + 1 - end - if n ~= #val then - error("invalid table: sparse array") - end - -- Encode - for i, v in ipairs(val) do - table.insert(res, encode(v, stack)) - end - stack[val] = nil - return "[" .. table.concat(res, ",") .. "]" - - else - -- Treat as an object - for k, v in pairs(val) do - if type(k) ~= "string" then - error("invalid table: mixed or invalid key types") - end - table.insert(res, encode(k, stack) .. ":" .. encode(v, stack)) - end - stack[val] = nil - return "{" .. table.concat(res, ",") .. "}" - end + if rawget(val, 1) ~= nil or next(val) == nil then + -- Treat as array -- check keys are valid and it is not sparse + local n = 0 + for k in pairs(val) do + if type(k) ~= "number" then + error("invalid table: mixed or invalid key types") + end + n = n + 1 + end + if n ~= #val then + error("invalid table: sparse array") + end + -- Encode + for i, v in ipairs(val) do + table.insert(res, encode(v, stack)) + end + stack[val] = nil + return "[" .. table.concat(res, ",") .. "]" + else + -- Treat as an object + for k, v in pairs(val) do + if type(k) ~= "string" then + error("invalid table: mixed or invalid key types") + end + table.insert(res, encode(k, stack) .. ":" .. encode(v, stack)) + end + stack[val] = nil + return "{" .. table.concat(res, ",") .. "}" + end end local function encode_string(val) - return '"' .. val:gsub('[%z\1-\31\\"]', escape_char) .. '"' + return '"' .. val:gsub('[%z\1-\31\\"]', escape_char) .. '"' end local function encode_number(val) - -- Check for NaN, -inf and inf - if val ~= val or val <= -math.huge or val >= math.huge then - error("unexpected number value '" .. tostring(val) .. "'") - end - return string.format("%.14g", val) + -- Check for NaN, -inf and inf + if val ~= val or val <= -math.huge or val >= math.huge then + error("unexpected number value '" .. tostring(val) .. "'") + end + return string.format("%.14g", val) end local type_func_map = { - ["nil"] = encode_nil, - ["table"] = encode_table, - ["string"] = encode_string, - ["number"] = encode_number, - ["boolean"] = tostring, + ["nil"] = encode_nil, + ["table"] = encode_table, + ["string"] = encode_string, + ["number"] = encode_number, + ["boolean"] = tostring, } - encode = function(val, stack) - local t = type(val) - local f = type_func_map[t] - if f then - return f(val, stack) - end - error("unexpected type '" .. t .. "'") + local t = type(val) + local f = type_func_map[t] + if f then + return f(val, stack) + end + error("unexpected type '" .. t .. "'") end - function json.encode(val) - return (encode(val)) + return (encode(val)) end ------------------------------------------------------------------------------- @@ -137,236 +135,238 @@ end local parse local function create_set(...) - local res = {} - for i = 1, select("#", ...) do - res[select(i, ...)] = true - end - return res + local res = {} + for i = 1, select("#", ...) do + res[select(i, ...)] = true + end + return res end -local space_chars = create_set(" ", "\t", "\r", "\n") -local delim_chars = create_set(" ", "\t", "\r", "\n", "]", "}", ",") +local space_chars = create_set(" ", "\t", "\r", "\n") +local delim_chars = create_set(" ", "\t", "\r", "\n", "]", "}", ",") local escape_chars = create_set("\\", "/", '"', "b", "f", "n", "r", "t", "u") -local literals = create_set("true", "false", "null") +local literals = create_set("true", "false", "null") local literal_map = { - ["true"] = true, - ["false"] = false, - ["null"] = nil, + ["true"] = true, + ["false"] = false, + ["null"] = nil, } - local function next_char(str, idx, set, negate) - for i = idx, #str do - if set[str:sub(i, i)] ~= negate then - return i - end - end - return #str + 1 + for i = idx, #str do + if set[str:sub(i, i)] ~= negate then + return i + end + end + return #str + 1 end local function decode_error(str, idx, msg) - local line_count = 1 - local col_count = 1 - for i = 1, idx - 1 do - col_count = col_count + 1 - if str:sub(i, i) == "\n" then - line_count = line_count + 1 - col_count = 1 - end - end - error(string.format("%s at line %d col %d", msg, line_count, col_count)) + local line_count = 1 + local col_count = 1 + for i = 1, idx - 1 do + col_count = col_count + 1 + if str:sub(i, i) == "\n" then + line_count = line_count + 1 + col_count = 1 + end + end + error(string.format("%s at line %d col %d", msg, line_count, col_count)) end local function codepoint_to_utf8(n) - -- http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=iws-appendixa - local f = math.floor - if n <= 0x7f then - return string.char(n) - elseif n <= 0x7ff then - return string.char(f(n / 64) + 192, n % 64 + 128) - elseif n <= 0xffff then - return string.char(f(n / 4096) + 224, f(n % 4096 / 64) + 128, n % 64 + 128) - elseif n <= 0x10ffff then - return string.char(f(n / 262144) + 240, f(n % 262144 / 4096) + 128, - f(n % 4096 / 64) + 128, n % 64 + 128) - end - error(string.format("invalid unicode codepoint '%x'", n)) + -- http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=iws-appendixa + local f = math.floor + if n <= 0x7f then + return string.char(n) + elseif n <= 0x7ff then + return string.char(f(n / 64) + 192, n % 64 + 128) + elseif n <= 0xffff then + return string.char(f(n / 4096) + 224, f(n % 4096 / 64) + 128, n % 64 + 128) + elseif n <= 0x10ffff then + return string.char(f(n / 262144) + 240, f(n % 262144 / 4096) + 128, f(n % 4096 / 64) + 128, n % 64 + 128) + end + error(string.format("invalid unicode codepoint '%x'", n)) end local function parse_unicode_escape(s) - local n1 = tonumber(s:sub(1, 4), 16) - local n2 = tonumber(s:sub(7, 10), 16) - -- Surrogate pair? - if n2 then - return codepoint_to_utf8((n1 - 0xd800) * 0x400 + (n2 - 0xdc00) + 0x10000) - else - return codepoint_to_utf8(n1) - end + local n1 = tonumber(s:sub(1, 4), 16) + local n2 = tonumber(s:sub(7, 10), 16) + -- Surrogate pair? + if n2 then + return codepoint_to_utf8((n1 - 0xd800) * 0x400 + (n2 - 0xdc00) + 0x10000) + else + return codepoint_to_utf8(n1) + end end local function parse_string(str, i) - local res = "" - local j = i + 1 - local k = j + local res = "" + local j = i + 1 + local k = j - while j <= #str do - local x = str:byte(j) + while j <= #str do + local x = str:byte(j) - if x < 32 then - decode_error(str, j, "control character in string") + if x < 32 then + decode_error(str, j, "control character in string") + elseif x == 92 then -- `\`: Escape + res = res .. str:sub(k, j - 1) + j = j + 1 + local c = str:sub(j, j) + if c == "u" then + local hex = str:match("^[dD][89aAbB]%x%x\\u%x%x%x%x", j + 1) + or str:match("^%x%x%x%x", j + 1) + or decode_error(str, j - 1, "invalid unicode escape in string") + res = res .. parse_unicode_escape(hex) + j = j + #hex + else + if not escape_chars[c] then + decode_error(str, j - 1, "invalid escape char '" .. c .. "' in string") + end + res = res .. escape_char_map_inv[c] + end + k = j + 1 + elseif x == 34 then -- `"`: End of string + res = res .. str:sub(k, j - 1) + return res, j + 1 + end - elseif x == 92 then -- `\`: Escape - res = res .. str:sub(k, j - 1) - j = j + 1 - local c = str:sub(j, j) - if c == "u" then - local hex = str:match("^[dD][89aAbB]%x%x\\u%x%x%x%x", j + 1) - or str:match("^%x%x%x%x", j + 1) - or decode_error(str, j - 1, "invalid unicode escape in string") - res = res .. parse_unicode_escape(hex) - j = j + #hex - else - if not escape_chars[c] then - decode_error(str, j - 1, "invalid escape char '" .. c .. "' in string") - end - res = res .. escape_char_map_inv[c] - end - k = j + 1 + j = j + 1 + end - elseif x == 34 then -- `"`: End of string - res = res .. str:sub(k, j - 1) - return res, j + 1 - end - - j = j + 1 - end - - decode_error(str, i, "expected closing quote for string") + decode_error(str, i, "expected closing quote for string") end local function parse_number(str, i) - local x = next_char(str, i, delim_chars) - local s = str:sub(i, x - 1) - local n = tonumber(s) - if not n then - decode_error(str, i, "invalid number '" .. s .. "'") - end - return n, x + local x = next_char(str, i, delim_chars) + local s = str:sub(i, x - 1) + local n = tonumber(s) + if not n then + decode_error(str, i, "invalid number '" .. s .. "'") + end + return n, x end local function parse_literal(str, i) - local x = next_char(str, i, delim_chars) - local word = str:sub(i, x - 1) - if not literals[word] then - decode_error(str, i, "invalid literal '" .. word .. "'") - end - return literal_map[word], x + local x = next_char(str, i, delim_chars) + local word = str:sub(i, x - 1) + if not literals[word] then + decode_error(str, i, "invalid literal '" .. word .. "'") + end + return literal_map[word], x end local function parse_array(str, i) - local res = {} - local n = 1 - i = i + 1 - while 1 do - local x - i = next_char(str, i, space_chars, true) - -- Empty / end of array? - if str:sub(i, i) == "]" then - i = i + 1 - break - end - -- Read token - x, i = parse(str, i) - res[n] = x - n = n + 1 - -- Next token - i = next_char(str, i, space_chars, true) - local chr = str:sub(i, i) - i = i + 1 - if chr == "]" then break end - if chr ~= "," then decode_error(str, i, "expected ']' or ','") end - end - return res, i + local res = {} + local n = 1 + i = i + 1 + while 1 do + local x + i = next_char(str, i, space_chars, true) + -- Empty / end of array? + if str:sub(i, i) == "]" then + i = i + 1 + break + end + -- Read token + x, i = parse(str, i) + res[n] = x + n = n + 1 + -- Next token + i = next_char(str, i, space_chars, true) + local chr = str:sub(i, i) + i = i + 1 + if chr == "]" then + break + end + if chr ~= "," then + decode_error(str, i, "expected ']' or ','") + end + end + return res, i end local function parse_object(str, i) - local res = {} - i = i + 1 - while 1 do - local key, val - i = next_char(str, i, space_chars, true) - -- Empty / end of object? - if str:sub(i, i) == "}" then - i = i + 1 - break - end - -- Read key - if str:sub(i, i) ~= '"' then - decode_error(str, i, "expected string for key") - end - key, i = parse(str, i) - -- Read ':' delimiter - i = next_char(str, i, space_chars, true) - if str:sub(i, i) ~= ":" then - decode_error(str, i, "expected ':' after key") - end - i = next_char(str, i + 1, space_chars, true) - -- Read value - val, i = parse(str, i) - -- Set - res[key] = val - -- Next token - i = next_char(str, i, space_chars, true) - local chr = str:sub(i, i) - i = i + 1 - if chr == "}" then break end - if chr ~= "," then decode_error(str, i, "expected '}' or ','") end - end - return res, i + local res = {} + i = i + 1 + while 1 do + local key, val + i = next_char(str, i, space_chars, true) + -- Empty / end of object? + if str:sub(i, i) == "}" then + i = i + 1 + break + end + -- Read key + if str:sub(i, i) ~= '"' then + decode_error(str, i, "expected string for key") + end + key, i = parse(str, i) + -- Read ':' delimiter + i = next_char(str, i, space_chars, true) + if str:sub(i, i) ~= ":" then + decode_error(str, i, "expected ':' after key") + end + i = next_char(str, i + 1, space_chars, true) + -- Read value + val, i = parse(str, i) + -- Set + res[key] = val + -- Next token + i = next_char(str, i, space_chars, true) + local chr = str:sub(i, i) + i = i + 1 + if chr == "}" then + break + end + if chr ~= "," then + decode_error(str, i, "expected '}' or ','") + end + end + return res, i end local char_func_map = { - ['"'] = parse_string, - ["0"] = parse_number, - ["1"] = parse_number, - ["2"] = parse_number, - ["3"] = parse_number, - ["4"] = parse_number, - ["5"] = parse_number, - ["6"] = parse_number, - ["7"] = parse_number, - ["8"] = parse_number, - ["9"] = parse_number, - ["-"] = parse_number, - ["t"] = parse_literal, - ["f"] = parse_literal, - ["n"] = parse_literal, - ["["] = parse_array, - ["{"] = parse_object, + ['"'] = parse_string, + ["0"] = parse_number, + ["1"] = parse_number, + ["2"] = parse_number, + ["3"] = parse_number, + ["4"] = parse_number, + ["5"] = parse_number, + ["6"] = parse_number, + ["7"] = parse_number, + ["8"] = parse_number, + ["9"] = parse_number, + ["-"] = parse_number, + ["t"] = parse_literal, + ["f"] = parse_literal, + ["n"] = parse_literal, + ["["] = parse_array, + ["{"] = parse_object, } - parse = function(str, idx) - local chr = str:sub(idx, idx) - local f = char_func_map[chr] - if f then - return f(str, idx) - end - decode_error(str, idx, "unexpected character '" .. chr .. "'") + local chr = str:sub(idx, idx) + local f = char_func_map[chr] + if f then + return f(str, idx) + end + decode_error(str, idx, "unexpected character '" .. chr .. "'") end - function json.decode(str) - if type(str) ~= "string" then - error("expected argument of type string, got " .. type(str)) - end - local res, idx = parse(str, next_char(str, 1, space_chars, true)) - idx = next_char(str, idx, space_chars, true) - if idx <= #str then - decode_error(str, idx, "trailing garbage") - end - return res + if type(str) ~= "string" then + error("expected argument of type string, got " .. type(str)) + end + local res, idx = parse(str, next_char(str, 1, space_chars, true)) + idx = next_char(str, idx, space_chars, true) + if idx <= #str then + decode_error(str, idx, "trailing garbage") + end + return res end return json diff --git a/.config/awesome/mytheme.lua b/.config/awesome/mytheme.lua index 1cf1a3e9..809afc67 100644 --- a/.config/awesome/mytheme.lua +++ b/.config/awesome/mytheme.lua @@ -13,24 +13,23 @@ local theme = {} theme.font = "JetBrainsMono NF 8" -theme.bg_normal = "#222222" -theme.bg_focus = "#333333" -theme.bg_urgent = "#ff0000" +theme.bg_normal = "#222222" +theme.bg_focus = "#333333" +theme.bg_urgent = "#ff0000" theme.bg_minimize = "#444444" -theme.bg_systray = theme.bg_normal +theme.bg_systray = theme.bg_normal -theme.fg_normal = "#aaaaaa" -theme.fg_focus = "#ffffff" -theme.fg_urgent = "#ffffff" +theme.fg_normal = "#aaaaaa" +theme.fg_focus = "#ffffff" +theme.fg_urgent = "#ffffff" theme.fg_minimize = "#ffffff" -theme.useless_gap = dpi(4) -theme.border_width = dpi(2) +theme.useless_gap = dpi(4) +theme.border_width = dpi(2) theme.border_normal = "#000000" -theme.border_focus = "#f2f2f2" +theme.border_focus = "#f2f2f2" theme.border_marked = "#91231c" - -- There are other variable sets -- overriding the default one when -- defined, the sets are: @@ -46,12 +45,8 @@ theme.border_marked = "#91231c" -- Generate taglist squares: local taglist_square_size = dpi(4) -theme.taglist_squares_sel = theme_assets.taglist_squares_sel( - taglist_square_size, theme.fg_normal -) -theme.taglist_squares_unsel = theme_assets.taglist_squares_unsel( - taglist_square_size, theme.fg_normal -) +theme.taglist_squares_sel = theme_assets.taglist_squares_sel(taglist_square_size, theme.fg_normal) +theme.taglist_squares_unsel = theme_assets.taglist_squares_unsel(taglist_square_size, theme.fg_normal) -- Variables set for theming notifications: -- notification_font @@ -63,8 +58,8 @@ theme.taglist_squares_unsel = theme_assets.taglist_squares_unsel( -- menu_[bg|fg]_[normal|focus] -- menu_[border_color|border_width] theme.menu_submenu_icon = themes_path .. "default/submenu.png" -theme.menu_height = dpi(16) -theme.menu_width = dpi(100) +theme.menu_height = dpi(16) +theme.menu_width = dpi(100) -- You can add as many variables as -- you wish and access them by using @@ -73,55 +68,53 @@ theme.menu_width = dpi(100) -- Define the image to load theme.titlebar_close_button_normal = themes_path .. "default/titlebar/close_normal.png" -theme.titlebar_close_button_focus = themes_path .. "default/titlebar/close_focus.png" +theme.titlebar_close_button_focus = themes_path .. "default/titlebar/close_focus.png" theme.titlebar_minimize_button_normal = themes_path .. "default/titlebar/minimize_normal.png" -theme.titlebar_minimize_button_focus = themes_path .. "default/titlebar/minimize_focus.png" +theme.titlebar_minimize_button_focus = themes_path .. "default/titlebar/minimize_focus.png" theme.titlebar_ontop_button_normal_inactive = themes_path .. "default/titlebar/ontop_normal_inactive.png" -theme.titlebar_ontop_button_focus_inactive = themes_path .. "default/titlebar/ontop_focus_inactive.png" -theme.titlebar_ontop_button_normal_active = themes_path .. "default/titlebar/ontop_normal_active.png" -theme.titlebar_ontop_button_focus_active = themes_path .. "default/titlebar/ontop_focus_active.png" +theme.titlebar_ontop_button_focus_inactive = themes_path .. "default/titlebar/ontop_focus_inactive.png" +theme.titlebar_ontop_button_normal_active = themes_path .. "default/titlebar/ontop_normal_active.png" +theme.titlebar_ontop_button_focus_active = themes_path .. "default/titlebar/ontop_focus_active.png" theme.titlebar_sticky_button_normal_inactive = themes_path .. "default/titlebar/sticky_normal_inactive.png" -theme.titlebar_sticky_button_focus_inactive = themes_path .. "default/titlebar/sticky_focus_inactive.png" -theme.titlebar_sticky_button_normal_active = themes_path .. "default/titlebar/sticky_normal_active.png" -theme.titlebar_sticky_button_focus_active = themes_path .. "default/titlebar/sticky_focus_active.png" +theme.titlebar_sticky_button_focus_inactive = themes_path .. "default/titlebar/sticky_focus_inactive.png" +theme.titlebar_sticky_button_normal_active = themes_path .. "default/titlebar/sticky_normal_active.png" +theme.titlebar_sticky_button_focus_active = themes_path .. "default/titlebar/sticky_focus_active.png" theme.titlebar_floating_button_normal_inactive = themes_path .. "default/titlebar/floating_normal_inactive.png" -theme.titlebar_floating_button_focus_inactive = themes_path .. "default/titlebar/floating_focus_inactive.png" -theme.titlebar_floating_button_normal_active = themes_path .. "default/titlebar/floating_normal_active.png" -theme.titlebar_floating_button_focus_active = themes_path .. "default/titlebar/floating_focus_active.png" +theme.titlebar_floating_button_focus_inactive = themes_path .. "default/titlebar/floating_focus_inactive.png" +theme.titlebar_floating_button_normal_active = themes_path .. "default/titlebar/floating_normal_active.png" +theme.titlebar_floating_button_focus_active = themes_path .. "default/titlebar/floating_focus_active.png" theme.titlebar_maximized_button_normal_inactive = themes_path .. "default/titlebar/maximized_normal_inactive.png" -theme.titlebar_maximized_button_focus_inactive = themes_path .. "default/titlebar/maximized_focus_inactive.png" -theme.titlebar_maximized_button_normal_active = themes_path .. "default/titlebar/maximized_normal_active.png" -theme.titlebar_maximized_button_focus_active = themes_path .. "default/titlebar/maximized_focus_active.png" +theme.titlebar_maximized_button_focus_inactive = themes_path .. "default/titlebar/maximized_focus_inactive.png" +theme.titlebar_maximized_button_normal_active = themes_path .. "default/titlebar/maximized_normal_active.png" +theme.titlebar_maximized_button_focus_active = themes_path .. "default/titlebar/maximized_focus_active.png" theme.wallpaper = "~/.local/share/wallpaper.png" -- You can use your own layout icons like this: -theme.layout_fairh = themes_path .. "default/layouts/fairhw.png" -theme.layout_fairv = themes_path .. "default/layouts/fairvw.png" -theme.layout_floating = themes_path .. "default/layouts/floatingw.png" -theme.layout_magnifier = themes_path .. "default/layouts/magnifierw.png" -theme.layout_max = themes_path .. "default/layouts/maxw.png" +theme.layout_fairh = themes_path .. "default/layouts/fairhw.png" +theme.layout_fairv = themes_path .. "default/layouts/fairvw.png" +theme.layout_floating = themes_path .. "default/layouts/floatingw.png" +theme.layout_magnifier = themes_path .. "default/layouts/magnifierw.png" +theme.layout_max = themes_path .. "default/layouts/maxw.png" theme.layout_fullscreen = themes_path .. "default/layouts/fullscreenw.png" theme.layout_tilebottom = themes_path .. "default/layouts/tilebottomw.png" -theme.layout_tileleft = themes_path .. "default/layouts/tileleftw.png" -theme.layout_tile = themes_path .. "default/layouts/tilew.png" -theme.layout_tiletop = themes_path .. "default/layouts/tiletopw.png" -theme.layout_spiral = themes_path .. "default/layouts/spiralw.png" -theme.layout_dwindle = themes_path .. "default/layouts/dwindlew.png" -theme.layout_cornernw = themes_path .. "default/layouts/cornernww.png" -theme.layout_cornerne = themes_path .. "default/layouts/cornernew.png" -theme.layout_cornersw = themes_path .. "default/layouts/cornersww.png" -theme.layout_cornerse = themes_path .. "default/layouts/cornersew.png" +theme.layout_tileleft = themes_path .. "default/layouts/tileleftw.png" +theme.layout_tile = themes_path .. "default/layouts/tilew.png" +theme.layout_tiletop = themes_path .. "default/layouts/tiletopw.png" +theme.layout_spiral = themes_path .. "default/layouts/spiralw.png" +theme.layout_dwindle = themes_path .. "default/layouts/dwindlew.png" +theme.layout_cornernw = themes_path .. "default/layouts/cornernww.png" +theme.layout_cornerne = themes_path .. "default/layouts/cornernew.png" +theme.layout_cornersw = themes_path .. "default/layouts/cornersww.png" +theme.layout_cornerse = themes_path .. "default/layouts/cornersew.png" -- Generate Awesome icon: -theme.awesome_icon = theme_assets.awesome_icon( - theme.menu_height, theme.bg_focus, theme.fg_focus -) +theme.awesome_icon = theme_assets.awesome_icon(theme.menu_height, theme.bg_focus, theme.fg_focus) -- Define the icon theme for application icons. If not set then the icons -- from /usr/share/icons and /usr/share/icons/hicolor will be used. diff --git a/.config/awesome/rc.lua b/.config/awesome/rc.lua index 7aa58925..057e6454 100644 --- a/.config/awesome/rc.lua +++ b/.config/awesome/rc.lua @@ -7,11 +7,11 @@ local batteryarc_widget = require("awesome-wm-widgets.batteryarc-widget.batterya local cpu_widget = require("awesome-wm-widgets.cpu-widget.cpu-widget") local brightness_widget = require("awesome-wm-widgets.brightness-widget.brightness") local spotify_widget = require("awesome-wm-widgets.spotify-widget.spotify") -local volume_widget = require('awesome-wm-widgets.volume-widget.volume') -local calendar_widget = require('awesome-wm-widgets.calendar-widget.calendar') -local logout_menu_widget = require('awesome-wm-widgets.logout-menu-widget.logout-menu') -local net_speed_widget = require('awesome-wm-widgets.net-speed-widget.net-speed') -local ram_widget = require('awesome-wm-widgets.ram-widget.ram-widget') +local volume_widget = require("awesome-wm-widgets.volume-widget.volume") +local calendar_widget = require("awesome-wm-widgets.calendar-widget.calendar") +local logout_menu_widget = require("awesome-wm-widgets.logout-menu-widget.logout-menu") +local net_speed_widget = require("awesome-wm-widgets.net-speed-widget.net-speed") +local ram_widget = require("awesome-wm-widgets.ram-widget.ram-widget") local weather_widget = require("awesome-wm-widgets.weather-widget.weather") -- Standard awesome library @@ -32,23 +32,27 @@ require("awful.hotkeys_popup.keys") -- OpenWeather API -- !Create file ~/.config/awesome/weather and paste API from OpenWeather, latitude and longitude, each on separate lines -local weather_file = '/home/kristofers/.config/awesome/weather' -- absolute path to `weather` file +local weather_file = "/home/kristofers/.config/awesome/weather" -- absolute path to `weather` file -- see if the file exists local function file_exists(file) - local f = io.open(file, "rb") - if f then f:close() end - return f ~= nil + local f = io.open(file, "rb") + if f then + f:close() + end + return f ~= nil end -- get all lines from a file, returns an empty -- list/table if the file does not exist local function lines_from(file) - if not file_exists(file) then return {} end - local lines = {} - for line in io.lines(file) do - lines[#lines + 1] = line - end - return lines + if not file_exists(file) then + return {} + end + local lines = {} + for line in io.lines(file) do + lines[#lines + 1] = line + end + return lines end local weather_output = lines_from(weather_file) @@ -56,29 +60,34 @@ local API = weather_output[1] local latitude = tonumber(weather_output[2]) local longitude = tonumber(weather_output[3]) - -- {{{ Error handling -- Check if awesome encountered an error during startup and fell back to -- another config (This code will only ever execute for the fallback config) if awesome.startup_errors then - naughty.notify({ preset = naughty.config.presets.critical, - title = "Oops, there were errors during startup!", - text = awesome.startup_errors }) + naughty.notify({ + preset = naughty.config.presets.critical, + title = "Oops, there were errors during startup!", + text = awesome.startup_errors, + }) end -- Handle runtime errors after startup do - local in_error = false - awesome.connect_signal("debug::error", function(err) - -- Make sure we don't go into an endless error loop - if in_error then return end - in_error = true + local in_error = false + awesome.connect_signal("debug::error", function(err) + -- Make sure we don't go into an endless error loop + if in_error then + return + end + in_error = true - naughty.notify({ preset = naughty.config.presets.critical, - title = "Oops, an error happened!", - text = tostring(err) }) - in_error = false - end) + naughty.notify({ + preset = naughty.config.presets.critical, + title = "Oops, an error happened!", + text = tostring(err), + }) + in_error = false + end) end -- }}} @@ -101,42 +110,49 @@ modkey = "Mod4" -- Table of layouts to cover with awful.layout.inc, order matters. awful.layout.layouts = { - awful.layout.suit.tile, - awful.layout.suit.spiral.dwindle, - awful.layout.suit.spiral, - --awful.layout.suit.floating, - --awful.layout.suit.tile.left, - --awful.layout.suit.tile.bottom, - --awful.layout.suit.tile.top, - awful.layout.suit.fair, - --awful.layout.suit.fair.horizontal, - --awful.layout.suit.max, - --awful.layout.suit.max.fullscreen, - --awful.layout.suit.magnifier, - --awful.layout.suit.corner.nw, - --awful.layout.suit.corner.ne, - --awful.layout.suit.corner.sw, - --awful.layout.suit.corner.se, + awful.layout.suit.tile, + awful.layout.suit.spiral.dwindle, + awful.layout.suit.spiral, + --awful.layout.suit.floating, + --awful.layout.suit.tile.left, + --awful.layout.suit.tile.bottom, + --awful.layout.suit.tile.top, + awful.layout.suit.fair, + --awful.layout.suit.fair.horizontal, + --awful.layout.suit.max, + --awful.layout.suit.max.fullscreen, + --awful.layout.suit.magnifier, + --awful.layout.suit.corner.nw, + --awful.layout.suit.corner.ne, + --awful.layout.suit.corner.sw, + --awful.layout.suit.corner.se, } -- }}} -- {{{ Menu -- Create a launcher widget and a main menu myawesomemenu = { - { "hotkeys", function() hotkeys_popup.show_help(nil, awful.screen.focused()) end }, - { "manual", terminal .. " -e man awesome" }, - { "edit config", editor_cmd .. " " .. awesome.conffile }, - { "restart", awesome.restart }, - { "quit", function() awesome.quit() end }, + { + "hotkeys", + function() + hotkeys_popup.show_help(nil, awful.screen.focused()) + end, + }, + { "manual", terminal .. " -e man awesome" }, + { "edit config", editor_cmd .. " " .. awesome.conffile }, + { "restart", awesome.restart }, + { + "quit", + function() + awesome.quit() + end, + }, } -mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon }, - { "open terminal", terminal } -} -}) +mymainmenu = + awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon }, { "open terminal", terminal } } }) -mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon, - menu = mymainmenu }) +mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon, menu = mymainmenu }) -- Menubar configuration menubar.utils.terminal = terminal -- Set the terminal for applications that require it @@ -149,376 +165,404 @@ menubar.utils.terminal = terminal -- Set the terminal for applications that requ -- Create a textclock widget mytextclock = wibox.widget.textclock() local cw = calendar_widget({ - theme = 'nord', - placement = "top_right", - previous_month_button = 4, - next_month_button = 5, + theme = "nord", + placement = "top_right", + previous_month_button = 4, + next_month_button = 5, }) -mytextclock:connect_signal("button::press", - function(_, _, _, button) - if button == 1 then cw.toggle() end - end) +mytextclock:connect_signal("button::press", function(_, _, _, button) + if button == 1 then + cw.toggle() + end +end) -- Create a wibox for each screen and add it local taglist_buttons = gears.table.join( - awful.button({}, 1, function(t) t:view_only() end), - awful.button({ modkey }, 1, function(t) - if client.focus then - client.focus:move_to_tag(t) - end - end), - awful.button({}, 3, awful.tag.viewtoggle), - awful.button({ modkey }, 3, function(t) - if client.focus then - client.focus:toggle_tag(t) - end - end), - awful.button({}, 4, function(t) awful.tag.viewnext(t.screen) end), - awful.button({}, 5, function(t) awful.tag.viewprev(t.screen) end) + awful.button({}, 1, function(t) + t:view_only() + end), + awful.button({ modkey }, 1, function(t) + if client.focus then + client.focus:move_to_tag(t) + end + end), + awful.button({}, 3, awful.tag.viewtoggle), + awful.button({ modkey }, 3, function(t) + if client.focus then + client.focus:toggle_tag(t) + end + end), + awful.button({}, 4, function(t) + awful.tag.viewnext(t.screen) + end), + awful.button({}, 5, function(t) + awful.tag.viewprev(t.screen) + end) ) local tasklist_buttons = gears.table.join( - awful.button({}, 1, function(c) - if c == client.focus then - c.minimized = true - else - c:emit_signal( - "request::activate", - "tasklist", - { raise = true } - ) - end - end), - awful.button({}, 3, function() - awful.menu.client_list({ theme = { width = 250 } }) - end), - awful.button({}, 4, function() - awful.client.focus.byidx(1) - end), - awful.button({}, 5, function() - awful.client.focus.byidx(-1) - end)) + awful.button({}, 1, function(c) + if c == client.focus then + c.minimized = true + else + c:emit_signal("request::activate", "tasklist", { raise = true }) + end + end), + awful.button({}, 3, function() + awful.menu.client_list({ theme = { width = 250 } }) + end), + awful.button({}, 4, function() + awful.client.focus.byidx(1) + end), + awful.button({}, 5, function() + awful.client.focus.byidx(-1) + end) +) local function set_wallpaper(s) - -- Wallpaper - if beautiful.wallpaper then - local wallpaper = beautiful.wallpaper - -- If wallpaper is a function, call it with the screen - if type(wallpaper) == "function" then - wallpaper = wallpaper(s) - end - gears.wallpaper.maximized(wallpaper, s, true) - end + -- Wallpaper + if beautiful.wallpaper then + local wallpaper = beautiful.wallpaper + -- If wallpaper is a function, call it with the screen + if type(wallpaper) == "function" then + wallpaper = wallpaper(s) + end + gears.wallpaper.maximized(wallpaper, s, true) + end end -- Re-set wallpaper when a screen's geometry changes (e.g. different resolution) screen.connect_signal("property::geometry", set_wallpaper) awful.screen.connect_for_each_screen(function(s) - -- Wallpaper - set_wallpaper(s) + -- Wallpaper + set_wallpaper(s) - -- Each screen has its own tag table. - awful.tag({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, s, awful.layout.layouts[1]) + -- Each screen has its own tag table. + awful.tag({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, s, awful.layout.layouts[1]) - -- Create a promptbox for each screen - s.mypromptbox = awful.widget.prompt() - -- Create an imagebox widget which will contain an icon indicating which layout we're using. - -- We need one layoutbox per screen. - s.mylayoutbox = awful.widget.layoutbox(s) - s.mylayoutbox:buttons(gears.table.join( - awful.button({}, 1, function() awful.layout.inc(1) end), - awful.button({}, 3, function() awful.layout.inc(-1) end), - awful.button({}, 4, function() awful.layout.inc(1) end), - awful.button({}, 5, function() awful.layout.inc(-1) end))) - -- Create a taglist widget - s.mytaglist = awful.widget.taglist { - screen = s, - filter = awful.widget.taglist.filter.all, - buttons = taglist_buttons - } + -- Create a promptbox for each screen + s.mypromptbox = awful.widget.prompt() + -- Create an imagebox widget which will contain an icon indicating which layout we're using. + -- We need one layoutbox per screen. + s.mylayoutbox = awful.widget.layoutbox(s) + s.mylayoutbox:buttons(gears.table.join( + awful.button({}, 1, function() + awful.layout.inc(1) + end), + awful.button({}, 3, function() + awful.layout.inc(-1) + end), + awful.button({}, 4, function() + awful.layout.inc(1) + end), + awful.button({}, 5, function() + awful.layout.inc(-1) + end) + )) + -- Create a taglist widget + s.mytaglist = awful.widget.taglist({ + screen = s, + filter = awful.widget.taglist.filter.all, + buttons = taglist_buttons, + }) - -- Create a tasklist widget - s.mytasklist = awful.widget.tasklist { - screen = s, - filter = awful.widget.tasklist.filter.currenttags, - buttons = tasklist_buttons - } + -- Create a tasklist widget + s.mytasklist = awful.widget.tasklist({ + screen = s, + filter = awful.widget.tasklist.filter.currenttags, + buttons = tasklist_buttons, + }) - -- Create the wibox - s.mywibox = awful.wibar({ position = "top", screen = s }) + -- Create the wibox + s.mywibox = awful.wibar({ position = "top", screen = s }) - -- Add widgets to the wibox - s.mywibox:setup { - layout = wibox.layout.align.horizontal, - { -- Left widgets - layout = wibox.layout.fixed.horizontal, - --mylauncher, - s.mytaglist, - s.mypromptbox, - }, - s.mytasklist, -- Middle widget - { -- Right widgets - layout = wibox.layout.fixed.horizontal, - wibox.widget.systray(), - cpu_widget(), - ram_widget(), - net_speed_widget(), - spotify_widget({ - dim_when_paused = true, - dim_opacity = 0.5, - max_lenght = -1, - }), - batteryarc_widget({ - show_current_level = true, - size = 32, - }), - brightness_widget { - program = 'brightnessctl', - step = 5, - base = 60, - tooltip = true, - }, - weather_widget({ - api_key = API, - coordinates = { latitude, longitude }, - show_hourly_forecst = true, - show_daily_forecast = true, - }), - -- logout_menu_widget(), - mytextclock, - s.mylayoutbox, - }, - } + -- Add widgets to the wibox + s.mywibox:setup({ + layout = wibox.layout.align.horizontal, + { -- Left widgets + layout = wibox.layout.fixed.horizontal, + --mylauncher, + s.mytaglist, + s.mypromptbox, + }, + s.mytasklist, -- Middle widget + { -- Right widgets + layout = wibox.layout.fixed.horizontal, + wibox.widget.systray(), + cpu_widget(), + ram_widget(), + net_speed_widget(), + spotify_widget({ + dim_when_paused = true, + dim_opacity = 0.5, + max_lenght = -1, + }), + batteryarc_widget({ + show_current_level = true, + size = 32, + }), + brightness_widget({ + program = "brightnessctl", + step = 5, + base = 60, + tooltip = true, + }), + weather_widget({ + api_key = API, + coordinates = { latitude, longitude }, + show_hourly_forecst = true, + show_daily_forecast = true, + }), + -- logout_menu_widget(), + mytextclock, + s.mylayoutbox, + }, + }) end) -- }}} -- {{{ Mouse bindings root.buttons(gears.table.join( - awful.button({}, 3, function() mymainmenu:toggle() end), - awful.button({}, 4, awful.tag.viewnext), - awful.button({}, 5, awful.tag.viewprev) + awful.button({}, 3, function() + mymainmenu:toggle() + end), + awful.button({}, 4, awful.tag.viewnext), + awful.button({}, 5, awful.tag.viewprev) )) -- }}} -- {{{ Key bindings globalkeys = gears.table.join( - awful.key({}, "#233", function() brightness_widget:inc() end), -- increase brightness - awful.key({}, "#232", function() brightness_widget:dec() end), -- decrease brightness + awful.key({}, "#233", function() + brightness_widget:inc() + end), -- increase brightness + awful.key({}, "#232", function() + brightness_widget:dec() + end), -- decrease brightness - awful.key({}, "#123", function() awful.spawn.with_shell("pulsemixer --change-volume +5") end), -- increase volume - awful.key({}, "#122", function() awful.spawn.with_shell("pulsemixer --change-volume -5") end), -- decrease volume - awful.key({}, "#121", function() awful.spawn.with_shell("pulsemixer --toggle-mute") end), -- mute - awful.key({}, "#172", function() awful.spawn.with_shell("playerctl -a play-pause") end), -- play/pause + awful.key({}, "#123", function() + awful.spawn.with_shell("pulsemixer --change-volume +5") + end), -- increase volume + awful.key({}, "#122", function() + awful.spawn.with_shell("pulsemixer --change-volume -5") + end), -- decrease volume + awful.key({}, "#121", function() + awful.spawn.with_shell("pulsemixer --toggle-mute") + end), -- mute + awful.key({}, "#172", function() + awful.spawn.with_shell("playerctl -a play-pause") + end), -- play/pause - awful.key({ "Control" }, "#107", function() awful.spawn.with_shell("flameshot gui") end, - { description = "take region screenshot", group = "launcher" }), -- take region screenshot + awful.key({ "Control" }, "#107", function() + awful.spawn.with_shell("flameshot gui") + end, { description = "take region screenshot", group = "launcher" }), -- take region screenshot + awful.key({ modkey }, "s", hotkeys_popup.show_help, { description = "show help", group = "awesome" }), + awful.key({ modkey }, "Left", awful.tag.viewprev, { description = "view previous", group = "tag" }), + awful.key({ modkey }, "Right", awful.tag.viewnext, { description = "view next", group = "tag" }), + awful.key({ modkey }, "Escape", awful.tag.history.restore, { description = "go back", group = "tag" }), - awful.key({ modkey, }, "s", hotkeys_popup.show_help, - { description = "show help", group = "awesome" }), - awful.key({ modkey, }, "Left", awful.tag.viewprev, - { description = "view previous", group = "tag" }), - awful.key({ modkey, }, "Right", awful.tag.viewnext, - { description = "view next", group = "tag" }), - awful.key({ modkey, }, "Escape", awful.tag.history.restore, - { description = "go back", group = "tag" }), + awful.key({ modkey }, "j", function() + awful.client.focus.byidx(1) + end, { description = "focus next by index", group = "client" }), + awful.key({ modkey }, "k", function() + awful.client.focus.byidx(-1) + end, { description = "focus previous by index", group = "client" }), + awful.key({ modkey }, "w", function() + mymainmenu:show() + end, { description = "show main menu", group = "awesome" }), - awful.key({ modkey, }, "j", function() awful.client.focus.byidx(1) end, - { description = "focus next by index", group = "client" } - ), - awful.key({ modkey, }, "k", function() awful.client.focus.byidx(-1) end, - { description = "focus previous by index", group = "client" } - ), - awful.key({ modkey, }, "w", function() mymainmenu:show() end, - { description = "show main menu", group = "awesome" }), + -- Layout manipulation + awful.key({ modkey, "Shift" }, "j", function() + awful.client.swap.byidx(1) + end, { description = "swap with next client by index", group = "client" }), + awful.key({ modkey, "Shift" }, "k", function() + awful.client.swap.byidx(-1) + end, { description = "swap with previous client by index", group = "client" }), + awful.key({ modkey, "Control" }, "j", function() + awful.screen.focus_relative(1) + end, { description = "focus the next screen", group = "screen" }), + awful.key({ modkey, "Control" }, "k", function() + awful.screen.focus_relative(-1) + end, { description = "focus the previous screen", group = "screen" }), + awful.key({ modkey }, "u", awful.client.urgent.jumpto, { description = "jump to urgent client", group = "client" }), + awful.key({ modkey }, "Tab", function() + awful.client.focus.history.previous() + if client.focus then + client.focus:raise() + end + end, { description = "go back", group = "client" }), - -- Layout manipulation - awful.key({ modkey, "Shift" }, "j", function() awful.client.swap.byidx(1) end, - { description = "swap with next client by index", group = "client" }), - awful.key({ modkey, "Shift" }, "k", function() awful.client.swap.byidx(-1) end, - { description = "swap with previous client by index", group = "client" }), - awful.key({ modkey, "Control" }, "j", function() awful.screen.focus_relative(1) end, - { description = "focus the next screen", group = "screen" }), - awful.key({ modkey, "Control" }, "k", function() awful.screen.focus_relative(-1) end, - { description = "focus the previous screen", group = "screen" }), - awful.key({ modkey, }, "u", awful.client.urgent.jumpto, - { description = "jump to urgent client", group = "client" }), - awful.key({ modkey, }, "Tab", function() awful.client.focus.history.previous() - if client.focus then - client.focus:raise() - end - end, - { description = "go back", group = "client" }), + -- Standard program + awful.key({ modkey }, "Return", function() + awful.spawn(terminal) + end, { description = "open a terminal", group = "launcher" }), + awful.key({ modkey, "Control" }, "r", awesome.restart, { description = "reload awesome", group = "awesome" }), + -- awful.key({ modkey, "Control" }, "q", awesome.quit, + -- {description = "quit awesome", group = "awesome"}), + awful.key({ modkey }, "b", function() + awful.spawn("firefox") + end, { description = "open firefox", group = "launcher" }), + awful.key({ modkey }, "n", function() + awful.spawn("spacefm") + end, { description = "open spacefm", group = "launcher" }), - -- Standard program - awful.key({ modkey, }, "Return", function() awful.spawn(terminal) end, - { description = "open a terminal", group = "launcher" }), - awful.key({ modkey, "Control" }, "r", awesome.restart, - { description = "reload awesome", group = "awesome" }), - -- awful.key({ modkey, "Control" }, "q", awesome.quit, - -- {description = "quit awesome", group = "awesome"}), - awful.key({ modkey, }, "b", function() awful.spawn("firefox") end, - { description = "open firefox", group = "launcher" }), - awful.key({ modkey, }, "n", function() awful.spawn("spacefm") end, - { description = "open spacefm", group = "launcher" }), + awful.key({ modkey }, "l", function() + awful.tag.incmwfact(0.05) + end, { description = "increase master width factor", group = "layout" }), + awful.key({ modkey }, "h", function() + awful.tag.incmwfact(-0.05) + end, { description = "decrease master width factor", group = "layout" }), + awful.key({ modkey, "Shift" }, "h", function() + awful.tag.incnmaster(1, nil, true) + end, { description = "increase the number of master clients", group = "layout" }), + awful.key({ modkey, "Shift" }, "l", function() + awful.tag.incnmaster(-1, nil, true) + end, { description = "decrease the number of master clients", group = "layout" }), + awful.key({ modkey, "Control" }, "h", function() + awful.tag.incncol(1, nil, true) + end, { description = "increase the number of columns", group = "layout" }), + awful.key({ modkey, "Control" }, "l", function() + awful.tag.incncol(-1, nil, true) + end, { description = "decrease the number of columns", group = "layout" }), + awful.key({ modkey }, "space", function() + awful.layout.inc(1) + end, { description = "select next", group = "layout" }), + awful.key({ modkey, "Shift" }, "space", function() + awful.layout.inc(-1) + end, { description = "select previous", group = "layout" }), - awful.key({ modkey, }, "l", function() awful.tag.incmwfact(0.05) end, - { description = "increase master width factor", group = "layout" }), - awful.key({ modkey, }, "h", function() awful.tag.incmwfact(-0.05) end, - { description = "decrease master width factor", group = "layout" }), - awful.key({ modkey, "Shift" }, "h", function() awful.tag.incnmaster(1, nil, true) end, - { description = "increase the number of master clients", group = "layout" }), - awful.key({ modkey, "Shift" }, "l", function() awful.tag.incnmaster(-1, nil, true) end, - { description = "decrease the number of master clients", group = "layout" }), - awful.key({ modkey, "Control" }, "h", function() awful.tag.incncol(1, nil, true) end, - { description = "increase the number of columns", group = "layout" }), - awful.key({ modkey, "Control" }, "l", function() awful.tag.incncol(-1, nil, true) end, - { description = "decrease the number of columns", group = "layout" }), - awful.key({ modkey, }, "space", function() awful.layout.inc(1) end, - { description = "select next", group = "layout" }), - awful.key({ modkey, "Shift" }, "space", function() awful.layout.inc(-1) end, - { description = "select previous", group = "layout" }), + -- awful.key({ modkey, "Control" }, "n", + -- function () + -- local c = awful.client.restore() + -- -- Focus restored client + -- if c then + -- c:emit_signal( + -- "request::activate", "key.unminimize", {raise = true} + -- ) + -- end + -- end, + -- {description = "restore minimized", group = "client"}), - -- awful.key({ modkey, "Control" }, "n", - -- function () - -- local c = awful.client.restore() - -- -- Focus restored client - -- if c then - -- c:emit_signal( - -- "request::activate", "key.unminimize", {raise = true} - -- ) - -- end - -- end, - -- {description = "restore minimized", group = "client"}), + -- Prompt + awful.key({ modkey }, "r", function() + awful.screen.focused().mypromptbox:run() + end, { description = "run prompt", group = "launcher" }), - -- Prompt - awful.key({ modkey }, "r", function() awful.screen.focused().mypromptbox:run() end, - { description = "run prompt", group = "launcher" }), - - awful.key({ modkey }, "x", - function() - awful.prompt.run { - prompt = "Run Lua code: ", - textbox = awful.screen.focused().mypromptbox.widget, - exe_callback = awful.util.eval, - history_path = awful.util.get_cache_dir() .. "/history_eval" - } - end, - { description = "lua execute prompt", group = "awesome" }), - -- Menubar - awful.key({ modkey }, "p", function() menubar.show() end, - { description = "show the menubar", group = "launcher" }) + awful.key({ modkey }, "x", function() + awful.prompt.run({ + prompt = "Run Lua code: ", + textbox = awful.screen.focused().mypromptbox.widget, + exe_callback = awful.util.eval, + history_path = awful.util.get_cache_dir() .. "/history_eval", + }) + end, { description = "lua execute prompt", group = "awesome" }), + -- Menubar + awful.key({ modkey }, "p", function() + menubar.show() + end, { description = "show the menubar", group = "launcher" }) ) clientkeys = gears.table.join( - awful.key({ modkey, }, "f", - function(c) - c.fullscreen = not c.fullscreen - c:raise() - end, - { description = "toggle fullscreen", group = "client" }), - awful.key({ modkey, "Shift" }, "q", function(c) c:kill() end, - { description = "close", group = "client" }), - awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle, - { description = "toggle floating", group = "client" }), - awful.key({ modkey, "Control" }, "Return", function(c) c:swap(awful.client.getmaster()) end, - { description = "move to master", group = "client" }), - awful.key({ modkey, }, "o", function(c) c:move_to_screen() end, - { description = "move to screen", group = "client" }), - awful.key({ modkey, }, "t", function(c) c.ontop = not c.ontop end, - { description = "toggle keep on top", group = "client" }), - awful.key({ modkey, }, "n", - function(c) - -- The client currently has the input focus, so it cannot be - -- minimized, since minimized clients can't have the focus. - c.minimized = true - end, - { description = "minimize", group = "client" }), - awful.key({ modkey, }, "m", - function(c) - c.maximized = not c.maximized - c:raise() - end, - { description = "(un)maximize", group = "client" }), - awful.key({ modkey, "Control" }, "m", - function(c) - c.maximized_vertical = not c.maximized_vertical - c:raise() - end, - { description = "(un)maximize vertically", group = "client" }), - awful.key({ modkey, "Shift" }, "m", - function(c) - c.maximized_horizontal = not c.maximized_horizontal - c:raise() - end, - { description = "(un)maximize horizontally", group = "client" }) + awful.key({ modkey }, "f", function(c) + c.fullscreen = not c.fullscreen + c:raise() + end, { description = "toggle fullscreen", group = "client" }), + awful.key({ modkey, "Shift" }, "q", function(c) + c:kill() + end, { description = "close", group = "client" }), + awful.key( + { modkey, "Control" }, + "space", + awful.client.floating.toggle, + { description = "toggle floating", group = "client" } + ), + awful.key({ modkey, "Control" }, "Return", function(c) + c:swap(awful.client.getmaster()) + end, { description = "move to master", group = "client" }), + awful.key({ modkey }, "o", function(c) + c:move_to_screen() + end, { description = "move to screen", group = "client" }), + awful.key({ modkey }, "t", function(c) + c.ontop = not c.ontop + end, { description = "toggle keep on top", group = "client" }), + awful.key({ modkey }, "n", function(c) + -- The client currently has the input focus, so it cannot be + -- minimized, since minimized clients can't have the focus. + c.minimized = true + end, { description = "minimize", group = "client" }), + awful.key({ modkey }, "m", function(c) + c.maximized = not c.maximized + c:raise() + end, { description = "(un)maximize", group = "client" }), + awful.key({ modkey, "Control" }, "m", function(c) + c.maximized_vertical = not c.maximized_vertical + c:raise() + end, { description = "(un)maximize vertically", group = "client" }), + awful.key({ modkey, "Shift" }, "m", function(c) + c.maximized_horizontal = not c.maximized_horizontal + c:raise() + end, { description = "(un)maximize horizontally", group = "client" }) ) -- Bind all key numbers to tags. -- Be careful: we use keycodes to make it work on any keyboard layout. -- This should map on the top row of your keyboard, usually 1 to 9. for i = 1, 9 do - globalkeys = gears.table.join(globalkeys, - -- View tag only. - awful.key({ modkey }, "#" .. i + 9, - function() - local screen = awful.screen.focused() - local tag = screen.tags[i] - if tag then - tag:view_only() - end - end, - { description = "view tag #" .. i, group = "tag" }), - -- Toggle tag display. - awful.key({ modkey, "Control" }, "#" .. i + 9, - function() - local screen = awful.screen.focused() - local tag = screen.tags[i] - if tag then - awful.tag.viewtoggle(tag) - end - end, - { description = "toggle tag #" .. i, group = "tag" }), - -- Move client to tag. - awful.key({ modkey, "Shift" }, "#" .. i + 9, - function() - if client.focus then - local tag = client.focus.screen.tags[i] - if tag then - client.focus:move_to_tag(tag) - end - end - end, - { description = "move focused client to tag #" .. i, group = "tag" }), - -- Toggle tag on focused client. - awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9, - function() - if client.focus then - local tag = client.focus.screen.tags[i] - if tag then - client.focus:toggle_tag(tag) - end - end - end, - { description = "toggle focused client on tag #" .. i, group = "tag" }) - ) + globalkeys = gears.table.join( + globalkeys, + -- View tag only. + awful.key({ modkey }, "#" .. i + 9, function() + local screen = awful.screen.focused() + local tag = screen.tags[i] + if tag then + tag:view_only() + end + end, { description = "view tag #" .. i, group = "tag" }), + -- Toggle tag display. + awful.key({ modkey, "Control" }, "#" .. i + 9, function() + local screen = awful.screen.focused() + local tag = screen.tags[i] + if tag then + awful.tag.viewtoggle(tag) + end + end, { description = "toggle tag #" .. i, group = "tag" }), + -- Move client to tag. + awful.key({ modkey, "Shift" }, "#" .. i + 9, function() + if client.focus then + local tag = client.focus.screen.tags[i] + if tag then + client.focus:move_to_tag(tag) + end + end + end, { description = "move focused client to tag #" .. i, group = "tag" }), + -- Toggle tag on focused client. + awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9, function() + if client.focus then + local tag = client.focus.screen.tags[i] + if tag then + client.focus:toggle_tag(tag) + end + end + end, { description = "toggle focused client on tag #" .. i, group = "tag" }) + ) end clientbuttons = gears.table.join( - awful.button({}, 1, function(c) - c:emit_signal("request::activate", "mouse_click", { raise = true }) - end), - awful.button({ modkey }, 1, function(c) - c:emit_signal("request::activate", "mouse_click", { raise = true }) - awful.mouse.client.move(c) - end), - awful.button({ modkey }, 3, function(c) - c:emit_signal("request::activate", "mouse_click", { raise = true }) - awful.mouse.client.resize(c) - end) + awful.button({}, 1, function(c) + c:emit_signal("request::activate", "mouse_click", { raise = true }) + end), + awful.button({ modkey }, 1, function(c) + c:emit_signal("request::activate", "mouse_click", { raise = true }) + awful.mouse.client.move(c) + end), + awful.button({ modkey }, 3, function(c) + c:emit_signal("request::activate", "mouse_click", { raise = true }) + awful.mouse.client.resize(c) + end) ) -- Set keys @@ -528,138 +572,146 @@ root.keys(globalkeys) -- {{{ Rules -- Rules to apply to new clients (through the "manage" signal). awful.rules.rules = { - -- All clients will match this rule. - { rule = {}, - properties = { border_width = beautiful.border_width, - border_color = beautiful.border_normal, - focus = awful.client.focus.filter, - raise = true, - keys = clientkeys, - -- buttons = clientbuttons, - screen = awful.screen.preferred, - --placement = awful.placement.no_overlap+awful.placement.no_offscreen - } - }, + -- All clients will match this rule. + { + rule = {}, + properties = { + border_width = beautiful.border_width, + border_color = beautiful.border_normal, + focus = awful.client.focus.filter, + raise = true, + keys = clientkeys, + -- buttons = clientbuttons, + screen = awful.screen.preferred, + --placement = awful.placement.no_overlap+awful.placement.no_offscreen + }, + }, - -- Floating clients. - { rule_any = { - instance = { - "DTA", -- Firefox addon DownThemAll. - "copyq", -- Includes session name in class. - "pinentry", - }, - class = { - "Blueman-manager", - "MessageWin", -- kalarm. - "Tor Browser", -- Needs a fixed window size to avoid fingerprinting by screen size. - "Wpa_gui", - "veromix", - "xtightvncviewer" }, + -- Floating clients. + { + rule_any = { + instance = { + "DTA", -- Firefox addon DownThemAll. + "copyq", -- Includes session name in class. + "pinentry", + }, + class = { + "Blueman-manager", + "MessageWin", -- kalarm. + "Tor Browser", -- Needs a fixed window size to avoid fingerprinting by screen size. + "Wpa_gui", + "veromix", + "xtightvncviewer", + }, - -- Note that the name property shown in xprop might be set slightly after creation of the client - -- and the name shown there might not match defined rules here. - name = { - "Event Tester", -- xev. - }, - role = { - "AlarmWindow", -- Thunderbird's calendar. - "ConfigManager", -- Thunderbird's about:config. - "pop-up", -- e.g. Google Chrome's (detached) Developer Tools. - } - }, properties = { floating = true, beautiful.useless } }, + -- Note that the name property shown in xprop might be set slightly after creation of the client + -- and the name shown there might not match defined rules here. + name = { + "Event Tester", -- xev. + }, + role = { + "AlarmWindow", -- Thunderbird's calendar. + "ConfigManager", -- Thunderbird's about:config. + "pop-up", -- e.g. Google Chrome's (detached) Developer Tools. + }, + }, + properties = { floating = true, beautiful.useless }, + }, - -- Add titlebars to normal clients and dialogs - { rule_any = { type = { "normal", "dialog" } - }, properties = { titlebars_enabled = false } - }, + -- Add titlebars to normal clients and dialogs + { rule_any = { type = { "normal", "dialog" } }, properties = { titlebars_enabled = false } }, - { - rule_any = { - class = { "tuxedo-control-center", "corectrl" } - }, properties = { screen = 1, tag = "7" } - }, - { - rule_any = { - class = { "Thunderbird", "discord", "ripcord", "TelegramDesktop" } - }, properties = { screen = 1, tag = "8" } - }, - { - rule_any = { - class = { "spotify", "Spotify" }, - }, properties = { screen = 1, tag = "9" } - }, + { + rule_any = { + class = { "tuxedo-control-center", "corectrl" }, + }, + properties = { screen = 1, tag = "7" }, + }, + { + rule_any = { + class = { "Thunderbird", "discord", "ripcord", "TelegramDesktop" }, + }, + properties = { screen = 1, tag = "8" }, + }, + { + rule_any = { + class = { "spotify", "Spotify" }, + }, + properties = { screen = 1, tag = "9" }, + }, - -- Set Firefox to always map on the tag named "2" on screen 1. - -- { rule = { class = "Firefox" }, - -- properties = { screen = 1, tag = "2" } }, + -- Set Firefox to always map on the tag named "2" on screen 1. + -- { rule = { class = "Firefox" }, + -- properties = { screen = 1, tag = "2" } }, } -- }}} -- {{{ Signals -- Signal function to execute when a new client appears. client.connect_signal("manage", function(c) - -- Set the windows at the slave, - -- i.e. put it at the end of others instead of setting it master. - -- if not awesome.startup then awful.client.setslave(c) end + -- Set the windows at the slave, + -- i.e. put it at the end of others instead of setting it master. + -- if not awesome.startup then awful.client.setslave(c) end - if awesome.startup - and not c.size_hints.user_position - and not c.size_hints.program_position then - -- Prevent clients from being unreachable after screen count changes. - awful.placement.no_offscreen(c) - end + if awesome.startup and not c.size_hints.user_position and not c.size_hints.program_position then + -- Prevent clients from being unreachable after screen count changes. + awful.placement.no_offscreen(c) + end end) -- Add a titlebar if titlebars_enabled is set to true in the rules. client.connect_signal("request::titlebars", function(c) - -- buttons for the titlebar - local buttons = gears.table.join( - awful.button({}, 1, function() - c:emit_signal("request::activate", "titlebar", { raise = true }) - awful.mouse.client.move(c) - end), - awful.button({}, 3, function() - c:emit_signal("request::activate", "titlebar", { raise = true }) - awful.mouse.client.resize(c) - end) - ) + -- buttons for the titlebar + local buttons = gears.table.join( + awful.button({}, 1, function() + c:emit_signal("request::activate", "titlebar", { raise = true }) + awful.mouse.client.move(c) + end), + awful.button({}, 3, function() + c:emit_signal("request::activate", "titlebar", { raise = true }) + awful.mouse.client.resize(c) + end) + ) - awful.titlebar(c):setup { - { -- Left - awful.titlebar.widget.iconwidget(c), - buttons = buttons, - layout = wibox.layout.fixed.horizontal - }, - { -- Middle - { -- Title - align = "center", - widget = awful.titlebar.widget.titlewidget(c) - }, - buttons = buttons, - layout = wibox.layout.flex.horizontal - }, - { -- Right - awful.titlebar.widget.floatingbutton(c), - awful.titlebar.widget.maximizedbutton(c), - awful.titlebar.widget.stickybutton(c), - awful.titlebar.widget.ontopbutton(c), - awful.titlebar.widget.closebutton(c), - layout = wibox.layout.fixed.horizontal() - }, - layout = wibox.layout.align.horizontal - } + awful.titlebar(c):setup({ + { -- Left + awful.titlebar.widget.iconwidget(c), + buttons = buttons, + layout = wibox.layout.fixed.horizontal, + }, + { -- Middle + { -- Title + align = "center", + widget = awful.titlebar.widget.titlewidget(c), + }, + buttons = buttons, + layout = wibox.layout.flex.horizontal, + }, + { -- Right + awful.titlebar.widget.floatingbutton(c), + awful.titlebar.widget.maximizedbutton(c), + awful.titlebar.widget.stickybutton(c), + awful.titlebar.widget.ontopbutton(c), + awful.titlebar.widget.closebutton(c), + layout = wibox.layout.fixed.horizontal(), + }, + layout = wibox.layout.align.horizontal, + }) end) -- Enable sloppy focus, so that focus follows mouse. client.connect_signal("mouse::enter", function(c) - c:emit_signal("request::activate", "mouse_enter", { raise = false }) + c:emit_signal("request::activate", "mouse_enter", { raise = false }) end) -client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end) -client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end) +client.connect_signal("focus", function(c) + c.border_color = beautiful.border_focus +end) +client.connect_signal("unfocus", function(c) + c.border_color = beautiful.border_normal +end) -- }}} - -- Autostart Applications awful.spawn.with_shell("picom --experimental-backends") awful.spawn.with_shell("setxkbmap lv") diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 2d7538e4..e6c65231 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -1,21 +1,22 @@ -require ('user.options') -require ('user.keymaps') -require ('user.plugins') -require ('user.colorscheme') -require ('user.cmp') -require ('user.lsp') -require ('user.telescope') -require ('user.treesitter') -require ('user.autopairs') -require ('user.comment') -require ('user.gitsigns') -require ('user.nvim-tree') -require ('user.bufferline') -require ('user.lualine') -require ('user.toggleterm') -require ('user.project') -require ('user.impatient') -require ('user.indentline') -require ('user.alpha') -require ('user.whichkey') -require ('user.autocommands') \ No newline at end of file +require("user.options") +require("user.keymaps") +require("user.plugins") +require("user.colorscheme") +require("user.cmp") +require("user.lsp") +require("user.telescope") +require("user.treesitter") +require("user.autopairs") +require("user.comment") +require("user.gitsigns") +require("user.nvim-tree") +require("user.bufferline") +require("user.lualine") +require("user.toggleterm") +require("user.project") +require("user.impatient") +require("user.indentline") +require("user.alpha") +require("user.whichkey") +require("user.autocommands") +require("user.colorizer") diff --git a/.config/nvim/lua/user/alpha.lua b/.config/nvim/lua/user/alpha.lua index 34a34f41..b874570b 100644 --- a/.config/nvim/lua/user/alpha.lua +++ b/.config/nvim/lua/user/alpha.lua @@ -1,41 +1,41 @@ -local status_ok, alpha = pcall(require, 'alpha') +local status_ok, alpha = pcall(require, "alpha") if not status_ok then - return + return end -local dashboard = require('alpha.themes.dashboard') +local dashboard = require("alpha.themes.dashboard") dashboard.section.header.val = { - [[ __ ]], - [[ ___ ___ ___ __ __ /\_\ ___ ___ ]], - [[ / _ `\ / __`\ / __`\/\ \/\ \\/\ \ / __` __`\ ]], - [[/\ \/\ \/\ __//\ \_\ \ \ \_/ |\ \ \/\ \/\ \/\ \ ]], - [[\ \_\ \_\ \____\ \____/\ \___/ \ \_\ \_\ \_\ \_\]], - [[ \/_/\/_/\/____/\/___/ \/__/ \/_/\/_/\/_/\/_/]], + [[ __ ]], + [[ ___ ___ ___ __ __ /\_\ ___ ___ ]], + [[ / _ `\ / __`\ / __`\/\ \/\ \\/\ \ / __` __`\ ]], + [[/\ \/\ \/\ __//\ \_\ \ \ \_/ |\ \ \/\ \/\ \/\ \ ]], + [[\ \_\ \_\ \____\ \____/\ \___/ \ \_\ \_\ \_\ \_\]], + [[ \/_/\/_/\/____/\/___/ \/__/ \/_/\/_/\/_/\/_/]], } dashboard.section.buttons.val = { - dashboard.button('f', ' Find file', ':Telescope find_files '), - dashboard.button('e', ' New file', ':ene startinsert '), - dashboard.button('p', ' Find project', ':Telescope projects '), - dashboard.button('r', ' Recently used files', ':Telescope oldfiles '), - dashboard.button('t', ' Find text', ':Telescope live_grep '), - dashboard.button('c', ' Configuration', ':e ~/.config/nvim/init.lua '), - dashboard.button('q', ' Quit Neovim', ':qa'), + dashboard.button("f", " Find file", ":Telescope find_files "), + dashboard.button("e", " New file", ":ene startinsert "), + dashboard.button("p", " Find project", ":Telescope projects "), + dashboard.button("r", " Recently used files", ":Telescope oldfiles "), + dashboard.button("t", " Find text", ":Telescope live_grep "), + dashboard.button("c", " Configuration", ":e ~/.config/nvim/init.lua "), + dashboard.button("q", " Quit Neovim", ":qa"), } local function footer() --- NOTE: requires the fortune-mod package to work - -- local handle = io.popen('fortune') - -- local fortune = handle:read('*a') - -- handle:close() - -- return fortune - return 'chrisatmachine.com' + -- NOTE: requires the fortune-mod package to work + -- local handle = io.popen('fortune') + -- local fortune = handle:read('*a') + -- handle:close() + -- return fortune + return "chrisatmachine.com" end dashboard.section.footer.val = footer() -dashboard.section.footer.opts.hl = 'Type' -dashboard.section.header.opts.hl = 'Include' -dashboard.section.buttons.opts.hl = 'Keyword' +dashboard.section.footer.opts.hl = "Type" +dashboard.section.header.opts.hl = "Include" +dashboard.section.buttons.opts.hl = "Keyword" dashboard.opts.opts.noautocmd = true -- vim.cmd([[autocmd User AlphaReady echo 'ready']]) diff --git a/.config/nvim/lua/user/autocommands.lua b/.config/nvim/lua/user/autocommands.lua index 006afabd..bf23c238 100644 --- a/.config/nvim/lua/user/autocommands.lua +++ b/.config/nvim/lua/user/autocommands.lua @@ -1,10 +1,14 @@ -vim.cmd [[ +vim.cmd([[ augroup _general_settings autocmd! - autocmd FileType qf,help,man,lspinfo nnoremap q :close - autocmd TextYankPost * silent!lua require('vim.highlight').on_yank({higroup = 'Visual', timeout = 200}) + autocmd FileType qf,help,man,lspinfo nnoremap q :close + autocmd TextYankPost * silent!lua require('vim.highlight').on_yank({higroup = 'Visual', timeout = 200}) autocmd BufWinEnter * :set formatoptions-=cro autocmd FileType qf set nobuflisted + autocmd BufWritePre * %s/\s\+$//e + autocmd InsertEnter * norm zz + highlight CursorLine ctermbg=White cterm=bold guibg=#222222 + highlight CursorColumn ctermbg=White cterm=bold guibg=#222222 augroup end augroup _git @@ -21,23 +25,23 @@ vim.cmd [[ augroup _auto_resize autocmd! - autocmd VimResized * tabdo wincmd = + autocmd VimResized * tabdo wincmd = augroup end augroup _alpha autocmd! autocmd User AlphaReady set showtabline=0 | autocmd BufUnload set showtabline=2 augroup end -]] --- Autoformat --- augroup _lsp --- autocmd! --- autocmd BufWritePre * lua vim.lsp.buf.formatting() --- augroup end + augroup _lsp + autocmd! + autocmd BufWritePre,InsertLeave * lua vim.lsp.buf.formatting() + augroup end --- " Verticaly center document when entering insert mode --- autocmd InsertEnter * norm zz - --- " Remove trailing whitespace on save --- autocmd BufWritePre * %s/\s\+$//e + augroup _run + autocmd! + autocmd FileType python map wexec '!python3' shellescape(@%, 1) + autocmd FileType rust imap wexec '!cargo run' + autocmd FileType rust map wexec '!cargo run' + augroup end +]]) diff --git a/.config/nvim/lua/user/autopairs.lua b/.config/nvim/lua/user/autopairs.lua index fac46fd6..1b96b349 100644 --- a/.config/nvim/lua/user/autopairs.lua +++ b/.config/nvim/lua/user/autopairs.lua @@ -1,33 +1,33 @@ -- Setup nvim-cmp. -local status_ok, npairs = pcall(require, 'nvim-autopairs') +local status_ok, npairs = pcall(require, "nvim-autopairs") if not status_ok then - return + return end -npairs.setup { - check_ts = true, - ts_config = { - lua = { 'string', 'source' }, - javascript = { 'string', 'template_string' }, - java = false, - }, - disable_filetype = { 'TelescopePrompt', 'spectre_panel' }, - fast_wrap = { - map = '', - chars = { '{', '[', '(', "'", '"' }, - pattern = string.gsub([[ [%'%"%)%>%]%)%}%,] ]], '%s+', ''), - offset = 0, -- Offset from pattern match - end_key = '$', - keys = 'qwertyuiopzxcvbnmasdfghjkl', - check_comma = true, - highlight = 'PmenuSel', - highlight_grey = 'LineNr', - }, -} +npairs.setup({ + check_ts = true, + ts_config = { + lua = { "string", "source" }, + javascript = { "string", "template_string" }, + java = false, + }, + disable_filetype = { "TelescopePrompt", "spectre_panel" }, + fast_wrap = { + map = "", + chars = { "{", "[", "(", "'", '"' }, + pattern = string.gsub([[ [%'%"%)%>%]%)%}%,] ]], "%s+", ""), + offset = 0, -- Offset from pattern match + end_key = "$", + keys = "qwertyuiopzxcvbnmasdfghjkl", + check_comma = true, + highlight = "PmenuSel", + highlight_grey = "LineNr", + }, +}) -local cmp_autopairs = require 'nvim-autopairs.completion.cmp' -local cmp_status_ok, cmp = pcall(require, 'cmp') +local cmp_autopairs = require("nvim-autopairs.completion.cmp") +local cmp_status_ok, cmp = pcall(require, "cmp") if not cmp_status_ok then - return + return end -cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done { map_char = { tex = '' } }) +cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done({ map_char = { tex = "" } })) diff --git a/.config/nvim/lua/user/bufferline.lua b/.config/nvim/lua/user/bufferline.lua index 1cee577d..5f8dbf4f 100644 --- a/.config/nvim/lua/user/bufferline.lua +++ b/.config/nvim/lua/user/bufferline.lua @@ -1,167 +1,167 @@ -local status_ok, bufferline = pcall(require, 'bufferline') +local status_ok, bufferline = pcall(require, "bufferline") if not status_ok then - return + return end -bufferline.setup { - options = { - numbers = 'none', -- | 'ordinal' | 'buffer_id' | 'both' | function({ ordinal, id, lower, raise }): string, - close_command = 'Bdelete! %d', -- can be a string | function, see 'Mouse actions' - right_mouse_command = 'Bdelete! %d', -- can be a string | function, see 'Mouse actions' - left_mouse_command = 'buffer %d', -- can be a string | function, see 'Mouse actions' - middle_mouse_command = nil, -- can be a string | function, see 'Mouse actions' - -- NOTE: this plugin is designed with this icon in mind, - -- and so changing this is NOT recommended, this is intended - -- as an escape hatch for people who cannot bear it for whatever reason - indicator_icon = '▎', - buffer_close_icon = '', - -- buffer_close_icon = '', - modified_icon = '●', - close_icon = '', - -- close_icon = '', - left_trunc_marker = '', - right_trunc_marker = '', - --- name_formatter can be used to change the buffer's label in the bufferline. - --- Please note some names can/will break the - --- bufferline so use this at your discretion knowing that it has - --- some limitations that will *NOT* be fixed. - -- name_formatter = function(buf) -- buf contains a 'name', 'path' and 'bufnr' - -- -- remove extension from markdown files for example - -- if buf.name:match('%.md') then - -- return vim.fn.fnamemodify(buf.name, ':t:r') - -- end - -- end, - max_name_length = 30, - max_prefix_length = 30, -- prefix used when a buffer is de-duplicated - tab_size = 21, - diagnostics = false, -- | 'nvim_lsp' | 'coc', - diagnostics_update_in_insert = false, - -- diagnostics_indicator = function(count, level, diagnostics_dict, context) - -- return '('..count..')' - -- end, - -- NOTE: this will be called a lot so don't do any heavy processing here - -- custom_filter = function(buf_number) - -- -- filter out filetypes you don't want to see - -- if vim.bo[buf_number].filetype ~= '' then - -- return true - -- end - -- -- filter out by buffer name - -- if vim.fn.bufname(buf_number) ~= '' then - -- return true - -- end - -- -- filter out based on arbitrary rules - -- -- e.g. filter out vim wiki buffer from tabline in your work repo - -- if vim.fn.getcwd() == '' and vim.bo[buf_number].filetype ~= 'wiki' then - -- return true - -- end - -- end, - offsets = { { filetype = 'NvimTree', text = '', padding = 1 } }, - show_buffer_icons = true, - show_buffer_close_icons = true, - show_close_icon = true, - show_tab_indicators = true, - persist_buffer_sort = true, -- whether or not custom sorted buffers should persist - -- can also be a table containing 2 custom separators - -- [focused and unfocused]. eg: { '|', '|' } - separator_style = 'thin', -- | 'thick' | 'thin' | { 'any', 'any' }, - enforce_regular_tabs = true, - always_show_bufferline = true, - -- sort_by = 'id' | 'extension' | 'relative_directory' | 'directory' | 'tabs' | function(buffer_a, buffer_b) - -- -- add custom logic - -- return buffer_a.modified > buffer_b.modified - -- end - }, - highlights = { - fill = { - guifg = { attribute = 'fg', highlight = '#ff0000' }, - guibg = { attribute = 'bg', highlight = 'TabLine' }, - }, - background = { - guifg = { attribute = 'fg', highlight = 'TabLine' }, - guibg = { attribute = 'bg', highlight = 'TabLine' }, - }, +bufferline.setup({ + options = { + numbers = "none", -- | 'ordinal' | 'buffer_id' | 'both' | function({ ordinal, id, lower, raise }): string, + close_command = "Bdelete! %d", -- can be a string | function, see 'Mouse actions' + right_mouse_command = "Bdelete! %d", -- can be a string | function, see 'Mouse actions' + left_mouse_command = "buffer %d", -- can be a string | function, see 'Mouse actions' + middle_mouse_command = nil, -- can be a string | function, see 'Mouse actions' + -- NOTE: this plugin is designed with this icon in mind, + -- and so changing this is NOT recommended, this is intended + -- as an escape hatch for people who cannot bear it for whatever reason + indicator_icon = "▎", + buffer_close_icon = "", + -- buffer_close_icon = '', + modified_icon = "●", + close_icon = "", + -- close_icon = '', + left_trunc_marker = "", + right_trunc_marker = "", + --- name_formatter can be used to change the buffer's label in the bufferline. + --- Please note some names can/will break the + --- bufferline so use this at your discretion knowing that it has + --- some limitations that will *NOT* be fixed. + -- name_formatter = function(buf) -- buf contains a 'name', 'path' and 'bufnr' + -- -- remove extension from markdown files for example + -- if buf.name:match('%.md') then + -- return vim.fn.fnamemodify(buf.name, ':t:r') + -- end + -- end, + max_name_length = 30, + max_prefix_length = 30, -- prefix used when a buffer is de-duplicated + tab_size = 21, + diagnostics = false, -- | 'nvim_lsp' | 'coc', + diagnostics_update_in_insert = false, + -- diagnostics_indicator = function(count, level, diagnostics_dict, context) + -- return '('..count..')' + -- end, + -- NOTE: this will be called a lot so don't do any heavy processing here + -- custom_filter = function(buf_number) + -- -- filter out filetypes you don't want to see + -- if vim.bo[buf_number].filetype ~= '' then + -- return true + -- end + -- -- filter out by buffer name + -- if vim.fn.bufname(buf_number) ~= '' then + -- return true + -- end + -- -- filter out based on arbitrary rules + -- -- e.g. filter out vim wiki buffer from tabline in your work repo + -- if vim.fn.getcwd() == '' and vim.bo[buf_number].filetype ~= 'wiki' then + -- return true + -- end + -- end, + offsets = { { filetype = "NvimTree", text = "", padding = 1 } }, + show_buffer_icons = true, + show_buffer_close_icons = true, + show_close_icon = true, + show_tab_indicators = true, + persist_buffer_sort = true, -- whether or not custom sorted buffers should persist + -- can also be a table containing 2 custom separators + -- [focused and unfocused]. eg: { '|', '|' } + separator_style = "thin", -- | 'thick' | 'thin' | { 'any', 'any' }, + enforce_regular_tabs = true, + always_show_bufferline = true, + -- sort_by = 'id' | 'extension' | 'relative_directory' | 'directory' | 'tabs' | function(buffer_a, buffer_b) + -- -- add custom logic + -- return buffer_a.modified > buffer_b.modified + -- end + }, + highlights = { + fill = { + guifg = { attribute = "fg", highlight = "#ff0000" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + background = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, - -- buffer_selected = { - -- guifg = {attribute='fg',highlight='#ff0000'}, - -- guibg = {attribute='bg',highlight='#0000ff'}, - -- gui = 'none' - -- }, - buffer_visible = { - guifg = { attribute = 'fg', highlight = 'TabLine' }, - guibg = { attribute = 'bg', highlight = 'TabLine' }, - }, + -- buffer_selected = { + -- guifg = {attribute='fg',highlight='#ff0000'}, + -- guibg = {attribute='bg',highlight='#0000ff'}, + -- gui = 'none' + -- }, + buffer_visible = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, - close_button = { - guifg = { attribute = 'fg', highlight = 'TabLine' }, - guibg = { attribute = 'bg', highlight = 'TabLine' }, - }, - close_button_visible = { - guifg = { attribute = 'fg', highlight = 'TabLine' }, - guibg = { attribute = 'bg', highlight = 'TabLine' }, - }, - -- close_button_selected = { - -- guifg = {attribute='fg',highlight='TabLineSel'}, - -- guibg ={attribute='bg',highlight='TabLineSel'} - -- }, + close_button = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + close_button_visible = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + -- close_button_selected = { + -- guifg = {attribute='fg',highlight='TabLineSel'}, + -- guibg ={attribute='bg',highlight='TabLineSel'} + -- }, - tab_selected = { - guifg = { attribute = 'fg', highlight = 'Normal' }, - guibg = { attribute = 'bg', highlight = 'Normal' }, - }, - tab = { - guifg = { attribute = 'fg', highlight = 'TabLine' }, - guibg = { attribute = 'bg', highlight = 'TabLine' }, - }, - tab_close = { - -- guifg = {attribute='fg',highlight='LspDiagnosticsDefaultError'}, - guifg = { attribute = 'fg', highlight = 'TabLineSel' }, - guibg = { attribute = 'bg', highlight = 'Normal' }, - }, + tab_selected = { + guifg = { attribute = "fg", highlight = "Normal" }, + guibg = { attribute = "bg", highlight = "Normal" }, + }, + tab = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + tab_close = { + -- guifg = {attribute='fg',highlight='LspDiagnosticsDefaultError'}, + guifg = { attribute = "fg", highlight = "TabLineSel" }, + guibg = { attribute = "bg", highlight = "Normal" }, + }, - duplicate_selected = { - guifg = { attribute = 'fg', highlight = 'TabLineSel' }, - guibg = { attribute = 'bg', highlight = 'TabLineSel' }, - gui = 'italic', - }, - duplicate_visible = { - guifg = { attribute = 'fg', highlight = 'TabLine' }, - guibg = { attribute = 'bg', highlight = 'TabLine' }, - gui = 'italic', - }, - duplicate = { - guifg = { attribute = 'fg', highlight = 'TabLine' }, - guibg = { attribute = 'bg', highlight = 'TabLine' }, - gui = 'italic', - }, + duplicate_selected = { + guifg = { attribute = "fg", highlight = "TabLineSel" }, + guibg = { attribute = "bg", highlight = "TabLineSel" }, + gui = "italic", + }, + duplicate_visible = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + gui = "italic", + }, + duplicate = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + gui = "italic", + }, - modified = { - guifg = { attribute = 'fg', highlight = 'TabLine' }, - guibg = { attribute = 'bg', highlight = 'TabLine' }, - }, - modified_selected = { - guifg = { attribute = 'fg', highlight = 'Normal' }, - guibg = { attribute = 'bg', highlight = 'Normal' }, - }, - modified_visible = { - guifg = { attribute = 'fg', highlight = 'TabLine' }, - guibg = { attribute = 'bg', highlight = 'TabLine' }, - }, + modified = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + modified_selected = { + guifg = { attribute = "fg", highlight = "Normal" }, + guibg = { attribute = "bg", highlight = "Normal" }, + }, + modified_visible = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, - separator = { - guifg = { attribute = 'bg', highlight = 'TabLine' }, - guibg = { attribute = 'bg', highlight = 'TabLine' }, - }, - separator_selected = { - guifg = { attribute = 'bg', highlight = 'Normal' }, - guibg = { attribute = 'bg', highlight = 'Normal' }, - }, - -- separator_visible = { - -- guifg = {attribute='bg',highlight='TabLine'}, - -- guibg = {attribute='bg',highlight='TabLine'} - -- }, - indicator_selected = { - guifg = { attribute = 'fg', highlight = 'LspDiagnosticsDefaultHint' }, - guibg = { attribute = 'bg', highlight = 'Normal' }, - }, - }, -} + separator = { + guifg = { attribute = "bg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + separator_selected = { + guifg = { attribute = "bg", highlight = "Normal" }, + guibg = { attribute = "bg", highlight = "Normal" }, + }, + -- separator_visible = { + -- guifg = {attribute='bg',highlight='TabLine'}, + -- guibg = {attribute='bg',highlight='TabLine'} + -- }, + indicator_selected = { + guifg = { attribute = "fg", highlight = "LspDiagnosticsDefaultHint" }, + guibg = { attribute = "bg", highlight = "Normal" }, + }, + }, +}) diff --git a/.config/nvim/lua/user/cmp.lua b/.config/nvim/lua/user/cmp.lua index 7763a2bc..df46cddd 100644 --- a/.config/nvim/lua/user/cmp.lua +++ b/.config/nvim/lua/user/cmp.lua @@ -1,131 +1,133 @@ -local cmp_status_ok, cmp = pcall(require, 'cmp') +local cmp_status_ok, cmp = pcall(require, "cmp") if not cmp_status_ok then - return + return end -local snip_status_ok, luasnip = pcall(require, 'luasnip') +local snip_status_ok, luasnip = pcall(require, "luasnip") if not snip_status_ok then - return + return end -require('luasnip/loaders/from_vscode').lazy_load() +require("luasnip/loaders/from_vscode").lazy_load() local check_backspace = function() - local col = vim.fn.col '.' - 1 - return col == 0 or vim.fn.getline('.'):sub(col, col):match '%s' + local col = vim.fn.col(".") - 1 + return col == 0 or vim.fn.getline("."):sub(col, col):match("%s") end --   פּ ﯟ   some other good icons local kind_icons = { - Text = '', - Method = 'm', - Function = '', - Constructor = '', - Field = '', - Variable = '', - Class = '', - Interface = '', - Module = '', - Property = '', - Unit = '', - Value = '', - Enum = '', - Keyword = '', - Snippet = '', - Color = '', - File = '', - Reference = '', - Folder = '', - EnumMember = '', - Constant = '', - Struct = '', - Event = '', - Operator = '', - TypeParameter = '', + Text = "", + Method = "m", + Function = "", + Constructor = "", + Field = "", + Variable = "", + Class = "", + Interface = "", + Module = "", + Property = "", + Unit = "", + Value = "", + Enum = "", + Keyword = "", + Snippet = "", + Color = "", + File = "", + Reference = "", + Folder = "", + EnumMember = "", + Constant = "", + Struct = "", + Event = "", + Operator = "", + TypeParameter = "", } -- find more here: https://www.nerdfonts.com/cheat-sheet -cmp.setup { - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) -- For `luasnip` users. - end, - }, - mapping = { - [''] = cmp.mapping.select_prev_item(), - [''] = cmp.mapping.select_next_item(), - [''] = cmp.mapping(cmp.mapping.scroll_docs(-1), { 'i', 'c' }), - [''] = cmp.mapping(cmp.mapping.scroll_docs(1), { 'i', 'c' }), - [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), - [''] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `` mapping. - [''] = cmp.mapping { - i = cmp.mapping.abort(), - c = cmp.mapping.close(), - }, - -- Accept currently selected item. If none selected, `select` first item. - -- Set `select` to `false` to only confirm explicitly selected items. - [''] = cmp.mapping.confirm { select = true }, - [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expandable() then - luasnip.expand() - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - elseif check_backspace() then - fallback() - else - fallback() - end - end, { - 'i', - 's', - }), - [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, { - 'i', - 's', - }), - }, - formatting = { - fields = { 'kind', 'abbr', 'menu' }, - format = function(entry, vim_item) - -- Kind icons - vim_item.kind = string.format('%s', kind_icons[vim_item.kind]) - -- vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind - vim_item.menu = ({ - nvim_lsp = '[LSP]', - luasnip = '[Snippet]', - buffer = '[Buffer]', - path = '[Path]', - })[entry.source.name] - return vim_item - end, - }, - sources = { - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - { name = 'buffer' }, - { name = 'path' }, - }, - confirm_opts = { - behavior = cmp.ConfirmBehavior.Replace, - select = false, - }, - window = { - documentation = { - border = { '╭', '─', '╮', '│', '╯', '─', '╰', '│' }, - }, - }, - experimental = { - ghost_text = false, - native_menu = false, - }, -} +cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) -- For `luasnip` users. + end, + }, + mapping = { + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.scroll_docs(1), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }), + [""] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `` mapping. + [""] = cmp.mapping({ + i = cmp.mapping.abort(), + c = cmp.mapping.close(), + }), + -- Accept currently selected item. If none selected, `select` first item. + -- Set `select` to `false` to only confirm explicitly selected items. + [""] = cmp.mapping.confirm({ select = true }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expandable() then + luasnip.expand() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif check_backspace() then + fallback() + else + fallback() + end + end, { + "i", + "s", + }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { + "i", + "s", + }), + }, + formatting = { + fields = { "kind", "abbr", "menu" }, + format = function(entry, vim_item) + -- Kind icons + vim_item.kind = string.format("%s", kind_icons[vim_item.kind]) + -- vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind + vim_item.menu = ({ + nvim_lsp = "[LSP]", + nvim_lua = "[NVIM_LUA]", + luasnip = "[Snippet]", + buffer = "[Buffer]", + path = "[Path]", + })[entry.source.name] + return vim_item + end, + }, + sources = { + { name = "nvim_lsp" }, + { name = "nvim_lua" }, + { name = "luasnip" }, + { name = "buffer" }, + { name = "path" }, + }, + confirm_opts = { + behavior = cmp.ConfirmBehavior.Replace, + select = false, + }, + window = { + documentation = { + border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, + }, + }, + experimental = { + ghost_text = false, + native_menu = false, + }, +}) diff --git a/.config/nvim/lua/user/colorizer.lua b/.config/nvim/lua/user/colorizer.lua new file mode 100644 index 00000000..ba8fcc52 --- /dev/null +++ b/.config/nvim/lua/user/colorizer.lua @@ -0,0 +1,6 @@ +local status_ok, colorizer = pcall(require, "colorizer") +if not status_ok then + return +end + +colorizer.setup() diff --git a/.config/nvim/lua/user/colorscheme.lua b/.config/nvim/lua/user/colorscheme.lua index 33c54f37..56aacd98 100644 --- a/.config/nvim/lua/user/colorscheme.lua +++ b/.config/nvim/lua/user/colorscheme.lua @@ -1,8 +1,8 @@ -vim.cmd [[ +vim.cmd([[ try colorscheme dracula catch /^Vim\%((\a\+)\)\=:E185/ colorscheme default set background=dark endtry -]] +]]) diff --git a/.config/nvim/lua/user/comment.lua b/.config/nvim/lua/user/comment.lua index ab9b64a5..07c1a2a5 100644 --- a/.config/nvim/lua/user/comment.lua +++ b/.config/nvim/lua/user/comment.lua @@ -1,22 +1,22 @@ -local status_ok, comment = pcall(require, 'Comment') +local status_ok, comment = pcall(require, "Comment") if not status_ok then - return + return end -comment.setup { - pre_hook = function(ctx) - local U = require 'Comment.utils' +comment.setup({ + pre_hook = function(ctx) + local U = require("Comment.utils") - local location = nil - if ctx.ctype == U.ctype.block then - location = require('ts_context_commentstring.utils').get_cursor_location() - elseif ctx.cmotion == U.cmotion.v or ctx.cmotion == U.cmotion.V then - location = require('ts_context_commentstring.utils').get_visual_start_location() - end + local location = nil + if ctx.ctype == U.ctype.block then + location = require("ts_context_commentstring.utils").get_cursor_location() + elseif ctx.cmotion == U.cmotion.v or ctx.cmotion == U.cmotion.V then + location = require("ts_context_commentstring.utils").get_visual_start_location() + end - return require('ts_context_commentstring.internal').calculate_commentstring { - key = ctx.ctype == U.ctype.line and '__default' or '__multiline', - location = location, - } - end, -} + return require("ts_context_commentstring.internal").calculate_commentstring({ + key = ctx.ctype == U.ctype.line and "__default" or "__multiline", + location = location, + }) + end, +}) diff --git a/.config/nvim/lua/user/gitsigns.lua b/.config/nvim/lua/user/gitsigns.lua index b41f03d7..07b71464 100644 --- a/.config/nvim/lua/user/gitsigns.lua +++ b/.config/nvim/lua/user/gitsigns.lua @@ -1,48 +1,48 @@ -local status_ok, gitsigns = pcall(require, 'gitsigns') +local status_ok, gitsigns = pcall(require, "gitsigns") if not status_ok then - return + return end -gitsigns.setup { - signs = { - add = { hl = 'GitSignsAdd', text = '▎', numhl = 'GitSignsAddNr', linehl = 'GitSignsAddLn' }, - change = { hl = 'GitSignsChange', text = '▎', numhl = 'GitSignsChangeNr', linehl = 'GitSignsChangeLn' }, - delete = { hl = 'GitSignsDelete', text = '契', numhl = 'GitSignsDeleteNr', linehl = 'GitSignsDeleteLn' }, - topdelete = { hl = 'GitSignsDelete', text = '契', numhl = 'GitSignsDeleteNr', linehl = 'GitSignsDeleteLn' }, - changedelete = { hl = 'GitSignsChange', text = '▎', numhl = 'GitSignsChangeNr', linehl = 'GitSignsChangeLn' }, - }, - signcolumn = true, -- Toggle with `:Gitsigns toggle_signs` - numhl = false, -- Toggle with `:Gitsigns toggle_numhl` - linehl = false, -- Toggle with `:Gitsigns toggle_linehl` - word_diff = false, -- Toggle with `:Gitsigns toggle_word_diff` - watch_gitdir = { - interval = 1000, - follow_files = true, - }, - attach_to_untracked = true, - current_line_blame = false, -- Toggle with `:Gitsigns toggle_current_line_blame` - current_line_blame_opts = { - virt_text = true, - virt_text_pos = 'eol', -- 'eol' | 'overlay' | 'right_align' - delay = 1000, - ignore_whitespace = false, - }, - current_line_blame_formatter_opts = { - relative_time = false, - }, - sign_priority = 6, - update_debounce = 100, - status_formatter = nil, -- Use default - max_file_length = 40000, - preview_config = { - -- Options passed to nvim_open_win - border = 'single', - style = 'minimal', - relative = 'cursor', - row = 0, - col = 1, - }, - yadm = { - enable = false, - }, -} +gitsigns.setup({ + signs = { + add = { hl = "GitSignsAdd", text = "▎", numhl = "GitSignsAddNr", linehl = "GitSignsAddLn" }, + change = { hl = "GitSignsChange", text = "▎", numhl = "GitSignsChangeNr", linehl = "GitSignsChangeLn" }, + delete = { hl = "GitSignsDelete", text = "契", numhl = "GitSignsDeleteNr", linehl = "GitSignsDeleteLn" }, + topdelete = { hl = "GitSignsDelete", text = "契", numhl = "GitSignsDeleteNr", linehl = "GitSignsDeleteLn" }, + changedelete = { hl = "GitSignsChange", text = "▎", numhl = "GitSignsChangeNr", linehl = "GitSignsChangeLn" }, + }, + signcolumn = true, -- Toggle with `:Gitsigns toggle_signs` + numhl = false, -- Toggle with `:Gitsigns toggle_numhl` + linehl = false, -- Toggle with `:Gitsigns toggle_linehl` + word_diff = false, -- Toggle with `:Gitsigns toggle_word_diff` + watch_gitdir = { + interval = 1000, + follow_files = true, + }, + attach_to_untracked = true, + current_line_blame = false, -- Toggle with `:Gitsigns toggle_current_line_blame` + current_line_blame_opts = { + virt_text = true, + virt_text_pos = "eol", -- 'eol' | 'overlay' | 'right_align' + delay = 1000, + ignore_whitespace = false, + }, + current_line_blame_formatter_opts = { + relative_time = false, + }, + sign_priority = 6, + update_debounce = 100, + status_formatter = nil, -- Use default + max_file_length = 40000, + preview_config = { + -- Options passed to nvim_open_win + border = "single", + style = "minimal", + relative = "cursor", + row = 0, + col = 1, + }, + yadm = { + enable = false, + }, +}) diff --git a/.config/nvim/lua/user/impatient.lua b/.config/nvim/lua/user/impatient.lua index f0a7d7d8..fa64f003 100644 --- a/.config/nvim/lua/user/impatient.lua +++ b/.config/nvim/lua/user/impatient.lua @@ -1,6 +1,6 @@ -local status_ok, impatient = pcall(require, 'impatient') +local status_ok, impatient = pcall(require, "impatient") if not status_ok then - return + return end impatient.enable_profile() diff --git a/.config/nvim/lua/user/indentline.lua b/.config/nvim/lua/user/indentline.lua index 84ed4cbb..9b0b8c70 100644 --- a/.config/nvim/lua/user/indentline.lua +++ b/.config/nvim/lua/user/indentline.lua @@ -1,73 +1,73 @@ local g = vim.g local opt = vim.opt local cmd = vim.cmd -local status_ok, indent_blankline = pcall(require, 'indent_blankline') +local status_ok, indent_blankline = pcall(require, "indent_blankline") if not status_ok then - return + return end -g.indent_blankline_buftype_exclude = { 'terminal', 'nofile' } +g.indent_blankline_buftype_exclude = { "terminal", "nofile" } g.indent_blankline_filetype_exclude = { - 'help', - 'startify', - 'dashboard', - 'packer', - 'neogitstatus', - 'NvimTree', - 'Trouble', + "help", + "startify", + "dashboard", + "packer", + "neogitstatus", + "NvimTree", + "Trouble", } g.indentLine_enabled = 1 -- g.indent_blankline_char = '│' -g.indent_blankline_char = '▏' +g.indent_blankline_char = "▏" -- g.indent_blankline_char = '▎' g.indent_blankline_show_trailing_blankline_indent = false g.indent_blankline_show_first_indent_level = true g.indent_blankline_use_treesitter = true g.indent_blankline_show_current_context = true g.indent_blankline_context_patterns = { - 'class', - 'return', - 'function', - 'method', - '^if', - '^while', - 'jsx_element', - '^for', - '^object', - '^table', - 'block', - 'arguments', - 'if_statement', - 'else_clause', - 'jsx_element', - 'jsx_self_closing_element', - 'try_statement', - 'catch_clause', - 'import_statement', - 'operation_type', + "class", + "return", + "function", + "method", + "^if", + "^while", + "jsx_element", + "^for", + "^object", + "^table", + "block", + "arguments", + "if_statement", + "else_clause", + "jsx_element", + "jsx_self_closing_element", + "try_statement", + "catch_clause", + "import_statement", + "operation_type", } -- HACK: work-around for https://github.com/lukas-reineke/indent-blankline.nvim/issues/59 -vim.wo.colorcolumn = '99999' +vim.wo.colorcolumn = "99999" --- cmd [[highlight IndentBlanklineIndent1 guifg=#E06C75 gui=nocombine]] --- cmd [[highlight IndentBlanklineIndent2 guifg=#E5C07B gui=nocombine]] --- cmd [[highlight IndentBlanklineIndent3 guifg=#98C379 gui=nocombine]] --- cmd [[highlight IndentBlanklineIndent4 guifg=#56B6C2 gui=nocombine]] --- cmd [[highlight IndentBlanklineIndent5 guifg=#61AFEF gui=nocombine]] --- cmd [[highlight IndentBlanklineIndent6 guifg=#C678DD gui=nocombine]] --- opt.list = true --- opt.listchars:append 'space:⋅' +cmd([[highlight IndentBlanklineIndent1 guifg=#E06C75 gui=nocombine]]) +cmd([[highlight IndentBlanklineIndent2 guifg=#E5C07B gui=nocombine]]) +cmd([[highlight IndentBlanklineIndent3 guifg=#98C379 gui=nocombine]]) +cmd([[highlight IndentBlanklineIndent4 guifg=#56B6C2 gui=nocombine]]) +cmd([[highlight IndentBlanklineIndent5 guifg=#61AFEF gui=nocombine]]) +cmd([[highlight IndentBlanklineIndent6 guifg=#C678DD gui=nocombine]]) +opt.list = true +opt.listchars:append("space:⋅") -- opt.listchars:append 'space:' --- opt.listchars:append 'eol:↴' +opt.listchars:append("eol:↴") indent_blankline.setup({ - -- show_end_of_line = true, - -- space_char_blankline = ' ', - show_current_context = true, - -- show_current_context_start = true, - -- char_highlight_list = { - -- 'IndentBlanklineIndent1', - -- 'IndentBlanklineIndent2', - -- 'IndentBlanklineIndent3', - -- }, + -- show_end_of_line = true, + -- space_char_blankline = ' ', + show_current_context = true, + -- show_current_context_start = true, + -- char_highlight_list = { + -- 'IndentBlanklineIndent1', + -- 'IndentBlanklineIndent2', + -- 'IndentBlanklineIndent3', + -- }, }) diff --git a/.config/nvim/lua/user/keymaps.lua b/.config/nvim/lua/user/keymaps.lua index 6ab01f3e..8cade6b8 100644 --- a/.config/nvim/lua/user/keymaps.lua +++ b/.config/nvim/lua/user/keymaps.lua @@ -3,9 +3,9 @@ local opts = { noremap = true, silent = true } local term_opts = { silent = true } --Remap space as leader key -keymap('', '', '', opts) -vim.g.mapleader = ' ' -vim.g.maplocalleader = ' ' +keymap("", "", "", opts) +vim.g.mapleader = " " +vim.g.maplocalleader = " " -- Modes -- normal_mode = 'n', @@ -17,45 +17,45 @@ vim.g.maplocalleader = ' ' -- Normal -- -- Shortcutting split navigation -keymap('n', '', 'h', opts) -keymap('n', '', 'j', opts) -keymap('n', '', 'k', opts) -keymap('n', '', 'l', opts) +keymap("n", "", "h", opts) +keymap("n", "", "j", opts) +keymap("n", "", "k", opts) +keymap("n", "", "l", opts) -- Resize with arrows -keymap('n', '', 'resize -2', opts) -keymap('n', '', 'resize +2', opts) -keymap('n', '', 'vertical resize -2', opts) -keymap('n', '', 'vertical resize +2', opts) +keymap("n", "", "resize -2", opts) +keymap("n", "", "resize +2", opts) +keymap("n", "", "vertical resize -2", opts) +keymap("n", "", "vertical resize +2", opts) -- Navigate buffers -keymap('n', '', 'bnext', opts) -keymap('n', '', 'bprevious', opts) +keymap("n", "", "bnext", opts) +keymap("n", "", "bprevious", opts) -- Move text up and down -keymap('n', '', 'm .+1==gi', opts) -keymap('n', '', 'm .-2==gi', opts) +keymap("n", "", "m .+1", opts) +keymap("n", "", "m .-2", opts) -- Insert -- --- Press jk fast to exit insert mode -keymap('i', 'jk', '', opts) +-- Press jk fast to exit insert mode +keymap("i", "jk", "", opts) -- Visual -- -- Stay in indent mode -keymap('v', '<', '', '>gv', opts) +keymap("v", "<", "", ">gv", opts) -- Move text up and down -keymap('v', '', 'm .+1==', opts) -keymap('v', '', 'm .-2==', opts) -keymap('v', 'p', '"_dP', opts) +keymap("v", "", "m .+1", opts) +keymap("v", "", "m .-2", opts) +keymap("v", "p", '"_dP', opts) -- Visual Block -- -- Move text up and down -keymap('x', 'J', 'move ">+1gv-gv', opts) -keymap('x', 'K', 'move "<-2gv-gv', opts) -keymap('x', '', 'move ">+1gv-gv', opts) -keymap('x', '', 'move "<-2gv-gv', opts) +keymap("x", "J", 'move ">+1gv-gv', opts) +keymap("x", "K", 'move "<-2gv-gv', opts) +keymap("x", "", 'move ">+1gv-gv', opts) +keymap("x", "", 'move "<-2gv-gv', opts) -- Terminal -- -- Better terminal navigation @@ -63,46 +63,3 @@ keymap('x', '', 'move "<-2gv-gv', opts) -- keymap('t', '', 'j', term_opts) -- keymap('t', '', 'k', term_opts) -- keymap('t', '', 'l', term_opts) - -keymap('n', 'n', ':NvimTreeFocus', opts) -keymap('n', 'C-t', ':NvimTreeToggle', opts) -keymap('n', 'C-f', ':NvimTreeFindFile', opts) -keymap('n', '', ':NvimTreeRefresh', opts) - --- Enable/Disable auto comment -keymap('', 'c', 'setlocal formatoption-=CRo', {}) -keymap('', 'C', 'setlocal formatoption=CRo', {}) - --- Enable spell checking, s for spell check -keymap('', 's', 'setlocal spell! spelllang=eu_us', {}) - --- Enable / Disable auto indent -keymap('', 'i', 'setlocal autoindent', {}) -keymap('', 'I', 'setlocal noautoindent', {}) - --- Moving line up or down by one line -keymap('', '', 'm -2', opts) -keymap('', '', 'm -2', opts) -keymap('', '', 'm +1', opts) -keymap('', '', 'm +1', opts) - --- Find files using Telescope command-line -keymap('n', 'ff', 'Telescope find_files hidden=true', opts) -keymap('n', 'fg', 'Telescope live_grep', opts) -keymap('n', 'fb', 'Telescope buffers', opts) -keymap('n', 'fh', 'Telescope help_tags', opts) - --- Alias 'replace all' to S -keymap('n', 'S', 's%//', opts) - - --- " run current script with python3 by CTRL+R in command and insert mode --- autocmd FileType python map wexec '!python3' shellescape(@%, 1) --- autocmd FileType python imap wexec '!python3' shellescape(@%, 1) --- autocmd FileType rust map wexec '!cargo run' --- autocmd FileType rust imap wexec '!cargo run' - --- autocmd BufWritePre,InsertLeave *.{py,rs,html,css,md,lua} Neoformat --- let g:neoformat_enabled_python = ['autopep8'] --- let g:neoformat_try_node_exe = 1 - diff --git a/.config/nvim/lua/user/lsp/configs.lua b/.config/nvim/lua/user/lsp/configs.lua index cbc2a203..6bf23738 100644 --- a/.config/nvim/lua/user/lsp/configs.lua +++ b/.config/nvim/lua/user/lsp/configs.lua @@ -1,24 +1,24 @@ -local status_ok, lsp_installer = pcall(require, 'nvim-lsp-installer') +local status_ok, lsp_installer = pcall(require, "nvim-lsp-installer") if not status_ok then - return + return end -local lspconfig = require('lspconfig') +local lspconfig = require("lspconfig") -local servers = { 'jsonls', 'sumneko_lua', 'pyright' } +local servers = { "jsonls", "sumneko_lua", "pyright" } lsp_installer.setup({ - ensure_installed = servers, + ensure_installed = servers, }) for _, server in pairs(servers) do - local opts = { - on_attach = require('user.lsp.handlers').on_attach, - capabilities = require('user.lsp.handlers').capabilities, - } - local has_custom_opts, server_custom_opts = pcall(require, 'user.lsp.settings.' .. server) - if has_custom_opts then - opts = vim.tbl_deep_extend('force', opts, server_custom_opts) - end - lspconfig[server].setup(opts) + local opts = { + on_attach = require("user.lsp.handlers").on_attach, + capabilities = require("user.lsp.handlers").capabilities, + } + local has_custom_opts, server_custom_opts = pcall(require, "user.lsp.settings." .. server) + if has_custom_opts then + opts = vim.tbl_deep_extend("force", opts, server_custom_opts) + end + lspconfig[server].setup(opts) end diff --git a/.config/nvim/lua/user/lsp/handlers.lua b/.config/nvim/lua/user/lsp/handlers.lua index 1c857529..d1344f70 100644 --- a/.config/nvim/lua/user/lsp/handlers.lua +++ b/.config/nvim/lua/user/lsp/handlers.lua @@ -1,100 +1,99 @@ local M = {} +local api = vim.api +local lsp = vim.lsp -- TODO: backfill this to template M.setup = function() - local signs = { - { name = 'DiagnosticSignError', text = '' }, - { name = 'DiagnosticSignWarn', text = '' }, - { name = 'DiagnosticSignHint', text = '' }, - { name = 'DiagnosticSignInfo', text = '' }, - } + local signs = { + { name = "DiagnosticSignError", text = "" }, + { name = "DiagnosticSignWarn", text = "" }, + { name = "DiagnosticSignHint", text = "" }, + { name = "DiagnosticSignInfo", text = "" }, + } - for _, sign in ipairs(signs) do - vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = '' }) - end + for _, sign in ipairs(signs) do + vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = "" }) + end - local config = { - -- disable virtual text - virtual_text = false, - -- show signs - signs = { - active = signs, - }, - update_in_insert = true, - underline = true, - severity_sort = true, - float = { - focusable = false, - style = 'minimal', - border = 'rounded', - source = 'always', - header = '', - prefix = '', - }, - } + local config = { + -- disable virtual text + virtual_text = false, + -- show signs + signs = { + active = signs, + }, + update_in_insert = true, + underline = true, + severity_sort = true, + float = { + focusable = false, + style = "minimal", + border = "rounded", + source = "always", + header = "", + prefix = "", + }, + } - vim.diagnostic.config(config) + vim.diagnostic.config(config) - vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { - border = 'rounded', - width = 60, - }) + lsp.handlers["textDocument/hover"] = lsp.with(lsp.handlers.hover, { + border = "rounded", + width = 60, + }) - vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.signature_help, { - border = 'rounded', - width = 60, - }) + lsp.handlers["textDocument/signatureHelp"] = lsp.with(lsp.handlers.signature_help, { + border = "rounded", + width = 60, + }) end local function lsp_highlight_document(client) - -- Set autocommands conditional on server_capabilities - local status_ok, illuminate = pcall(require, 'illuminate') - if not status_ok then - return - end - illuminate.on_attach(client) - -- end + -- Set autocommands conditional on server_capabilities + local status_ok, illuminate = pcall(require, "illuminate") + if not status_ok then + return + end + illuminate.on_attach(client) + -- end end local function lsp_keymaps(bufnr) - local opts = { noremap = true, silent = true } - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', 'lua vim.lsp.buf.declaration()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', 'lua vim.lsp.buf.definition()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', 'lua vim.lsp.buf.hover()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', 'lua vim.lsp.buf.implementation()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', '', 'lua vim.lsp.buf.signature_help()', opts) - -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'rn', 'lua vim.lsp.buf.rename()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', 'lua vim.lsp.buf.references()', opts) - -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'ca', 'lua vim.lsp.buf.code_action()', opts) - -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'f', 'lua vim.diagnostic.open_float()', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', '[d', 'lua vim.diagnostic.goto_prev({ border = "rounded" })', opts) - vim.api.nvim_buf_set_keymap( - bufnr, - 'n', - 'gl', - 'lua vim.diagnostic.open_float({ border = "rounded" })', - opts - ) - vim.api.nvim_buf_set_keymap(bufnr, 'n', ']d', 'lua vim.diagnostic.goto_next({ border = "rounded" })', opts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'q', 'lua vim.diagnostic.setloclist()', opts) - vim.cmd([[ command! Format execute 'lua vim.lsp.buf.format{async=true}' ]]) + local opts = { noremap = true, silent = true } + api.nvim_buf_set_keymap(bufnr, "n", "gD", "lua lsp.buf.declaration()", opts) + api.nvim_buf_set_keymap(bufnr, "n", "gd", "lua lsp.buf.definition()", opts) + api.nvim_buf_set_keymap(bufnr, "n", "K", "lua lsp.buf.hover()", opts) + api.nvim_buf_set_keymap(bufnr, "n", "gi", "lua lsp.buf.implementation()", opts) + api.nvim_buf_set_keymap(bufnr, "n", "", "lua lsp.buf.signature_help()", opts) + -- api.nvim_buf_set_keymap(bufnr, 'n', 'rn', 'lua lsp.buf.rename()', opts) + api.nvim_buf_set_keymap(bufnr, "n", "gr", "lua lsp.buf.references()", opts) + -- api.nvim_buf_set_keymap(bufnr, 'n', 'ca', 'lua lsp.buf.code_action()', opts) + -- api.nvim_buf_set_keymap(bufnr, 'n', 'f', 'lua vim.diagnostic.open_float()', opts) + api.nvim_buf_set_keymap(bufnr, "n", "[d", 'lua vim.diagnostic.goto_prev({ border = "rounded" })', opts) + api.nvim_buf_set_keymap(bufnr, "n", "gl", 'lua vim.diagnostic.open_float({ border = "rounded" })', opts) + api.nvim_buf_set_keymap(bufnr, "n", "]d", 'lua vim.diagnostic.goto_next({ border = "rounded" })', opts) + api.nvim_buf_set_keymap(bufnr, "n", "q", "lua vim.diagnostic.setloclist()", opts) + vim.cmd([[ command! Format execute 'lua lsp.buf.format{async=true}' ]]) end M.on_attach = function(client, bufnr) - -- vim.notify(client.name .. ' starting...') - -- TODO: refactor this into a method that checks if string in list - if client.name == 'tsserver' then - client.resolved_capabilities.document_formatting = false - end - lsp_keymaps(bufnr) - lsp_highlight_document(client) + -- vim.notify(client.name .. ' starting...') + -- TODO: refactor this into a method that checks if string in list + if client.name == "tsserver" then + client.resolved_capabilities.document_formatting = false + end + if client.name == "sumneko_lua" then + client.resolved_capabilities.document_formatting = false + end + lsp_keymaps(bufnr) + lsp_highlight_document(client) end -local capabilities = vim.lsp.protocol.make_client_capabilities() +local capabilities = lsp.protocol.make_client_capabilities() -local status_ok, cmp_nvim_lsp = pcall(require, 'cmp_nvim_lsp') +local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") if not status_ok then - return + return end M.capabilities = cmp_nvim_lsp.update_capabilities(capabilities) diff --git a/.config/nvim/lua/user/lsp/init.lua b/.config/nvim/lua/user/lsp/init.lua index 39f39856..98f9f111 100644 --- a/.config/nvim/lua/user/lsp/init.lua +++ b/.config/nvim/lua/user/lsp/init.lua @@ -1,8 +1,8 @@ -local status_ok, _ = pcall(require, 'lspconfig') +local status_ok, _ = pcall(require, "lspconfig") if not status_ok then - return + return end -require('user.lsp.configs') -require('user.lsp.handlers').setup() -require('user.lsp.null-ls') +require("user.lsp.configs") +require("user.lsp.handlers").setup() +require("user.lsp.null-ls") diff --git a/.config/nvim/lua/user/lsp/null-ls.lua b/.config/nvim/lua/user/lsp/null-ls.lua index 83c42438..d705b9cd 100644 --- a/.config/nvim/lua/user/lsp/null-ls.lua +++ b/.config/nvim/lua/user/lsp/null-ls.lua @@ -1,6 +1,6 @@ -local null_ls_status_ok, null_ls = pcall(require, 'null-ls') +local null_ls_status_ok, null_ls = pcall(require, "null-ls") if not null_ls_status_ok then - return + return end -- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/formatting @@ -9,11 +9,15 @@ local formatting = null_ls.builtins.formatting local diagnostics = null_ls.builtins.diagnostics null_ls.setup({ - debug = false, - sources = { - formatting.prettier.with({ extra_args = { '--no-semi', '--single-quote', '--jsx-single-quote' } }), - formatting.black.with({ extra_args = { '--fast' } }), - formatting.stylua, - -- diagnostics.flake8 - }, + debug = true, + sources = { + formatting.prettier.with({ extra_args = { "--no-semi", "--single-quote", "--jsx-single-quote" } }), + formatting.autopep8, + formatting.stylua, + formatting.rustfmt, + formatting.beautysh, + -- diagnostics.luacheck, + diagnostics.pylint, + diagnostics.zsh, + }, }) diff --git a/.config/nvim/lua/user/lsp/settings/jsonls.lua b/.config/nvim/lua/user/lsp/settings/jsonls.lua index 856af467..ca5e8352 100644 --- a/.config/nvim/lua/user/lsp/settings/jsonls.lua +++ b/.config/nvim/lua/user/lsp/settings/jsonls.lua @@ -1,197 +1,197 @@ local default_schemas = nil local status_ok, jsonls_settings = pcall(require, "nlspsettings.jsonls") if status_ok then - default_schemas = jsonls_settings.get_default_schemas() + default_schemas = jsonls_settings.get_default_schemas() end local schemas = { - { - description = "TypeScript compiler configuration file", - fileMatch = { - "tsconfig.json", - "tsconfig.*.json", - }, - url = "https://json.schemastore.org/tsconfig.json", - }, - { - description = "Lerna config", - fileMatch = { "lerna.json" }, - url = "https://json.schemastore.org/lerna.json", - }, - { - description = "Babel configuration", - fileMatch = { - ".babelrc.json", - ".babelrc", - "babel.config.json", - }, - url = "https://json.schemastore.org/babelrc.json", - }, - { - description = "ESLint config", - fileMatch = { - ".eslintrc.json", - ".eslintrc", - }, - url = "https://json.schemastore.org/eslintrc.json", - }, - { - description = "Bucklescript config", - fileMatch = { "bsconfig.json" }, - url = "https://raw.githubusercontent.com/rescript-lang/rescript-compiler/8.2.0/docs/docson/build-schema.json", - }, - { - description = "Prettier config", - fileMatch = { - ".prettierrc", - ".prettierrc.json", - "prettier.config.json", - }, - url = "https://json.schemastore.org/prettierrc", - }, - { - description = "Vercel Now config", - fileMatch = { "now.json" }, - url = "https://json.schemastore.org/now", - }, - { - description = "Stylelint config", - fileMatch = { - ".stylelintrc", - ".stylelintrc.json", - "stylelint.config.json", - }, - url = "https://json.schemastore.org/stylelintrc", - }, - { - description = "A JSON schema for the ASP.NET LaunchSettings.json files", - fileMatch = { "launchsettings.json" }, - url = "https://json.schemastore.org/launchsettings.json", - }, - { - description = "Schema for CMake Presets", - fileMatch = { - "CMakePresets.json", - "CMakeUserPresets.json", - }, - url = "https://raw.githubusercontent.com/Kitware/CMake/master/Help/manual/presets/schema.json", - }, - { - description = "Configuration file as an alternative for configuring your repository in the settings page.", - fileMatch = { - ".codeclimate.json", - }, - url = "https://json.schemastore.org/codeclimate.json", - }, - { - description = "LLVM compilation database", - fileMatch = { - "compile_commands.json", - }, - url = "https://json.schemastore.org/compile-commands.json", - }, - { - description = "Config file for Command Task Runner", - fileMatch = { - "commands.json", - }, - url = "https://json.schemastore.org/commands.json", - }, - { - description = "AWS CloudFormation provides a common language for you to describe and provision all the infrastructure resources in your cloud environment.", - fileMatch = { - "*.cf.json", - "cloudformation.json", - }, - url = "https://raw.githubusercontent.com/awslabs/goformation/v5.2.9/schema/cloudformation.schema.json", - }, - { - description = "The AWS Serverless Application Model (AWS SAM, previously known as Project Flourish) extends AWS CloudFormation to provide a simplified way of defining the Amazon API Gateway APIs, AWS Lambda functions, and Amazon DynamoDB tables needed by your serverless application.", - fileMatch = { - "serverless.template", - "*.sam.json", - "sam.json", - }, - url = "https://raw.githubusercontent.com/awslabs/goformation/v5.2.9/schema/sam.schema.json", - }, - { - description = "Json schema for properties json file for a GitHub Workflow template", - fileMatch = { - ".github/workflow-templates/**.properties.json", - }, - url = "https://json.schemastore.org/github-workflow-template-properties.json", - }, - { - description = "golangci-lint configuration file", - fileMatch = { - ".golangci.toml", - ".golangci.json", - }, - url = "https://json.schemastore.org/golangci-lint.json", - }, - { - description = "JSON schema for the JSON Feed format", - fileMatch = { - "feed.json", - }, - url = "https://json.schemastore.org/feed.json", - versions = { - ["1"] = "https://json.schemastore.org/feed-1.json", - ["1.1"] = "https://json.schemastore.org/feed.json", - }, - }, - { - description = "Packer template JSON configuration", - fileMatch = { - "packer.json", - }, - url = "https://json.schemastore.org/packer.json", - }, - { - description = "NPM configuration file", - fileMatch = { - "package.json", - }, - url = "https://json.schemastore.org/package.json", - }, - { - description = "JSON schema for Visual Studio component configuration files", - fileMatch = { - "*.vsconfig", - }, - url = "https://json.schemastore.org/vsconfig.json", - }, - { - description = "Resume json", - fileMatch = { "resume.json" }, - url = "https://raw.githubusercontent.com/jsonresume/resume-schema/v1.0.0/schema.json", - }, + { + description = "TypeScript compiler configuration file", + fileMatch = { + "tsconfig.json", + "tsconfig.*.json", + }, + url = "https://json.schemastore.org/tsconfig.json", + }, + { + description = "Lerna config", + fileMatch = { "lerna.json" }, + url = "https://json.schemastore.org/lerna.json", + }, + { + description = "Babel configuration", + fileMatch = { + ".babelrc.json", + ".babelrc", + "babel.config.json", + }, + url = "https://json.schemastore.org/babelrc.json", + }, + { + description = "ESLint config", + fileMatch = { + ".eslintrc.json", + ".eslintrc", + }, + url = "https://json.schemastore.org/eslintrc.json", + }, + { + description = "Bucklescript config", + fileMatch = { "bsconfig.json" }, + url = "https://raw.githubusercontent.com/rescript-lang/rescript-compiler/8.2.0/docs/docson/build-schema.json", + }, + { + description = "Prettier config", + fileMatch = { + ".prettierrc", + ".prettierrc.json", + "prettier.config.json", + }, + url = "https://json.schemastore.org/prettierrc", + }, + { + description = "Vercel Now config", + fileMatch = { "now.json" }, + url = "https://json.schemastore.org/now", + }, + { + description = "Stylelint config", + fileMatch = { + ".stylelintrc", + ".stylelintrc.json", + "stylelint.config.json", + }, + url = "https://json.schemastore.org/stylelintrc", + }, + { + description = "A JSON schema for the ASP.NET LaunchSettings.json files", + fileMatch = { "launchsettings.json" }, + url = "https://json.schemastore.org/launchsettings.json", + }, + { + description = "Schema for CMake Presets", + fileMatch = { + "CMakePresets.json", + "CMakeUserPresets.json", + }, + url = "https://raw.githubusercontent.com/Kitware/CMake/master/Help/manual/presets/schema.json", + }, + { + description = "Configuration file as an alternative for configuring your repository in the settings page.", + fileMatch = { + ".codeclimate.json", + }, + url = "https://json.schemastore.org/codeclimate.json", + }, + { + description = "LLVM compilation database", + fileMatch = { + "compile_commands.json", + }, + url = "https://json.schemastore.org/compile-commands.json", + }, + { + description = "Config file for Command Task Runner", + fileMatch = { + "commands.json", + }, + url = "https://json.schemastore.org/commands.json", + }, + { + description = "AWS CloudFormation provides a common language for you to describe and provision all the infrastructure resources in your cloud environment.", + fileMatch = { + "*.cf.json", + "cloudformation.json", + }, + url = "https://raw.githubusercontent.com/awslabs/goformation/v5.2.9/schema/cloudformation.schema.json", + }, + { + description = "The AWS Serverless Application Model (AWS SAM, previously known as Project Flourish) extends AWS CloudFormation to provide a simplified way of defining the Amazon API Gateway APIs, AWS Lambda functions, and Amazon DynamoDB tables needed by your serverless application.", + fileMatch = { + "serverless.template", + "*.sam.json", + "sam.json", + }, + url = "https://raw.githubusercontent.com/awslabs/goformation/v5.2.9/schema/sam.schema.json", + }, + { + description = "Json schema for properties json file for a GitHub Workflow template", + fileMatch = { + ".github/workflow-templates/**.properties.json", + }, + url = "https://json.schemastore.org/github-workflow-template-properties.json", + }, + { + description = "golangci-lint configuration file", + fileMatch = { + ".golangci.toml", + ".golangci.json", + }, + url = "https://json.schemastore.org/golangci-lint.json", + }, + { + description = "JSON schema for the JSON Feed format", + fileMatch = { + "feed.json", + }, + url = "https://json.schemastore.org/feed.json", + versions = { + ["1"] = "https://json.schemastore.org/feed-1.json", + ["1.1"] = "https://json.schemastore.org/feed.json", + }, + }, + { + description = "Packer template JSON configuration", + fileMatch = { + "packer.json", + }, + url = "https://json.schemastore.org/packer.json", + }, + { + description = "NPM configuration file", + fileMatch = { + "package.json", + }, + url = "https://json.schemastore.org/package.json", + }, + { + description = "JSON schema for Visual Studio component configuration files", + fileMatch = { + "*.vsconfig", + }, + url = "https://json.schemastore.org/vsconfig.json", + }, + { + description = "Resume json", + fileMatch = { "resume.json" }, + url = "https://raw.githubusercontent.com/jsonresume/resume-schema/v1.0.0/schema.json", + }, } local function extend(tab1, tab2) - for _, value in ipairs(tab2 or {}) do - table.insert(tab1, value) - end - return tab1 + for _, value in ipairs(tab2 or {}) do + table.insert(tab1, value) + end + return tab1 end local extended_schemas = extend(schemas, default_schemas) local opts = { - settings = { - json = { - schemas = extended_schemas, - }, - }, - setup = { - commands = { - Format = { - function() - vim.lsp.buf.range_formatting({}, { 0, 0 }, { vim.fn.line "$", 0 }) - end, - }, - }, - }, + settings = { + json = { + schemas = extended_schemas, + }, + }, + setup = { + commands = { + Format = { + function() + vim.lsp.buf.range_formatting({}, { 0, 0 }, { vim.fn.line("$"), 0 }) + end, + }, + }, + }, } return opts diff --git a/.config/nvim/lua/user/lsp/settings/pyright.lua b/.config/nvim/lua/user/lsp/settings/pyright.lua index 501d073d..570ef9dc 100644 --- a/.config/nvim/lua/user/lsp/settings/pyright.lua +++ b/.config/nvim/lua/user/lsp/settings/pyright.lua @@ -1,9 +1,9 @@ return { - settings = { - python = { - analysis = { - typeCheckingMode = "off" - }, - }, - }, -} \ No newline at end of file + settings = { + python = { + analysis = { + typeCheckingMode = "off", + }, + }, + }, +} diff --git a/.config/nvim/lua/user/lsp/settings/sumneko_lua.lua b/.config/nvim/lua/user/lsp/settings/sumneko_lua.lua index 9848bdd8..2c8bf396 100644 --- a/.config/nvim/lua/user/lsp/settings/sumneko_lua.lua +++ b/.config/nvim/lua/user/lsp/settings/sumneko_lua.lua @@ -1,15 +1,15 @@ return { - settings = { - Lua = { - diagnostics = { - globals = { "vim" }, - }, - workspace = { - library = { - [vim.fn.expand("$VIMRUNTIME/lua")] = true, - [vim.fn.stdpath("config") .. "/lua"] = true, - }, - }, - }, - }, + settings = { + Lua = { + diagnostics = { + globals = { "vim", "require" }, + }, + workspace = { + library = { + [vim.fn.expand("$VIMRUNTIME/lua")] = true, + [vim.fn.stdpath("config") .. "/lua"] = true, + }, + }, + }, + }, } diff --git a/.config/nvim/lua/user/lualine.lua b/.config/nvim/lua/user/lualine.lua index cfc325ac..47bd0d10 100644 --- a/.config/nvim/lua/user/lualine.lua +++ b/.config/nvim/lua/user/lualine.lua @@ -1,93 +1,93 @@ -local status_ok, lualine = pcall(require, 'lualine') +local status_ok, lualine = pcall(require, "lualine") if not status_ok then - return + return end local hide_in_width = function() - return vim.fn.winwidth(0) > 80 + return vim.fn.winwidth(0) > 80 end local diagnostics = { - 'diagnostics', - sources = { 'nvim_diagnostic' }, - sections = { 'error', 'warn' }, - symbols = { error = ' ', warn = ' ' }, - colored = false, - update_in_insert = false, - always_visible = true, + "diagnostics", + sources = { "nvim_diagnostic" }, + sections = { "error", "warn" }, + symbols = { error = " ", warn = " " }, + colored = false, + update_in_insert = false, + always_visible = true, } local diff = { - 'diff', - colored = false, - symbols = { added = ' ', modified = ' ', removed = ' ' }, -- changes diff symbols - cond = hide_in_width + "diff", + colored = false, + symbols = { added = " ", modified = " ", removed = " " }, -- changes diff symbols + cond = hide_in_width, } local mode = { - 'mode', - fmt = function(str) - return '-- ' .. str .. ' --' - end, + "mode", + fmt = function(str) + return "-- " .. str .. " --" + end, } local filetype = { - 'filetype', - icons_enabled = false, - icon = nil, + "filetype", + icons_enabled = false, + icon = nil, } local branch = { - 'branch', - icons_enabled = true, - icon = '', + "branch", + icons_enabled = true, + icon = "", } local location = { - 'location', - padding = 0, + "location", + padding = 0, } -- cool function for progress local progress = function() - local current_line = vim.fn.line('.') - local total_lines = vim.fn.line('$') - local chars = { '__', '▁▁', '▂▂', '▃▃', '▄▄', '▅▅', '▆▆', '▇▇', '██' } - local line_ratio = current_line / total_lines - local index = math.ceil(line_ratio * #chars) - return chars[index] + local current_line = vim.fn.line(".") + local total_lines = vim.fn.line("$") + local chars = { "__", "▁▁", "▂▂", "▃▃", "▄▄", "▅▅", "▆▆", "▇▇", "██" } + local line_ratio = current_line / total_lines + local index = math.ceil(line_ratio * #chars) + return chars[index] end local spaces = function() - return 'spaces: ' .. vim.api.nvim_buf_get_option(0, 'shiftwidth') + return "spaces: " .. vim.api.nvim_buf_get_option(0, "shiftwidth") end lualine.setup({ - options = { - icons_enabled = true, - theme = 'auto', - component_separators = { left = '', right = ''}, - section_separators = { left = '', right = ''}, - disabled_filetypes = {}, - always_divide_middle = true, - globalstatus = false, - }, - sections = { - lualine_a = {'mode'}, - lualine_b = {'branch', 'diff', 'diagnostics'}, - lualine_c = {'filename'}, - lualine_x = {'encoding', 'fileformat', 'filetype'}, - lualine_y = {'progress'}, - lualine_z = {'location'} - }, - inactive_sections = { - lualine_a = {}, - lualine_b = {}, - lualine_c = { 'filename' }, - lualine_x = { 'location' }, - lualine_y = {}, - lualine_z = {}, - }, - tabline = {}, - extensions = {}, + options = { + icons_enabled = true, + theme = "auto", + component_separators = { left = "", right = "" }, + section_separators = { left = "", right = "" }, + disabled_filetypes = {}, + always_divide_middle = true, + globalstatus = false, + }, + sections = { + lualine_a = { "mode" }, + lualine_b = { "branch", "diff", "diagnostics" }, + lualine_c = { "filename" }, + lualine_x = { "encoding", "fileformat", "filetype" }, + lualine_y = { "progress" }, + lualine_z = { "location" }, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { "filename" }, + lualine_x = { "location" }, + lualine_y = {}, + lualine_z = {}, + }, + tabline = {}, + extensions = {}, }) diff --git a/.config/nvim/lua/user/nvim-tree.lua b/.config/nvim/lua/user/nvim-tree.lua index a40958d6..ace3d7a8 100644 --- a/.config/nvim/lua/user/nvim-tree.lua +++ b/.config/nvim/lua/user/nvim-tree.lua @@ -1,81 +1,80 @@ -local status_ok, nvim_tree = pcall(require, 'nvim-tree') +local status_ok, nvim_tree = pcall(require, "nvim-tree") if not status_ok then - return + return end -local config_status_ok, nvim_tree_config = pcall(require, 'nvim-tree.config') +local config_status_ok, nvim_tree_config = pcall(require, "nvim-tree.config") if not config_status_ok then - return + return end local tree_cb = nvim_tree_config.nvim_tree_callback - -nvim_tree.setup { - sort_by = 'case_sensitive', - update_focused_file = { - enable = true, - update_cwd = true, - }, - renderer = { - group_empty = true, - root_folder_modifier = ':t', - icons = { - webdev_colors = true, - show = { - file = true, - folder = true, - folder_arrow = true, - git = true, - }, - glyphs = { - default = '', - symlink = '', - folder = { - arrow_open = '', - arrow_closed = '', - default = '', - open = '', - empty = '', - empty_open = '', - symlink = '', - symlink_open = '', - }, - git = { - unstaged = '', - staged = 'S', - unmerged = '', - renamed = '➜', - untracked = 'U', - deleted = '', - ignored = '◌', - }, - }, - }, - }, - diagnostics = { - enable = true, - show_on_dirs = true, - icons = { - hint = '', - info = '', - warning = '', - error = '', - }, - }, - view = { - width = 30, - height = 30, - side = 'left', - mappings = { - list = { - { key = { 'l', '', 'o' }, cb = tree_cb 'edit' }, - { key = 'h', cb = tree_cb 'close_node' }, - { key = 'v', cb = tree_cb 'vsplit' }, - }, - }, - }, - filters = { - dotfiles = false, - }, -} \ No newline at end of file +nvim_tree.setup({ + sort_by = "case_sensitive", + update_focused_file = { + enable = true, + update_cwd = true, + }, + renderer = { + group_empty = true, + root_folder_modifier = ":t", + icons = { + webdev_colors = true, + show = { + file = true, + folder = true, + folder_arrow = true, + git = true, + }, + glyphs = { + default = "", + symlink = "", + folder = { + arrow_open = "", + arrow_closed = "", + default = "", + open = "", + empty = "", + empty_open = "", + symlink = "", + symlink_open = "", + }, + git = { + unstaged = "", + staged = "S", + unmerged = "", + renamed = "➜", + untracked = "U", + deleted = "", + ignored = "◌", + }, + }, + }, + }, + diagnostics = { + enable = true, + show_on_dirs = true, + icons = { + hint = "", + info = "", + warning = "", + error = "", + }, + }, + view = { + width = 30, + height = 30, + side = "left", + mappings = { + list = { + { key = { "l", "", "o" }, cb = tree_cb("edit") }, + { key = "h", cb = tree_cb("close_node") }, + { key = "v", cb = tree_cb("vsplit") }, + }, + }, + }, + filters = { + dotfiles = false, + }, +}) diff --git a/.config/nvim/lua/user/options.lua b/.config/nvim/lua/user/options.lua index 62cff0f2..749e3577 100644 --- a/.config/nvim/lua/user/options.lua +++ b/.config/nvim/lua/user/options.lua @@ -1,56 +1,59 @@ local g = vim.g local o = vim.o -g.mapleader = ' ' -g.maplocalleader = ' ' +g.mapleader = " " +g.maplocalleader = " " local options = { - backup = false, -- creates a backup file - clipboard = 'unnamedplus', -- allows neovim to access the system clipboard - cmdheight = 2, -- more space in the neovim command line for displaying messages - completeopt = { 'menu', 'menuone', 'noselect' }, -- mostly just for cmp - conceallevel = 0, -- so that `` is visible in markdown files - fileencoding = 'utf-8', -- the encoding written to a file - hlsearch = true, -- highlight all matches on previous search pattern - ignorecase = true, -- ignore case in search patterns - mouse = 'a', -- allow the mouse to be used in neovim - pumheight = 10, -- pop up menu height - showmode = false, -- we don't need to see things like -- INSERT -- anymore - showtabline = 2, -- always show tabs - smartcase = true, -- smart case - smartindent = true, -- make indenting smarter again - splitbelow = true, -- force all horizontal splits to go below current window - splitright = true, -- force all vertical splits to go to the right of current window - swapfile = true, -- creates a swapfile - termguicolors = true, -- set term gui colors (most terminals support this) - timeoutlen = 100, -- time to wait for a mapped sequence to complete (in milliseconds) - undofile = true, -- enable persistent undo - updatetime = 300, -- faster completion (4000ms default) - writebackup = false, -- if a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited - expandtab = true, -- convert tabs to spaces - shiftwidth = 4, -- the number of spaces inserted for each indentation - tabstop = 4, -- insert 4 spaces for a tab - cursorline = true, -- highlight the current line - cursorcolumn = true, -- highlight the current column - number = true, -- set numbered lines - relativenumber = true, -- set relative numbered lines - numberwidth = 4, -- set number column width to 4 {default 4} - signcolumn = 'yes', -- always show the sign column, otherwise it would shift the text each time - wrap = false, -- display lines as one long line - scrolloff = 8, -- is one of my fav - sidescrolloff = 8, - --wildmode = 'longest,list,full', - guifont = 'JetBrainsMono NF:h11', -- the font used in graphical neovim applications + backup = false, -- creates a backup file + clipboard = "unnamedplus", -- allows neovim to access the system clipboard + cmdheight = 2, -- more space in the neovim command line for displaying messages + completeopt = { "menu", "menuone", "noselect" }, -- mostly just for cmp + conceallevel = 0, -- so that `` is visible in markdown files + fileencoding = "utf-8", -- the encoding written to a file + hlsearch = true, -- highlight all matches on previous search pattern + ignorecase = true, -- ignore case in search patterns + mouse = "a", -- allow the mouse to be used in neovim + pumheight = 10, -- pop up menu height + showmode = false, -- we don't need to see things like -- INSERT -- anymore + showtabline = 2, -- always show tabs + smartcase = true, -- smart case + smartindent = true, -- make indenting smarter again + splitbelow = true, -- force all horizontal splits to go below current window + splitright = true, -- force all vertical splits to go to the right of current window + swapfile = true, -- creates a swapfile + termguicolors = true, -- set term gui colors (most terminals support this) + timeoutlen = 100, -- time to wait for a mapped sequence to complete (in milliseconds) + undofile = true, -- enable persistent undo + updatetime = 300, -- faster completion (4000ms default) + writebackup = false, -- if a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited + expandtab = true, -- convert tabs to spaces + shiftwidth = 4, -- the number of spaces inserted for each indentation + tabstop = 4, -- insert 4 spaces for a tab + cursorline = true, -- highlight the current line + cursorcolumn = true, -- highlight the current column + number = true, -- set numbered lines + relativenumber = true, -- set relative numbered lines + numberwidth = 4, -- set number column width to 4 {default 4} + signcolumn = "yes", -- always show the sign column, otherwise it would shift the text each time + wrap = false, -- display lines as one long line + scrolloff = 8, -- is one of my fav + sidescrolloff = 8, + --wildmode = 'longest,list,full', + guifont = "JetBrainsMono NF:h11", -- the font used in graphical neovim applications } for k, v in pairs(options) do - vim.opt[k] = v + vim.opt[k] = v end -vim.cmd [[highlight CursorLine ctermbg=Yellow cterm=bold guibg=#2b2b2b]] -vim.cmd [[highlight CursorColumn ctermbg=Yellow cterm=bold guibg=#2b2b2b]] - +vim.cmd([[highlight CursorLine ctermbg=Yellow cterm=bold guibg=#2b2b2b]]) +vim.cmd([[highlight CursorColumn ctermbg=Yellow cterm=bold guibg=#2b2b2b]]) g.dracula_transparent_bg = true g.dracula_italic_comment = true g.dracula_show_end_of_buffer = true + +vim.opt_local.suffixesadd:prepend(".lua") +vim.opt_local.suffixesadd:prepend("init.lua") +vim.opt_local.path:prepend(vim.fn.stdpath("config") .. "/lua") diff --git a/.config/nvim/lua/user/plugins.lua b/.config/nvim/lua/user/plugins.lua index bd13c5e7..45b550ae 100644 --- a/.config/nvim/lua/user/plugins.lua +++ b/.config/nvim/lua/user/plugins.lua @@ -1,18 +1,18 @@ local fn = vim.fn -- Automatically install packer -local install_path = fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim' +local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim" if fn.empty(fn.glob(install_path)) > 0 then - PACKER_BOOTSTRAP = fn.system({ - 'git', - 'clone', - '--depth', - '1', - 'https://github.com/wbthomason/packer.nvim', - install_path, - }) - print('Installing packer close and reopen Neovim...') - vim.cmd([[packadd packer.nvim]]) + PACKER_BOOTSTRAP = fn.system({ + "git", + "clone", + "--depth", + "1", + "https://github.com/wbthomason/packer.nvim", + install_path, + }) + print("Installing packer close and reopen Neovim...") + vim.cmd([[packadd packer.nvim]]) end -- Autocommand that reloads neovim whenever you save the plugins.lua file @@ -24,91 +24,88 @@ vim.cmd([[ ]]) -- Use a protected call so we don't error out on first use -local status_ok, packer = pcall(require, 'packer') +local status_ok, packer = pcall(require, "packer") if not status_ok then - return + return end -- Have packer use a popup window packer.init({ - display = { - open_fn = function() - return require('packer.util').float({ border = 'rounded' }) - end, - }, + display = { + open_fn = function() + return require("packer.util").float({ border = "rounded" }) + end, + }, }) -- Install your plugins here -return packer.startup( - function(use) - -- My plugins here +return packer.startup(function(use) + -- My plugins here - use 'wbthomason/packer.nvim' -- Have packer manage itself - use 'nvim-lua/popup.nvim' -- Useful lua functions used by lots of plugins - use 'nvim-lua/plenary.nvim' -- Useful lua functions used by lots of plugins - use 'windwp/nvim-autopairs' -- Autopairs, integrates with both cmp and treesitter - use 'numToStr/Comment.nvim' - use 'JoosepAlviste/nvim-ts-context-commentstring' - use 'kyazdani42/nvim-web-devicons' - use 'kyazdani42/nvim-tree.lua' - use 'akinsho/bufferline.nvim' - use 'moll/vim-bbye' - use 'nvim-lualine/lualine.nvim' - use 'akinsho/toggleterm.nvim' - use 'ahmedkhalf/project.nvim' - use 'lewis6991/impatient.nvim' - use 'lukas-reineke/indent-blankline.nvim' - use 'goolord/alpha-nvim' - use 'folke/which-key.nvim' - use 'andweeb/presence.nvim' - use 'mattn/emmet-vim' - use 'sbdchd/neoformat' - use 'vimwiki/vimwiki' - use 'saecki/crates.nvim' - use { - 'norcalli/nvim-colorizer.lua', - config = function() - require('colorizer').setup() - end - } + use("wbthomason/packer.nvim") -- Have packer manage itself + use("nvim-lua/popup.nvim") -- Useful lua functions used by lots of plugins + use("nvim-lua/plenary.nvim") -- Useful lua functions used by lots of plugins + use("windwp/nvim-autopairs") -- Autopairs, integrates with both cmp and treesitte + use("numToStr/Comment.nvim") + use("JoosepAlviste/nvim-ts-context-commentstring") + use("kyazdani42/nvim-web-devicons") + use("kyazdani42/nvim-tree.lua") + use("akinsho/bufferline.nvim") + use("moll/vim-bbye") + use("nvim-lualine/lualine.nvim") + use("akinsho/toggleterm.nvim") + use("ahmedkhalf/project.nvim") + use("lewis6991/impatient.nvim") + use("lukas-reineke/indent-blankline.nvim") + use("goolord/alpha-nvim") + use("folke/which-key.nvim") + use("andweeb/presence.nvim") + use("mattn/emmet-vim") + use("saecki/crates.nvim") + use("norcalli/nvim-colorizer.lua") - -- Colorschemes - use 'Mofiqul/dracula.nvim' - use 'folke/tokyonight.nvim' - use 'lunarvim/darkplus.nvim' + -- Vimwiki + use("vimwiki/vimwiki") + use("jbyuki/carrot.nvim") - -- cmp plugins - use 'hrsh7th/nvim-cmp'-- The completion plugin - use 'hrsh7th/cmp-buffer' -- buffer completions - use 'hrsh7th/cmp-path'-- path completions - use 'hrsh7th/cmp-cmdline' -- cmdline completions - use 'saadparwaiz1/cmp_luasnip' -- snippet completions - use 'hrsh7th/cmp-nvim-lsp' - use 'hrsh7th/cmp-nvim-lua' + -- Colorschemes + use("Mofiqul/dracula.nvim") + use("folke/tokyonight.nvim") + use("lunarvim/darkplus.nvim") - -- snippets - use 'L3MON4D3/LuaSnip' --snippet engine - use 'rafamadriz/friendly-snippets' -- a bunch of snippets to use + -- cmp plugins + use("hrsh7th/nvim-cmp") -- The completion plugin + use("hrsh7th/cmp-buffer") -- buffer completions + use("hrsh7th/cmp-path") -- path completions + use("hrsh7th/cmp-cmdline") -- cmdline completions + use("saadparwaiz1/cmp_luasnip") -- snippet completions + use("hrsh7th/cmp-nvim-lsp") + use("hrsh7th/cmp-nvim-lua") - -- LSP - use 'neovim/nvim-lspconfig' -- enable LSP - use 'williamboman/nvim-lsp-installer' -- simple to use language server installer - use 'jose-elias-alvarez/null-ls.nvim' -- for formatters and linters + -- snippets + use("L3MON4D3/LuaSnip") --snippet engine + use("rafamadriz/friendly-snippets") -- a bunch of snippets to use - -- Telescope - use 'nvim-telescope/telescope.nvim' - use {'nvim-telescope/telescope-fzf-native.nvim', run = 'make' } + -- LSP + use("neovim/nvim-lspconfig") -- enable LSP + use("williamboman/nvim-lsp-installer") -- simple to use language server installer + use("jose-elias-alvarez/null-ls.nvim") -- for formatters and linters - -- Treesitter - use 'nvim-treesitter/nvim-treesitter' + -- Telescope + use({ "nvim-telescope/telescope.nvim", run = ":TSUpdate" }) + use({ "nvim-telescope/telescope-fzf-native.nvim", run = "make" }) + use("nvim-telescope/telescope-media-files.nvim") - -- Git - use 'lewis6991/gitsigns.nvim' + -- Treesitter + use("nvim-treesitter/nvim-treesitter") + use("p00f/nvim-ts-rainbow") - -- Automatically set up your configuration after cloning packer.nvim - -- Put this at the end after all plugins - if PACKER_BOOTSTRAP then - require('packer').sync() - end - end -) + -- Git + use("lewis6991/gitsigns.nvim") + + -- Automatically set up your configuration after cloning packer.nvim + -- Put this at the end after all plugins + if PACKER_BOOTSTRAP then + require("packer").sync() + end +end) diff --git a/.config/nvim/lua/user/project.lua b/.config/nvim/lua/user/project.lua index df04f3ca..5b579d24 100644 --- a/.config/nvim/lua/user/project.lua +++ b/.config/nvim/lua/user/project.lua @@ -1,48 +1,48 @@ local status_ok, project = pcall(require, "project_nvim") if not status_ok then - return + return end project.setup({ - ---@usage set to false to disable project.nvim. - --- This is on by default since it's currently the expected behavior. - active = true, + ---@usage set to false to disable project.nvim. + --- This is on by default since it's currently the expected behavior. + active = true, - on_config_done = nil, + on_config_done = nil, - ---@usage set to true to disable setting the current-woriking directory - --- Manual mode doesn't automatically change your root directory, so you have - --- the option to manually do so using `:ProjectRoot` command. - manual_mode = false, + ---@usage set to true to disable setting the current-woriking directory + --- Manual mode doesn't automatically change your root directory, so you have + --- the option to manually do so using `:ProjectRoot` command. + manual_mode = false, - ---@usage Methods of detecting the root directory - --- Allowed values: **"lsp"** uses the native neovim lsp - --- **"pattern"** uses vim-rooter like glob pattern matching. Here - --- order matters: if one is not detected, the other is used as fallback. You - --- can also delete or rearangne the detection methods. - -- detection_methods = { "lsp", "pattern" }, -- NOTE: lsp detection will get annoying with multiple langs in one project - detection_methods = { "pattern" }, + ---@usage Methods of detecting the root directory + --- Allowed values: **"lsp"** uses the native neovim lsp + --- **"pattern"** uses vim-rooter like glob pattern matching. Here + --- order matters: if one is not detected, the other is used as fallback. You + --- can also delete or rearangne the detection methods. + -- detection_methods = { "lsp", "pattern" }, -- NOTE: lsp detection will get annoying with multiple langs in one project + detection_methods = { "pattern" }, - ---@usage patterns used to detect root dir, when **"pattern"** is in detection_methods - patterns = { ".git", "_darcs", ".hg", ".bzr", ".svn", "Makefile", "package.json" }, + ---@usage patterns used to detect root dir, when **"pattern"** is in detection_methods + patterns = { ".git", "_darcs", ".hg", ".bzr", ".svn", "Makefile", "package.json" }, - ---@ Show hidden files in telescope when searching for files in a project - show_hidden = false, + ---@ Show hidden files in telescope when searching for files in a project + show_hidden = false, - ---@usage When set to false, you will get a message when project.nvim changes your directory. - -- When set to false, you will get a message when project.nvim changes your directory. - silent_chdir = true, + ---@usage When set to false, you will get a message when project.nvim changes your directory. + -- When set to false, you will get a message when project.nvim changes your directory. + silent_chdir = true, - ---@usage list of lsp client names to ignore when using **lsp** detection. eg: { "efm", ... } - ignore_lsp = {}, + ---@usage list of lsp client names to ignore when using **lsp** detection. eg: { "efm", ... } + ignore_lsp = {}, - ---@type string - ---@usage path to store the project history for use in telescope - datapath = vim.fn.stdpath("data"), + ---@type string + ---@usage path to store the project history for use in telescope + datapath = vim.fn.stdpath("data"), }) local tele_status_ok, telescope = pcall(require, "telescope") if not tele_status_ok then - return + return end -telescope.load_extension('projects') +telescope.load_extension("projects") diff --git a/.config/nvim/lua/user/telescope.lua b/.config/nvim/lua/user/telescope.lua index 84e7e94c..d80d7d7b 100644 --- a/.config/nvim/lua/user/telescope.lua +++ b/.config/nvim/lua/user/telescope.lua @@ -1,99 +1,106 @@ -local status_ok, telescope = pcall(require, 'telescope') +local status_ok, telescope = pcall(require, "telescope") if not status_ok then - return + return end -local actions = require 'telescope.actions' +local actions = require("telescope.actions") +telescope.load_extension("fzf") +telescope.load_extension("media_files") -telescope.setup { - defaults = { +telescope.setup({ + defaults = { - prompt_prefix = ' ', - selection_caret = ' ', - path_display = { 'smart' }, + prompt_prefix = " ", + selection_caret = " ", + path_display = { "smart" }, - mappings = { - i = { - [''] = actions.cycle_history_next, - [''] = actions.cycle_history_prev, + mappings = { + i = { + [""] = actions.cycle_history_next, + [""] = actions.cycle_history_prev, - [''] = actions.move_selection_next, - [''] = actions.move_selection_previous, + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, - [''] = actions.close, + [""] = actions.close, - [''] = actions.move_selection_next, - [''] = actions.move_selection_previous, + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, - [''] = actions.select_default, - [''] = actions.select_horizontal, - [''] = actions.select_vertical, - [''] = actions.select_tab, + [""] = actions.select_default, + [""] = actions.select_horizontal, + [""] = actions.select_vertical, + [""] = actions.select_tab, - [''] = actions.preview_scrolling_up, - [''] = actions.preview_scrolling_down, + [""] = actions.preview_scrolling_up, + [""] = actions.preview_scrolling_down, - [''] = actions.results_scrolling_up, - [''] = actions.results_scrolling_down, + [""] = actions.results_scrolling_up, + [""] = actions.results_scrolling_down, - [''] = actions.toggle_selection + actions.move_selection_worse, - [''] = actions.toggle_selection + actions.move_selection_better, - [''] = actions.send_to_qflist + actions.open_qflist, - [''] = actions.send_selected_to_qflist + actions.open_qflist, - [''] = actions.complete_tag, - [''] = actions.which_key, -- keys from pressing - }, + [""] = actions.toggle_selection + actions.move_selection_worse, + [""] = actions.toggle_selection + actions.move_selection_better, + [""] = actions.send_to_qflist + actions.open_qflist, + [""] = actions.send_selected_to_qflist + actions.open_qflist, + [""] = actions.complete_tag, + [""] = actions.which_key, -- keys from pressing + }, - n = { - [''] = actions.close, - [''] = actions.select_default, - [''] = actions.select_horizontal, - [''] = actions.select_vertical, - [''] = actions.select_tab, + n = { + [""] = actions.close, + [""] = actions.select_default, + [""] = actions.select_horizontal, + [""] = actions.select_vertical, + [""] = actions.select_tab, - [''] = actions.toggle_selection + actions.move_selection_worse, - [''] = actions.toggle_selection + actions.move_selection_better, - [''] = actions.send_to_qflist + actions.open_qflist, - [''] = actions.send_selected_to_qflist + actions.open_qflist, + [""] = actions.toggle_selection + actions.move_selection_worse, + [""] = actions.toggle_selection + actions.move_selection_better, + [""] = actions.send_to_qflist + actions.open_qflist, + [""] = actions.send_selected_to_qflist + actions.open_qflist, - ['j'] = actions.move_selection_next, - ['k'] = actions.move_selection_previous, - ['H'] = actions.move_to_top, - ['M'] = actions.move_to_middle, - ['L'] = actions.move_to_bottom, + ["j"] = actions.move_selection_next, + ["k"] = actions.move_selection_previous, + ["H"] = actions.move_to_top, + ["M"] = actions.move_to_middle, + ["L"] = actions.move_to_bottom, - [''] = actions.move_selection_next, - [''] = actions.move_selection_previous, - ['gg'] = actions.move_to_top, - ['G'] = actions.move_to_bottom, + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, + ["gg"] = actions.move_to_top, + ["G"] = actions.move_to_bottom, - [''] = actions.preview_scrolling_up, - [''] = actions.preview_scrolling_down, + [""] = actions.preview_scrolling_up, + [""] = actions.preview_scrolling_down, - [''] = actions.results_scrolling_up, - [''] = actions.results_scrolling_down, + [""] = actions.results_scrolling_up, + [""] = actions.results_scrolling_down, - ['?'] = actions.which_key, - }, - }, - }, - pickers = { - -- Default configuration for builtin pickers goes here: - -- picker_name = { - -- picker_config_key = value, - -- ... - -- } - -- Now the picker_config_key will be applied every time you call this - -- builtin picker - }, - extensions = { - fzf = { - fuzzy = true, -- false will only do exact matching - override_generic_sorter = true, -- override the generic sorter - override_file_sorter = true, -- override the file sorter - case_mode = "smart_case", -- or "ignore_case" or "respect_case" - -- the default case_mode is "smart_case" - }, - } -} -require('telescope').load_extension('fzf') \ No newline at end of file + ["?"] = actions.which_key, + }, + }, + }, + pickers = { + -- Default configuration for builtin pickers goes here: + -- picker_name = { + -- picker_config_key = value, + -- ... + -- } + -- Now the picker_config_key will be applied every time you call this + -- builtin picker + }, + extensions = { + fzf = { + fuzzy = true, -- false will only do exact matching + override_generic_sorter = true, -- override the generic sorter + override_file_sorter = true, -- override the file sorter + case_mode = "smart_case", -- or "ignore_case" or "respect_case" + -- the default case_mode is "smart_case" + }, + media_files = { + -- filetypes whitelist + -- defaults to {"png", "jpg", "mp4", "webm", "pdf"} + filetypes = { "png", "webp", "jpg", "jpeg" }, + find_cmd = "rg", -- find command (defaults to `fd`) + }, + }, +}) diff --git a/.config/nvim/lua/user/toggleterm.lua b/.config/nvim/lua/user/toggleterm.lua index d4866ca4..66817ea3 100644 --- a/.config/nvim/lua/user/toggleterm.lua +++ b/.config/nvim/lua/user/toggleterm.lua @@ -58,10 +58,10 @@ function _NCDU_TOGGLE() ncdu:toggle() end -local htop = Terminal:new({ cmd = 'htop', hidden = true }) +local btop = Terminal:new({ cmd = 'btop', hidden = true }) -function _HTOP_TOGGLE() - htop:toggle() +function _BTOP_TOGGLE() + btop:toggle() end local python = Terminal:new({ cmd = 'python', hidden = true }) diff --git a/.config/nvim/lua/user/treesitter.lua b/.config/nvim/lua/user/treesitter.lua index 6e7644ca..3c772d7a 100644 --- a/.config/nvim/lua/user/treesitter.lua +++ b/.config/nvim/lua/user/treesitter.lua @@ -1,17 +1,25 @@ -local status_ok, configs = pcall(require, 'nvim-treesitter.configs') +local status_ok, configs = pcall(require, "nvim-treesitter.configs") if not status_ok then - return + return end configs.setup({ - ensure_installed = 'all', -- one of 'all' or a list of languages - ignore_install = { '' }, -- List of parsers to ignore installing - highlight = { - enable = true, -- false will disable the whole extension - disable = { }, -- list of language that will be disabled - }, - autopairs = { - enable = true, - }, - indent = { enable = true, disable = { } }, + ensure_installed = "all", -- one of 'all' or a list of languages + ignore_install = { "" }, -- List of parsers to ignore installing + highlight = { + enable = true, -- false will disable the whole extension + disable = {}, -- list of language that will be disabled + }, + autopairs = { + enable = true, + }, + indent = { enable = true, disable = { "yaml" } }, + rainbow = { + enable = true, + -- disable = { "jsx", "cpp" }, list of languages you want to disable the plugin for + extended_mode = true, -- Also highlight non-bracket delimiters like html tags, boolean or table: lang -> boolean + max_file_lines = nil, -- Do not enable for files with more than n lines, int + -- colors = {}, -- table of hex strings + -- termcolors = {} -- table of colour name strings + }, }) diff --git a/.config/nvim/lua/user/whichkey.lua b/.config/nvim/lua/user/whichkey.lua index 4812cc9a..820c5950 100644 --- a/.config/nvim/lua/user/whichkey.lua +++ b/.config/nvim/lua/user/whichkey.lua @@ -1,186 +1,195 @@ -local status_ok, which_key = pcall(require, 'which-key') +local status_ok, which_key = pcall(require, "which-key") if not status_ok then - return + return end local setup = { - plugins = { - marks = true, -- shows a list of your marks on ' and ` - registers = true, -- shows your registers on ' in NORMAL or in INSERT mode - spelling = { - enabled = true, -- enabling this will show WhichKey when pressing z= to select spelling suggestions - suggestions = 20, -- how many suggestions should be shown in the list? - }, - -- the presets plugin, adds help for a bunch of default keybindings in Neovim - -- No actual key bindings are created - presets = { - operators = false, -- adds help for operators like d, y, ... and registers them for motion / text object completion - motions = true, -- adds help for motions - text_objects = true, -- help for text objects triggered after entering an operator - windows = true, -- default bindings on - nav = true, -- misc bindings to work with windows - z = true, -- bindings for folds, spelling and others prefixed with z - g = true, -- bindings for prefixed with g - }, - }, - -- add operators that will trigger motion and text object completion - -- to enable all native operators, set the preset / operators plugin above - -- operators = { gc = 'Comments' }, - key_labels = { - -- override the label used to display some keys. It doesn't effect WK in any other way. - -- For example: - -- [''] = 'SPC', - -- [''] = 'RET', - -- [''] = 'TAB', - }, - icons = { - breadcrumb = '»', -- symbol used in the command line area that shows your active key combo - separator = '➜', -- symbol used between a key and it's label - group = '+', -- symbol prepended to a group - }, - popup_mappings = { - scroll_down = '', -- binding to scroll down inside the popup - scroll_up = '', -- binding to scroll up inside the popup - }, - window = { - border = 'rounded', -- none, single, double, shadow - position = 'bottom', -- bottom, top - margin = { 1, 0, 1, 0 }, -- extra window margin [top, right, bottom, left] - padding = { 2, 2, 2, 2 }, -- extra window padding [top, right, bottom, left] - winblend = 0, - }, - layout = { - height = { min = 4, max = 25 }, -- min and max height of the columns - width = { min = 20, max = 50 }, -- min and max width of the columns - spacing = 3, -- spacing between columns - align = 'left', -- align columns left, center or right - }, - ignore_missing = true, -- enable this to hide mappings for which you didn't specify a label - hidden = { '', '', '', '', 'call', 'lua', '^:', '^ ' }, -- hide mapping boilerplate - show_help = true, -- show help message on the command line when the popup is visible - triggers = 'auto', -- automatically setup triggers - -- triggers = {''} -- or specify a list manually - triggers_blacklist = { - -- list of mode / prefixes that should never be hooked by WhichKey - -- this is mostly relevant for key maps that start with a native binding - -- most people should not need to change this - i = { 'j', 'k' }, - v = { 'j', 'k' }, - }, + plugins = { + marks = true, -- shows a list of your marks on " and ` + registers = true, -- shows your registers on " in NORMAL or in INSERT mode + spelling = { + enabled = true, -- enabling this will show WhichKey when pressing z= to select spelling suggestions + suggestions = 20, -- how many suggestions should be shown in the list? + }, + -- the presets plugin, adds help for a bunch of default keybindings in Neovim + -- No actual key bindings are created + presets = { + operators = false, -- adds help for operators like d, y, ... and registers them for motion / text object completion + motions = true, -- adds help for motions + text_objects = true, -- help for text objects triggered after entering an operator + windows = true, -- default bindings on + nav = true, -- misc bindings to work with windows + z = true, -- bindings for folds, spelling and others prefixed with z + g = true, -- bindings for prefixed with g + }, + }, + -- add operators that will trigger motion and text object completion + -- to enable all native operators, set the preset / operators plugin above + -- operators = { gc = "Comments" }, + key_labels = { + -- override the label used to display some keys. It doesn"t effect WK in any other way. + -- For example: + -- [""] = "SPC", + -- [""] = "RET", + -- [""] = "TAB", + }, + icons = { + breadcrumb = "»", -- symbol used in the command line area that shows your active key combo + separator = "➜", -- symbol used between a key and it"s label + group = "+", -- symbol prepended to a group + }, + popup_mappings = { + scroll_down = "", -- binding to scroll down inside the popup + scroll_up = "", -- binding to scroll up inside the popup + }, + window = { + border = "rounded", -- none, single, double, shadow + position = "bottom", -- bottom, top + margin = { 1, 0, 1, 0 }, -- extra window margin [top, right, bottom, left] + padding = { 2, 2, 2, 2 }, -- extra window padding [top, right, bottom, left] + winblend = 0, + }, + layout = { + height = { min = 4, max = 25 }, -- min and max height of the columns + width = { min = 20, max = 50 }, -- min and max width of the columns + spacing = 3, -- spacing between columns + align = "left", -- align columns left, center or right + }, + ignore_missing = true, -- enable this to hide mappings for which you didn"t specify a label + hidden = { "", "", "", "", "call", "lua", "^:", "^ " }, -- hide mapping boilerplate + show_help = true, -- show help message on the command line when the popup is visible + triggers = "auto", -- automatically setup triggers + -- triggers = {""} -- or specify a list manually + triggers_blacklist = { + -- list of mode / prefixes that should never be hooked by WhichKey + -- this is mostly relevant for key maps that start with a native binding + -- most people should not need to change this + i = { "j", "k" }, + v = { "j", "k" }, + }, } local opts = { - mode = 'n', -- NORMAL mode - prefix = '', - buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings - silent = true, -- use `silent` when creating keymaps - noremap = true, -- use `noremap` when creating keymaps - nowait = true, -- use `nowait` when creating keymaps + mode = "n", -- NORMAL mode + prefix = "", + buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings + silent = true, -- use `silent` when creating keymaps + noremap = true, -- use `noremap` when creating keymaps + nowait = true, -- use `nowait` when creating keymaps } local mappings = { - ['a'] = { 'Alpha', 'Alpha' }, - ['b'] = { - 'lua require("telescope.builtin").buffers(require"telescope.themes").get_dropdown{previewer = false})', - 'Buffers', - }, - ['e'] = { 'NvimTreeToggle', 'Explorer' }, - ['w'] = { 'w!', 'Save' }, - ['q'] = { 'q!', 'Quit' }, - ['c'] = { 'Bdelete!', 'Close Buffer' }, - ['h'] = { 'nohlsearch', 'No Highlight' }, - ['f'] = { - 'lua require("telescope.builtin").find_files(require("telescope.themes").get_dropdown{previewer = false})', - 'Find files', - }, - ['F'] = { 'Telescope live_grep theme=ivy', 'Find Text' }, - ['P'] = { 'lua require("telescope").extensions.projects.projects()', 'Projects' }, + ["a"] = { "Alpha", "Alpha" }, + ["b"] = { + "lua require('telescope.builtin).buffers(require'telescope.themes').get_dropdown{previewer = false})", + "Buffers", + }, + ["e"] = { "NvimTreeToggle", "Explorer" }, + ["w"] = { "w!", "Save" }, + ["q"] = { "q!", "Quit" }, + ["c"] = { "Bdelete!", "Close Buffer" }, + ["h"] = { "nohlsearch", "No Highlight" }, + ["f"] = { + "lua require('telescope.builtin').find_files(require('telescope.themes').get_dropdown{previewer = false}) hidden=true", + "Find files", + }, + ["F"] = { "Telescope live_grep theme=ivy", "Find Text" }, + ["P"] = { "lua require('telescope').extensions.projects.projects()", "Projects" }, - p = { - name = 'Packer', - c = { 'PackerCompile', 'Compile' }, - i = { 'PackerInstall', 'Install' }, - s = { 'PackerSync', 'Sync' }, - S = { 'PackerStatus', 'Status' }, - u = { 'PackerUpdate', 'Update' }, - }, + p = { + name = "Packer", + c = { "PackerCompile", "Compile" }, + i = { "PackerInstall", "Install" }, + s = { "PackerSync", "Sync" }, + S = { "PackerStatus", "Status" }, + u = { "PackerUpdate", "Update" }, + }, - g = { - name = 'Git', - g = { 'lua _LAZYGIT_TOGGLE()', 'Lazygit' }, - j = { 'lua require "gitsigns".next_hunk()', 'Next Hunk' }, - k = { 'lua require "gitsigns".prev_hunk()', 'Prev Hunk' }, - l = { 'lua require "gitsigns".blame_line()', 'Blame' }, - p = { 'lua require "gitsigns".preview_hunk()', 'Preview Hunk' }, - r = { 'lua require "gitsigns".reset_hunk()', 'Reset Hunk' }, - R = { 'lua require "gitsigns".reset_buffer()', 'Reset Buffer' }, - s = { 'lua require "gitsigns".stage_hunk()', 'Stage Hunk' }, - u = { - 'lua require "gitsigns".undo_stage_hunk()', - 'Undo Stage Hunk', - }, - o = { 'Telescope git_status', 'Open changed file' }, - b = { 'Telescope git_branches', 'Checkout branch' }, - c = { 'Telescope git_commits', 'Checkout commit' }, - d = { - 'Gitsigns diffthis HEAD', - 'Diff', - }, - }, + g = { + name = "Git", + g = { "lua _LAZYGIT_TOGGLE()", "Lazygit" }, + j = { "lua require 'gitsigns'.next_hunk()", "Next Hunk" }, + k = { "lua require 'gitsigns'.prev_hunk()", "Prev Hunk" }, + l = { "lua require 'gitsigns'.blame_line()", "Blame" }, + p = { "lua require 'gitsigns'.preview_hunk()", "Preview Hunk" }, + r = { "lua require 'gitsigns'.reset_hunk()", "Reset Hunk" }, + R = { "lua require 'gitsigns'.reset_buffer()", "Reset Buffer" }, + s = { "lua require 'gitsigns'.stage_hunk()", "Stage Hunk" }, + u = { + "lua require 'gitsigns'.undo_stage_hunk()", + "Undo Stage Hunk", + }, + o = { "Telescope git_status", "Open changed file" }, + b = { "Telescope git_branches", "Checkout branch" }, + c = { "Telescope git_commits", "Checkout commit" }, + d = { + "Gitsigns diffthis HEAD", + "Diff", + }, + }, - l = { - name = 'LSP', - a = { 'lua vim.lsp.buf.code_action()', 'Code Action' }, - d = { - 'Telescope lsp_document_diagnostics', - 'Document Diagnostics', - }, - w = { - 'Telescope lsp_workspace_diagnostics', - 'Workspace Diagnostics', - }, - f = { 'lua vim.lsp.buf.format{async=true}', 'Format' }, - i = { 'LspInfo', 'Info' }, - I = { 'LspInstallInfo', 'Installer Info' }, - j = { - 'lua vim.lsp.diagnostic.goto_next()', - 'Next Diagnostic', - }, - k = { - 'lua vim.lsp.diagnostic.goto_prev()', - 'Prev Diagnostic', - }, - l = { 'lua vim.lsp.codelens.run()', 'CodeLens Action' }, - q = { 'lua vim.lsp.diagnostic.set_loclist()', 'Quickfix' }, - r = { 'lua vim.lsp.buf.rename()', 'Rename' }, - s = { 'Telescope lsp_document_symbols', 'Document Symbols' }, - S = { - 'Telescope lsp_dynamic_workspace_symbols', - 'Workspace Symbols', - }, - }, - s = { - name = 'Search', - b = { 'Telescope git_branches', 'Checkout branch' }, - c = { 'Telescope colorscheme', 'Colorscheme' }, - h = { 'Telescope help_tags', 'Find Help' }, - M = { 'Telescope man_pages', 'Man Pages' }, - r = { 'Telescope oldfiles', 'Open Recent File' }, - R = { 'Telescope registers', 'Registers' }, - k = { 'Telescope keymaps', 'Keymaps' }, - C = { 'Telescope commands', 'Commands' }, - }, + l = { + name = "LSP", + a = { "lua vim.lsp.buf.code_action()", "Code Action" }, + d = { + "Telescope lsp_document_diagnostics", + "Document Diagnostics", + }, + w = { + "Telescope lsp_workspace_diagnostics", + "Workspace Diagnostics", + }, + f = { "lua vim.lsp.buf.format{async=true}", "Format" }, + i = { "LspInfo", "Info" }, + I = { "LspInstallInfo", "Installer Info" }, + j = { + "lua vim.lsp.diagnostic.goto_next()", + "Next Diagnostic", + }, + k = { + "lua vim.lsp.diagnostic.goto_prev()", + "Prev Diagnostic", + }, + l = { "lua vim.lsp.codelens.run()", "CodeLens Action" }, + q = { "lua vim.lsp.diagnostic.set_loclist()", "Quickfix" }, + r = { "lua vim.lsp.buf.rename()", "Rename" }, + s = { "Telescope lsp_document_symbols", "Document Symbols" }, + S = { + "Telescope lsp_dynamic_workspace_symbols", + "Workspace Symbols", + }, + }, + s = { + name = "Search", + s = { "s%//", "Replace word" }, + b = { "Telescope git_branches", "Checkout branch" }, + c = { "Telescope colorscheme", "Colorscheme" }, + h = { "Telescope help_tags", "Find Help" }, + M = { "Telescope man_pages", "Man Pages" }, + r = { "Telescope oldfiles", "Open Recent File" }, + R = { "Telescope registers", "Registers" }, + k = { "Telescope keymaps", "Keymaps" }, + C = { "Telescope commands", "Commands" }, + }, - t = { - name = 'Terminal', - n = { 'lua _NODE_TOGGLE()', 'Node' }, - u = { 'lua _NCDU_TOGGLE()', 'NCDU' }, - t = { 'lua _HTOP_TOGGLE()', 'Htop' }, - p = { 'lua _PYTHON_TOGGLE()', 'Python' }, - f = { 'ToggleTerm direction=float', 'Float' }, - h = { 'ToggleTerm size=10 direction=horizontal', 'Horizontal' }, - v = { 'ToggleTerm size=80 direction=vertical', 'Vertical' }, - }, + t = { + name = "Terminal", + n = { "lua _NODE_TOGGLE()", "Node" }, + u = { "lua _NCDU_TOGGLE()", "NCDU" }, + t = { "lua _BTOP_TOGGLE()", "Btop" }, + p = { "lua _PYTHON_TOGGLE()", "Python" }, + f = { "ToggleTerm direction=float", "Float" }, + h = { "ToggleTerm size=10 direction=horizontal", "Horizontal" }, + v = { "ToggleTerm size=80 direction=vertical", "Vertical" }, + }, + S = { + name = "Settings", + c = { "setlocal formatoptions-=cro", "Disable autocomment" }, + C = { "setlocal formatoptions=cro", "Enable autocomment" }, + s = { "setlocal spell! spelllang=en_us", "Toggle spellchecker" }, + I = { "setlocal autoindent", "Enable autoindent" }, + i = { "setlocal noautoindent", "Disable autoindent" }, + }, } which_key.setup(setup) diff --git a/.config/zlua/z.lua b/.config/zlua/z.lua index 1f7563db..cf15e19f 100644 --- a/.config/zlua/z.lua +++ b/.config/zlua/z.lua @@ -83,11 +83,10 @@ -- --===================================================================== - ----------------------------------------------------------------------- -- Module Header ----------------------------------------------------------------------- -local modname = 'z' +local modname = "z" local MM = {} _G[modname] = MM package.loaded[modname] = MM --return modname @@ -99,43 +98,40 @@ else setfenv(1, MM) end - ----------------------------------------------------------------------- -- Environment ----------------------------------------------------------------------- -local windows = package.config:sub(1, 1) ~= '/' and true or false +local windows = package.config:sub(1, 1) ~= "/" and true or false local in_module = pcall(debug.getlocal, 4, 1) and true or false local utils = {} os.path = {} os.argv = arg ~= nil and arg or {} -os.path.sep = windows and '\\' or '/' - +os.path.sep = windows and "\\" or "/" ----------------------------------------------------------------------- -- Global Variable ----------------------------------------------------------------------- MAX_AGE = 5000 -DATA_FILE = '~/.config/zlua/.zlua' -PRINT_MODE = '' -PWD = '' -Z_METHOD = 'frecent' +DATA_FILE = "~/.config/zlua/.zlua" +PRINT_MODE = "" +PWD = "" +Z_METHOD = "frecent" Z_SUBDIR = false Z_INTERACTIVE = 0 Z_EXCLUDE = {} -Z_CMD = 'z' +Z_CMD = "z" Z_MATCHMODE = 0 Z_MATCHNAME = false Z_SKIPPWD = false Z_HYPHEN = false -os.LOG_NAME = os.getenv('_ZL_LOG_NAME') - +os.LOG_NAME = os.getenv("_ZL_LOG_NAME") ----------------------------------------------------------------------- -- string lib ----------------------------------------------------------------------- function string:split(sSeparator, nMax, bRegexp) - assert(sSeparator ~= '') + assert(sSeparator ~= "") assert(nMax == nil or nMax >= 1) local aRecord = {} if self:len() > 0 then @@ -152,7 +148,7 @@ function string:split(sSeparator, nMax, bRegexp) end aRecord[nField] = self:sub(nStart) else - aRecord[1] = '' + aRecord[1] = "" end return aRecord end @@ -166,18 +162,22 @@ function string:startswith(text) end function string:endswith(text) - return text == "" or self:sub(- #text) == text + return text == "" or self:sub(-#text) == text end function string:lstrip() - if self == nil then return nil end - local s = self:gsub('^%s+', '') + if self == nil then + return nil + end + local s = self:gsub("^%s+", "") return s end function string:rstrip() - if self == nil then return nil end - local s = self:gsub('%s+$', '') + if self == nil then + return nil + end + local s = self:gsub("%s+$", "") return s end @@ -186,7 +186,7 @@ function string:strip() end function string:rfind(key) - if key == '' then + if key == "" then return self:len(), 0 end local length = self:len() @@ -199,10 +199,10 @@ end function string:join(parts) if parts == nil or #parts == 0 then - return '' + return "" end local size = #parts - local text = '' + local text = "" local index = 1 while index <= size do if index == 1 then @@ -220,8 +220,12 @@ end ----------------------------------------------------------------------- function table.length(T) local count = 0 - if T == nil then return 0 end - for _ in pairs(T) do count = count + 1 end + if T == nil then + return 0 + end + for _ in pairs(T) do + count = count + 1 + end return count end @@ -229,13 +233,15 @@ end -- print table ----------------------------------------------------------------------- function dump(o) - if type(o) == 'table' then - local s = '{ ' + if type(o) == "table" then + local s = "{ " for k, v in pairs(o) do - if type(k) ~= 'number' then k = '"' .. k .. '"' end - s = s .. '[' .. k .. '] = ' .. dump(v) .. ',' + if type(k) ~= "number" then + k = '"' .. k .. '"' + end + s = s .. "[" .. k .. "] = " .. dump(v) .. "," end - return s .. '} ' + return s .. "} " else return tostring(o) end @@ -282,7 +288,7 @@ function os.call(command) if fp == nil then return nil end - local line = fp:read('*l') + local line = fp:read("*l") fp:close() return line end @@ -294,11 +300,11 @@ function os.log(text) if not os.LOG_NAME then return end - local fp = io.open(os.LOG_NAME, 'a') + local fp = io.open(os.LOG_NAME, "a") if not fp then return end - local date = "[" .. os.date('%Y-%m-%d %H:%M:%S') .. "] " + local date = "[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] " fp:write(date .. text .. "\n") fp:close() end @@ -311,7 +317,7 @@ os.native.status, os.native.ffi = pcall(require, "ffi") if os.native.status then local ffi = os.native.ffi if windows then - ffi.cdef [[ + ffi.cdef([[ int GetFullPathNameA(const char *name, uint32_t size, char *out, char **name); int ReplaceFileA(const char *dstname, const char *srcname, void *, uint32_t, void *, void *); uint32_t GetTickCount(void); @@ -319,9 +325,9 @@ if os.native.status then uint32_t GetCurrentDirectoryA(uint32_t size, char *ptr); uint32_t GetShortPathNameA(const char *longname, char *shortname, uint32_t size); uint32_t GetLongPathNameA(const char *shortname, char *longname, uint32_t size); - ]] - local kernel32 = ffi.load('kernel32.dll') - local buffer = ffi.new('char[?]', 4100) + ]]) + local kernel32 = ffi.load("kernel32.dll") + local buffer = ffi.new("char[?]", 4100) local INVALID_FILE_ATTRIBUTES = 0xffffffff local FILE_ATTRIBUTE_DIRECTORY = 0x10 os.native.kernel32 = kernel32 @@ -377,19 +383,21 @@ if os.native.status then function os.native.getcwd() local hr = kernel32.GetCurrentDirectoryA(4096, buffer) - if hr <= 0 then return nil end + if hr <= 0 then + return nil + end return ffi.string(buffer, hr) end else - ffi.cdef [[ + ffi.cdef([[ typedef struct { long tv_sec; long tv_usec; } timeval; int gettimeofday(timeval *tv, void *tz); int access(const char *name, int mode); char *realpath(const char *path, char *resolve); char *getcwd(char *buf, size_t size); - ]] - local timeval = ffi.new('timeval[?]', 1) - local buffer = ffi.new('char[?]', 4100) + ]]) + local timeval = ffi.new("timeval[?]", 1) + local buffer = ffi.new("char[?]", 4100) function os.native.gettimeofday() local hr = ffi.C.gettimeofday(timeval, nil) local sec = tonumber(timeval[0].tv_sec) @@ -422,32 +430,33 @@ if os.native.status then os.native.init = true end - ----------------------------------------------------------------------- -- get current path ----------------------------------------------------------------------- function os.pwd() if os.native and os.native.getcwd then local hr = os.native.getcwd() - if hr then return hr end + if hr then + return hr + end end if os.getcwd then return os.getcwd() end if windows then - local fp = io.popen('cd') + local fp = io.popen("cd") if fp == nil then - return '' + return "" end - local line = fp:read('*l') + local line = fp:read("*l") fp:close() return line else - local fp = io.popen('pwd') + local fp = io.popen("pwd") if fp == nil then - return '' + return "" end - local line = fp:read('*l') + local line = fp:read("*l") fp:close() return line end @@ -457,22 +466,22 @@ end -- which executable ----------------------------------------------------------------------- function os.path.which(exename) - local path = os.getenv('PATH') + local path = os.getenv("PATH") if windows then - paths = ('.;' .. path):split(';') + paths = (".;" .. path):split(";") else - paths = path:split(':') + paths = path:split(":") end for _, path in pairs(paths) do if not windows then - local name = path .. '/' .. exename + local name = path .. "/" .. exename if os.path.exists(name) then return name end else - for _, ext in pairs({ '.exe', '.cmd', '.bat' }) do - local name = path .. '\\' .. exename .. ext - if path == '.' then + for _, ext in pairs({ ".exe", ".cmd", ".bat" }) do + local name = path .. "\\" .. exename .. ext + if path == "." then name = exename .. ext end if os.path.exists(name) then @@ -496,49 +505,53 @@ end -- absolute path (system call, can fall back to os.path.absolute) ----------------------------------------------------------------------- function os.path.abspath(path) - if path == '' then path = '.' end + if path == "" then + path = "." + end if os.native and os.native.GetFullPathName then local test = os.native.GetFullPathName(path) - if test then return test end + if test then + return test + end end if windows then local script = 'FOR /f "delims=" %%i IN ("%s") DO @echo %%~fi' local script = string.format(script, path) - local script = 'cmd.exe /C ' .. script .. ' 2> nul' + local script = "cmd.exe /C " .. script .. " 2> nul" local output = os.call(script) - local test = output:gsub('%s$', '') - if test ~= nil and test ~= '' then + local test = output:gsub("%s$", "") + if test ~= nil and test ~= "" then return test end else - local test = os.path.which('realpath') - if test ~= nil and test ~= '' then - test = os.call('realpath -s \'' .. path .. '\' 2> /dev/null') - if test ~= nil and test ~= '' then + local test = os.path.which("realpath") + if test ~= nil and test ~= "" then + test = os.call("realpath -s '" .. path .. "' 2> /dev/null") + if test ~= nil and test ~= "" then return test end - test = os.call('realpath \'' .. path .. '\' 2> /dev/null') - if test ~= nil and test ~= '' then + test = os.call("realpath '" .. path .. "' 2> /dev/null") + if test ~= nil and test ~= "" then return test end end - local test = os.path.which('perl') - if test ~= nil and test ~= '' then - local s = 'perl -MCwd -e "print Cwd::realpath(\\$ARGV[0])" \'%s\'' + local test = os.path.which("perl") + if test ~= nil and test ~= "" then + local s = "perl -MCwd -e \"print Cwd::realpath(\\$ARGV[0])\" '%s'" local s = string.format(s, path) test = os.call(s) - if test ~= nil and test ~= '' then + if test ~= nil and test ~= "" then return test end end - for _, python in pairs({ 'python3', 'python2', 'python' }) do - local s = 'sys.stdout.write(os.path.abspath(sys.argv[1]))' - local s = '-c "import os, sys;' .. s .. '" \'' .. path .. '\'' - local s = python .. ' ' .. s + for _, python in pairs({ "python3", "python2", "python" }) do + local s = "sys.stdout.write(os.path.abspath(sys.argv[1]))" + local s = '-c "import os, sys;' .. s .. "\" '" .. path .. "'" + local s = python .. " " .. s local test = os.path.which(python) - if test ~= nil and test ~= '' then + if test ~= nil and test ~= "" then test = os.call(s) - if test ~= nil and test ~= '' then + if test ~= nil and test ~= "" then return test end end @@ -551,12 +564,12 @@ end -- dir exists ----------------------------------------------------------------------- function os.path.isdir(pathname) - if pathname == '/' then + if pathname == "/" then return true - elseif pathname == '' then + elseif pathname == "" then return false elseif windows then - if pathname == '\\' then + if pathname == "\\" then return true end end @@ -567,7 +580,7 @@ function os.path.isdir(pathname) return os.isdir(pathname) end local name = pathname - if (not name:endswith('/')) and (not name:endswith('\\')) then + if (not name:endswith("/")) and (not name:endswith("\\")) then name = name .. os.path.sep end return os.path.exists(name) @@ -577,7 +590,7 @@ end -- file or path exists ----------------------------------------------------------------------- function os.path.exists(name) - if name == '/' then + if name == "/" then return true end if os.native and os.native.exists then @@ -593,8 +606,8 @@ function os.path.exists(name) io.close(f) return true end - elseif name:sub(-1) == '/' and code == 20 and (not windows) then - local test = name .. '.' + elseif name:sub(-1) == "/" and code == 20 and not windows then + local test = name .. "." ok, err, code = os.rename(test, test) if code == 16 or code == 13 or code == 22 then return true @@ -609,16 +622,16 @@ end -- is absolute path ----------------------------------------------------------------------- function os.path.isabs(path) - if path == nil or path == '' then + if path == nil or path == "" then return false - elseif path:sub(1, 1) == '/' then + elseif path:sub(1, 1) == "/" then return true end if windows then local head = path:sub(1, 1) - if head == '\\' then + if head == "\\" then return true - elseif path:match('^%a:[/\\]') ~= nil then + elseif path:match("^%a:[/\\]") ~= nil then return true end end @@ -630,10 +643,10 @@ end ----------------------------------------------------------------------- function os.path.norm(pathname) if windows then - pathname = pathname:gsub('\\', '/') + pathname = pathname:gsub("\\", "/") end if windows then - pathname = pathname:gsub('/', '\\') + pathname = pathname:gsub("/", "\\") end return pathname end @@ -642,34 +655,34 @@ end -- normalize . and .. ----------------------------------------------------------------------- function os.path.normpath(path) - if os.path.sep ~= '/' then - path = path:gsub('\\', '/') + if os.path.sep ~= "/" then + path = path:gsub("\\", "/") end - path = path:gsub('/+', '/') + path = path:gsub("/+", "/") local srcpath = path - local basedir = '' + local basedir = "" local isabs = false - if windows and path:sub(2, 2) == ':' then + if windows and path:sub(2, 2) == ":" then basedir = path:sub(1, 2) path = path:sub(3, -1) end - if path:sub(1, 1) == '/' then - basedir = basedir .. '/' + if path:sub(1, 1) == "/" then + basedir = basedir .. "/" isabs = true path = path:sub(2, -1) end - local parts = path:split('/') + local parts = path:split("/") local output = {} for _, path in ipairs(parts) do - if path == '.' or path == '' then - elseif path == '..' then + if path == "." or path == "" then + elseif path == ".." then local size = #output if size == 0 then if not isabs then - table.insert(output, '..') + table.insert(output, "..") end - elseif output[size] == '..' then - table.insert(output, '..') + elseif output[size] == ".." then + table.insert(output, "..") else table.remove(output, size) end @@ -677,61 +690,63 @@ function os.path.normpath(path) table.insert(output, path) end end - path = basedir .. string.join('/', output) - if windows then path = path:gsub('/', '\\') end - return path == '' and '.' or path + path = basedir .. string.join("/", output) + if windows then + path = path:gsub("/", "\\") + end + return path == "" and "." or path end ----------------------------------------------------------------------- -- join two path ----------------------------------------------------------------------- function os.path.join(path1, path2) - if path1 == nil or path1 == '' then - if path2 == nil or path2 == '' then - return '' + if path1 == nil or path1 == "" then + if path2 == nil or path2 == "" then + return "" else return path2 end - elseif path2 == nil or path2 == '' then + elseif path2 == nil or path2 == "" then local head = path1:sub(-1, -1) - if head == '/' or (windows and head == '\\') then + if head == "/" or (windows and head == "\\") then return path1 end return path1 .. os.path.sep elseif os.path.isabs(path2) then if windows then local head = path2:sub(1, 1) - if head == '/' or head == '\\' then - if path1:match('^%a:') then + if head == "/" or head == "\\" then + if path1:match("^%a:") then return path1:sub(1, 2) .. path2 end end end return path2 elseif windows then - local d1 = path1:match('^%a:') and path1:sub(1, 2) or '' - local d2 = path2:match('^%a:') and path2:sub(1, 2) or '' - if d1 ~= '' then - if d2 ~= '' then + local d1 = path1:match("^%a:") and path1:sub(1, 2) or "" + local d2 = path2:match("^%a:") and path2:sub(1, 2) or "" + if d1 ~= "" then + if d2 ~= "" then if d1:lower() == d2:lower() then return d2 .. os.path.join(path1:sub(3), path2:sub(3)) else return path2 end end - elseif d2 ~= '' then + elseif d2 ~= "" then return path2 end end local postsep = true local len1 = path1:len() local len2 = path2:len() - if path1:sub(-1, -1) == '/' then + if path1:sub(-1, -1) == "/" then postsep = false elseif windows then - if path1:sub(-1, -1) == '\\' then + if path1:sub(-1, -1) == "\\" then postsep = false - elseif len1 == 2 and path1:sub(2, 2) == ':' then + elseif len1 == 2 and path1:sub(2, 2) == ":" then postsep = false end end @@ -746,49 +761,49 @@ end -- split ----------------------------------------------------------------------- function os.path.split(path) - if path == '' then - return '', '' + if path == "" then + return "", "" end - local pos = path:rfind('/') - if os.path.sep == '\\' then - local p2 = path:rfind('\\') + local pos = path:rfind("/") + if os.path.sep == "\\" then + local p2 = path:rfind("\\") if pos == nil and p2 ~= nil then pos = p2 elseif pos ~= nil and p2 ~= nil then pos = (pos < p2) and pos or p2 end - if path:match('^%a:[/\\]') and pos == nil then + if path:match("^%a:[/\\]") and pos == nil then return path:sub(1, 2), path:sub(3) end end if pos == nil then if windows then - local drive = path:match('^%a:') and path:sub(1, 2) or '' - if drive ~= '' then + local drive = path:match("^%a:") and path:sub(1, 2) or "" + if drive ~= "" then return path:sub(1, 2), path:sub(3) end end - return '', path + return "", path elseif pos == 1 then return path:sub(1, 1), path:sub(2) elseif windows then - local drive = path:match('^%a:') and path:sub(1, 2) or '' - if pos == 3 and drive ~= '' then + local drive = path:match("^%a:") and path:sub(1, 2) or "" + if pos == 3 and drive ~= "" then return path:sub(1, 3), path:sub(4) end end local head = path:sub(1, pos) local tail = path:sub(pos + 1) if not windows then - local test = string.rep('/', head:len()) + local test = string.rep("/", head:len()) if head ~= test then - head = head:gsub('/+$', '') + head = head:gsub("/+$", "") end else - local t1 = string.rep('/', head:len()) - local t2 = string.rep('\\', head:len()) + local t1 = string.rep("/", head:len()) + local t2 = string.rep("\\", head:len()) if head ~= t1 and head ~= t2 then - head = head:gsub('[/\\]+$', '') + head = head:gsub("[/\\]+$", "") end end return head, tail @@ -799,14 +814,14 @@ end ----------------------------------------------------------------------- function os.path.subdir(basename, subname) if windows then - basename = basename:gsub('\\', '/') - subname = subname:gsub('\\', '/') + basename = basename:gsub("\\", "/") + subname = subname:gsub("\\", "/") basename = basename:lower() subname = subname:lower() end local last = basename:sub(-1, -1) - if last ~= '/' then - basename = basename .. '/' + if last ~= "/" then + basename = basename .. "/" end if subname:find(basename, 0, true) == 1 then return true @@ -818,11 +833,11 @@ end -- check single name element ----------------------------------------------------------------------- function os.path.single(path) - if string.match(path, '/') then + if string.match(path, "/") then return false end if windows then - if string.match(path, '\\') then + if string.match(path, "\\") then return false end end @@ -833,25 +848,25 @@ end -- expand user home ----------------------------------------------------------------------- function os.path.expand(pathname) - if not pathname:find('~') then + if not pathname:find("~") then return pathname end - local home = '' + local home = "" if windows then - home = os.getenv('USERPROFILE') + home = os.getenv("USERPROFILE") else - home = os.getenv('HOME') + home = os.getenv("HOME") end - if pathname == '~' then + if pathname == "~" then return home end local head = pathname:sub(1, 2) if windows then - if head == '~/' or head == '~\\' then - return home .. '\\' .. pathname:sub(3, -1) + if head == "~/" or head == "~\\" then + return home .. "\\" .. pathname:sub(3, -1) end - elseif head == '~/' then - return home .. '/' .. pathname:sub(3, -1) + elseif head == "~/" then + return home .. "/" .. pathname:sub(3, -1) end return pathname end @@ -859,8 +874,7 @@ end ----------------------------------------------------------------------- -- search executable ----------------------------------------------------------------------- -function os.path.search(name) -end +function os.path.search(name) end ----------------------------------------------------------------------- -- get lua executable @@ -904,32 +918,32 @@ end ----------------------------------------------------------------------- function os.environ(name, default) local value = os.getenv(name) - if os.envmap ~= nil and type(os.envmap) == 'table' then + if os.envmap ~= nil and type(os.envmap) == "table" then local t = os.envmap[name] - value = (t ~= nil and type(t) == 'string') and t or value + value = (t ~= nil and type(t) == "string") and t or value end if value == nil then return default - elseif type(default) == 'boolean' then + elseif type(default) == "boolean" then value = value:lower() - if value == '0' or value == '' or value == 'no' then + if value == "0" or value == "" or value == "no" then return false - elseif value == 'false' or value == 'n' or value == 'f' then + elseif value == "false" or value == "n" or value == "f" then return false else return true end - elseif type(default) == 'number' then + elseif type(default) == "number" then value = tonumber(value) if value == nil then return default else return value end - elseif type(default) == 'string' then + elseif type(default) == "string" then return value - elseif type(default) == 'table' then - return value:sep(',') + elseif type(default) == "table" then + return value:sep(",") end end @@ -942,7 +956,7 @@ function os.getopt(argv) argv = argv ~= nil and argv or os.argv if argv == nil then return nil, nil - elseif (#argv) == 0 then + elseif #argv == 0 then return options, args end local count = #argv @@ -950,19 +964,19 @@ function os.getopt(argv) while index <= count do local arg = argv[index] local head = arg:sub(1, 1) - if arg ~= '' then - if head ~= '-' then + if arg ~= "" then + if head ~= "-" then break end - if arg == '-' then - options['-'] = '' - elseif arg == '--' then - options['-'] = '-' - elseif arg:match('^-%d+$') then - options['-'] = arg:sub(2) + if arg == "-" then + options["-"] = "" + elseif arg == "--" then + options["-"] = "-" + elseif arg:match("^-%d+$") then + options["-"] = arg:sub(2) else - local part = arg:split('=') - options[part[1]] = part[2] ~= nil and part[2] or '' + local part = arg:split("=") + options[part[1]] = part[2] ~= nil and part[2] or "" end end index = index + 1 @@ -983,18 +997,18 @@ function math.random_init() seed = seed .. tostring(math.random(99999999)) if os.argv ~= nil then for _, key in ipairs(os.argv) do - seed = seed .. '/' .. key + seed = seed .. "/" .. key end end - local ppid = os.getenv('PPID') - seed = (ppid ~= nil) and (seed .. '/' .. ppid) or seed + local ppid = os.getenv("PPID") + seed = (ppid ~= nil) and (seed .. "/" .. ppid) or seed -- random seed from socket.gettime() - local status, socket = pcall(require, 'socket') + local status, socket = pcall(require, "socket") if status then seed = seed .. tostring(socket.gettime()) end -- random seed from _ZL_RANDOM - local rnd = os.getenv('_ZL_RANDOM') + local rnd = os.getenv("_ZL_RANDOM") if rnd ~= nil then seed = seed .. rnd end @@ -1014,7 +1028,7 @@ end -- math random string ----------------------------------------------------------------------- function math.random_string(N) - local text = '' + local text = "" for i = 1, N do local k = math.random(0, 26 * 2 + 10 - 1) if k < 26 then @@ -1036,10 +1050,10 @@ function path_case_insensitive() if windows then return true end - local eos = os.getenv('OS') - eos = eos ~= nil and eos or '' + local eos = os.getenv("OS") + eos = eos ~= nil and eos or "" eos = eos:lower() - if eos:sub(1, 7) == 'windows' then + if eos:sub(1, 7) == "windows" then return true end return false @@ -1052,12 +1066,12 @@ function data_load(filename) local M = {} local N = {} local insensitive = path_case_insensitive() - local fp = io.open(os.path.expand(filename), 'r') + local fp = io.open(os.path.expand(filename), "r") if fp == nil then return {} end for line in fp:lines() do - local part = string.split(line, '|') + local part = string.split(line, "|") local item = {} if part and part[1] and part[2] and part[3] then local key = insensitive and part[1]:lower() or part[1] @@ -1089,10 +1103,10 @@ function data_save(filename, M) filename = os.path.expand(filename) math.random_init() while true do - tmpname = filename .. '.' .. tostring(os.time()) + tmpname = filename .. "." .. tostring(os.time()) if os.native and os.native.tickcount then local key = os.native.tickcount() % 1000 - tmpname = tmpname .. string.format('%03d', key) + tmpname = tmpname .. string.format("%03d", key) tmpname = tmpname .. math.random_string(5) else tmpname = tmpname .. math.random_string(8) @@ -1104,21 +1118,21 @@ function data_save(filename, M) end if windows then if os.native and os.native.ReplaceFile then - fp = io.open(tmpname, 'w') + fp = io.open(tmpname, "w") else - fp = io.open(filename, 'w') + fp = io.open(filename, "w") tmpname = nil end else - fp = io.open(tmpname, 'w') + fp = io.open(tmpname, "w") end if fp == nil then return false end for i = 1, #M do local item = M[i] - local text = item.name .. '|' .. item.rank .. '|' .. item.time - fp:write(text .. '\n') + local text = item.name .. "|" .. item.rank .. "|" .. item.time + fp:write(text .. "\n") end fp:close() if tmpname ~= nil then @@ -1219,7 +1233,6 @@ end function case_insensitive_pattern(pattern) -- find an optional '%' (group 1) followed by any character (group 2) local p = pattern:gsub("(%%?)(.)", function(percent, letter) - if percent ~= "" or not letter:match("%a") then -- if the '%' matched, or `letter` is not a letter, return "as is" return percent .. letter @@ -1247,7 +1260,7 @@ function path_match(pathname, patterns, matchlast) pos = endup + 1 end if matchlast and #patterns > 0 then - local last = '' + local last = "" local index = #patterns local pat = patterns[index] if not windows then @@ -1275,7 +1288,7 @@ function data_select(M, patterns, matchlast) for i = 1, #patterns do local p = patterns[i] if Z_HYPHEN then - p = p:gsub('-', '%%-') + p = p:gsub("-", "%%-") end table.insert(pats, case_insensitive_pattern(p)) end @@ -1316,18 +1329,18 @@ end function z_add(path) local paths = {} local count = 0 - if type(path) == 'table' then + if type(path) == "table" then paths = path - elseif type(path) == 'string' then + elseif type(path) == "string" then paths[1] = path end if table.length(paths) == 0 then return false end - local H = os.getenv('HOME') + local H = os.getenv("HOME") local M = data_load(DATA_FILE) - local nc = os.getenv('_ZL_NO_CHECK') - if nc == nil or nc == '' or nc == '0' then + local nc = os.getenv("_ZL_NO_CHECK") + if nc == nil or nc == "" or nc == "0" then M = data_filter(M) end -- insert paths @@ -1338,9 +1351,9 @@ function z_add(path) path = os.path.norm(path) -- check ignore if windows then - if path:len() == 3 and path:sub(2, 2) == ':' then + if path:len() == 3 and path:sub(2, 2) == ":" then local tail = path:sub(3, 3) - if tail == '/' or tail == '\\' then + if tail == "/" or tail == "\\" then skip = true end end @@ -1386,15 +1399,15 @@ function z_remove(path) local paths = {} local count = 0 local remove = {} - if type(path) == 'table' then + if type(path) == "table" then paths = path - elseif type(path) == 'string' then + elseif type(path) == "string" then paths[1] = path end if table.length(paths) == 0 then return false end - local H = os.getenv('HOME') + local H = os.getenv("HOME") local M = data_load(DATA_FILE) local X = {} M = data_filter(M) @@ -1427,7 +1440,7 @@ end ----------------------------------------------------------------------- function z_match(patterns, method, subdir) patterns = patterns ~= nil and patterns or {} - method = method ~= nil and method or 'frecent' + method = method ~= nil and method or "frecent" subdir = subdir ~= nil and subdir or false local M = data_load(DATA_FILE) M = data_select(M, patterns, false) @@ -1440,12 +1453,12 @@ function z_match(patterns, method, subdir) end end M = data_update_frecent(M) - if method == 'time' then + if method == "time" then current = os.time() for _, item in pairs(M) do item.score = item.time - current end - elseif method == 'rank' then + elseif method == "rank" then for _, item in pairs(M) do item.score = item.rank end @@ -1454,12 +1467,14 @@ function z_match(patterns, method, subdir) item.score = item.frecent end end - table.sort(M, function(a, b) return a.score > b.score end) - local pwd = (PWD == nil or PWD == '') and os.getenv('PWD') or PWD - if pwd == nil or pwd == '' then + table.sort(M, function(a, b) + return a.score > b.score + end) + local pwd = (PWD == nil or PWD == "") and os.getenv("PWD") or PWD + if pwd == nil or pwd == "" then pwd = os.pwd() end - if pwd ~= '' and pwd ~= nil then + if pwd ~= "" and pwd ~= nil then if subdir then local N = {} for _, item in pairs(M) do @@ -1494,7 +1509,7 @@ function z_print(M, weight, number) local numsize = string.len(tostring(#M)) for _, item in pairs(M) do local record = {} - record.score = string.format('%.2f', item.score) + record.score = string.format("%.2f", item.score) record.name = item.name table.insert(N, record) if record.score:len() > maxsize then @@ -1502,48 +1517,50 @@ function z_print(M, weight, number) end end local fp = io.stdout - if PRINT_MODE == '' then + if PRINT_MODE == "" then fp = io.stdout - elseif PRINT_MODE == '' then + elseif PRINT_MODE == "" then fp = io.stderr else - fp = io.open(PRINT_MODE, 'w') + fp = io.open(PRINT_MODE, "w") end for i = #N, 1, -1 do local record = N[i] local line = record.score while true do local tail = line:sub(-1, -1) - if tail ~= '0' and tail ~= '.' then + if tail ~= "0" and tail ~= "." then break end line = line:sub(1, -2) - if tail == '.' then + if tail == "." then break end end local dx = maxsize - line:len() if dx > 0 then - line = line .. string.rep(' ', dx) + line = line .. string.rep(" ", dx) end if weight then - line = line .. ' ' .. record.name + line = line .. " " .. record.name else line = record.name end if number then local head = tostring(i) if head:len() < numsize then - head = string.rep(' ', numsize - head:len()) .. head + head = string.rep(" ", numsize - head:len()) .. head end - line = head .. ': ' .. line + line = head .. ": " .. line end if fp ~= nil then - fp:write(line .. '\n') + fp:write(line .. "\n") end end - if PRINT_MODE:sub(1, 1) ~= '<' then - if fp ~= nil then fp:close() end + if PRINT_MODE:sub(1, 1) ~= "<" then + if fp ~= nil then + fp:close() + end end end @@ -1558,16 +1575,16 @@ function z_cd(patterns) return nil end local last = patterns[#patterns] - if last == '~' or last == '~/' then - return os.path.expand('~') - elseif windows and last == '~\\' then - return os.path.expand('~') + if last == "~" or last == "~/" then + return os.path.expand("~") + elseif windows and last == "~\\" then + return os.path.expand("~") end if os.path.isabs(last) and os.path.isdir(last) then local size = #patterns if size <= 1 then return os.path.norm(last) - elseif last ~= '/' and last ~= '\\' then + elseif last ~= "/" and last ~= "\\" then return os.path.norm(last) end end @@ -1582,17 +1599,19 @@ function z_cd(patterns) elseif Z_INTERACTIVE == 0 then return M[1].name end - if os.environ('_ZL_INT_SORT', false) then - table.sort(M, function(a, b) return a.name < b.name end) + if os.environ("_ZL_INT_SORT", false) then + table.sort(M, function(a, b) + return a.name < b.name + end) end local retval = nil if Z_INTERACTIVE == 1 then - PRINT_MODE = '' + PRINT_MODE = "" z_print(M, true, true) - io.stderr:write('> ') + io.stderr:write("> ") io.stderr:flush() - local input = io.read('*l') - if input == nil or input == '' then + local input = io.read("*l") + if input == nil or input == "" then return nil end local index = tonumber(input) @@ -1604,22 +1623,22 @@ function z_cd(patterns) end retval = M[index].name elseif Z_INTERACTIVE == 2 then - local fzf = os.environ('_ZL_FZF', 'fzf') - local tmpname = '/tmp/zlua.txt' - local cmd = '--nth 2.. --reverse --inline-info --tac ' - local flag = os.environ('_ZL_FZF_FLAG', '') - flag = (flag == '' or flag == nil) and '+s -e' or flag - cmd = ((fzf == '') and 'fzf' or fzf) .. ' ' .. cmd .. ' ' .. flag + local fzf = os.environ("_ZL_FZF", "fzf") + local tmpname = "/tmp/zlua.txt" + local cmd = "--nth 2.. --reverse --inline-info --tac " + local flag = os.environ("_ZL_FZF_FLAG", "") + flag = (flag == "" or flag == nil) and "+s -e" or flag + cmd = ((fzf == "") and "fzf" or fzf) .. " " .. cmd .. " " .. flag if not windows then tmpname = os.tmpname() - local height = os.environ('_ZL_FZF_HEIGHT', '35%') - if height ~= nil and height ~= '' and height ~= '0' then - cmd = cmd .. ' --height ' .. height + local height = os.environ("_ZL_FZF_HEIGHT", "35%") + if height ~= nil and height ~= "" and height ~= "0" then + cmd = cmd .. " --height " .. height end cmd = cmd .. ' < "' .. tmpname .. '"' else - tmpname = os.tmpname():gsub('\\', ''):gsub('%.', '') - tmpname = os.environ('TMP', '') .. '\\zlua_' .. tmpname .. '.txt' + tmpname = os.tmpname():gsub("\\", ""):gsub("%.", "") + tmpname = os.environ("TMP", "") .. "\\zlua_" .. tmpname .. ".txt" cmd = 'type "' .. tmpname .. '" | ' .. cmd end PRINT_MODE = tmpname @@ -1627,16 +1646,16 @@ function z_cd(patterns) retval = os.call(cmd) -- io.stderr:write('<'..cmd..'>\n') os.remove(tmpname) - if retval == '' or retval == nil then + if retval == "" or retval == nil then return nil end - local pos = retval:find(' ') + local pos = retval:find(" ") if not pos then return nil end - retval = retval:sub(pos, -1):gsub('^%s*', '') + retval = retval:sub(pos, -1):gsub("^%s*", "") end - return (retval ~= '' and retval or nil) + return (retval ~= "" and retval or nil) end ----------------------------------------------------------------------- @@ -1658,9 +1677,9 @@ end -- find_vcs_root ----------------------------------------------------------------------- function find_vcs_root(path) - local markers = os.getenv('_ZL_ROOT_MARKERS') - local markers = markers and markers or '.git,.svn,.hg,.root' - local markers = string.split(markers, ',') + local markers = os.getenv("_ZL_ROOT_MARKERS") + local markers = markers and markers or ".git,.svn,.hg,.root" + local markers = string.split(markers, ",") path = os.path.absolute(path) while true do for _, marker in ipairs(markers) do @@ -1670,7 +1689,9 @@ function find_vcs_root(path) end end local parent, _ = os.path.split(path) - if path == parent then break end + if path == parent then + break + end path = parent end return nil @@ -1688,50 +1709,50 @@ function cd_backward(args, options, pwd) if nargs == 0 then return find_vcs_root(pwd) elseif nargs == 1 then - if args[1]:sub(1, 2) == '..' then + if args[1]:sub(1, 2) == ".." then local size = args[1]:len() - 1 - if args[1]:match('^%.%.+$') then + if args[1]:match("^%.%.+$") then size = args[1]:len() - 1 - elseif args[1]:match('^%.%.%d+$') then + elseif args[1]:match("^%.%.%d+$") then size = tonumber(args[1]:sub(3)) else return nil end local path = pwd for index = 1, size do - path = os.path.join(path, '..') + path = os.path.join(path, "..") end return os.path.normpath(path) else pwd = os.path.split(pwd) - local test = windows and pwd:gsub('\\', '/') or pwd + local test = windows and pwd:gsub("\\", "/") or pwd local key = windows and args[1]:lower() or args[1] - if not key:match('%u') then + if not key:match("%u") then test = test:lower() end - local pos, ends = test:rfind('/' .. key) + local pos, ends = test:rfind("/" .. key) if pos then - ends = test:find('/', pos + key:len() + 1, true) + ends = test:find("/", pos + key:len() + 1, true) ends = ends and ends or test:len() return os.path.normpath(pwd:sub(1, ends)) elseif windows and test:startswith(key) then - ends = test:find('/', key:len(), true) + ends = test:find("/", key:len(), true) ends = ends and ends or test:len() return os.path.normpath(pwd:sub(1, ends)) end pos = test:rfind(key) if pos then - ends = test:find('/', pos + key:len(), true) + ends = test:find("/", pos + key:len(), true) ends = ends and ends or test:len() return os.path.normpath(pwd:sub(1, ends)) end return nil end else - local test = windows and pwd:gsub('\\', '/') or pwd + local test = windows and pwd:gsub("\\", "/") or pwd local src = args[1] local dst = args[2] - if not src:match('%u') then + if not src:match("%u") then test = test:lower() end local start, ends = test:rfind(src) @@ -1749,17 +1770,19 @@ end ----------------------------------------------------------------------- function cd_minus(args, options) Z_SKIPPWD = true - local M = z_match({}, 'time', Z_SUBDIR) + local M = z_match({}, "time", Z_SUBDIR) local size = #M - if options['-'] == '-' then + if options["-"] == "-" then for i, item in ipairs(M) do - if i > 10 then break end - io.stderr:write(' ' .. tostring(i - 1) .. ' ' .. item.name .. '\n') + if i > 10 then + break + end + io.stderr:write(" " .. tostring(i - 1) .. " " .. item.name .. "\n") end else local level = 0 - local num = options['-'] - if num and num ~= '' then + local num = options["-"] + if num and num ~= "" then level = tonumber(num) end if level >= 0 and level < size then @@ -1773,63 +1796,63 @@ end -- cd breadcrumbs: z -b -i, z -b -I ----------------------------------------------------------------------- function cd_breadcrumbs(pwd, interactive) - local pwd = (pwd == nil or pwd == '') and os.pwd() or pwd + local pwd = (pwd == nil or pwd == "") and os.pwd() or pwd local pwd = os.path.normpath(pwd) local path, _ = os.path.split(pwd) local elements = {} local interactive = interactive and interactive or 1 - local fullname = os.environ('_ZL_FULL_PATH', false) + local fullname = os.environ("_ZL_FULL_PATH", false) while true do local head, name = os.path.split(path) if head == path then -- reached root table.insert(elements, { head, head }) break - elseif name ~= '' then + elseif name ~= "" then table.insert(elements, { name, path }) else break end path = head end - local tmpname = '/tmp/zlua.txt' + local tmpname = "/tmp/zlua.txt" local fp = io.stderr if interactive == 2 then if not windows then tmpname = os.tmpname() else - tmpname = os.tmpname():gsub('\\', ''):gsub('%.', '') - tmpname = os.environ('TMP', '') .. '\\zlua_' .. tmpname .. '.txt' + tmpname = os.tmpname():gsub("\\", ""):gsub("%.", "") + tmpname = os.environ("TMP", "") .. "\\zlua_" .. tmpname .. ".txt" end - fp = io.open(tmpname, 'w') + fp = io.open(tmpname, "w") end -- print table local maxsize = string.len(tostring(#elements)) for i = #elements, 1, -1 do local item = elements[i] local name = item[1] - local text = string.rep(' ', maxsize - string.len(i)) .. tostring(i) - text = text .. ': ' .. (fullname and item[2] or item[1]) - fp:write(text .. '\n') + local text = string.rep(" ", maxsize - string.len(i)) .. tostring(i) + text = text .. ": " .. (fullname and item[2] or item[1]) + fp:write(text .. "\n") end if fp ~= io.stderr then fp:close() end - local retval = '' + local retval = "" -- select from stdin or fzf if interactive == 1 then - io.stderr:write('> ') + io.stderr:write("> ") io.stderr:flush() - retval = io.read('*l') + retval = io.read("*l") elseif interactive == 2 then - local fzf = os.environ('_ZL_FZF', 'fzf') - local cmd = '--reverse --inline-info --tac ' - local flag = os.environ('_ZL_FZF_FLAG', '') - flag = (flag == '' or flag == nil) and '+s -e' or flag - cmd = ((fzf == '') and 'fzf' or fzf) .. ' ' .. cmd .. ' ' .. flag + local fzf = os.environ("_ZL_FZF", "fzf") + local cmd = "--reverse --inline-info --tac " + local flag = os.environ("_ZL_FZF_FLAG", "") + flag = (flag == "" or flag == nil) and "+s -e" or flag + cmd = ((fzf == "") and "fzf" or fzf) .. " " .. cmd .. " " .. flag if not windows then - local height = os.environ('_ZL_FZF_HEIGHT', '35%') - if height ~= nil and height ~= '' and height ~= '0' then - cmd = cmd .. ' --height ' .. height + local height = os.environ("_ZL_FZF_HEIGHT", "35%") + if height ~= nil and height ~= "" and height ~= "0" then + cmd = cmd .. " --height " .. height end cmd = cmd .. '< "' .. tmpname .. '"' else @@ -1837,14 +1860,14 @@ function cd_breadcrumbs(pwd, interactive) end retval = os.call(cmd) os.remove(tmpname) - if retval == '' or retval == nil then + if retval == "" or retval == nil then return nil end - local pos = retval:find(':') + local pos = retval:find(":") if not pos then return nil end - retval = retval:sub(1, pos - 1):gsub('^%s*', '') + retval = retval:sub(1, pos - 1):gsub("^%s*", "") end local index = tonumber(retval) if index == nil or index < 1 or index > #elements then @@ -1862,37 +1885,37 @@ function main(argv) if options == nil then return false elseif table.length(args) == 0 and table.length(options) == 0 then - print(os.argv[0] .. ': missing arguments') - help = os.argv[-1] .. ' ' .. os.argv[0] .. ' --help' - print('Try \'' .. help .. '\' for more information') + print(os.argv[0] .. ": missing arguments") + help = os.argv[-1] .. " " .. os.argv[0] .. " --help" + print("Try '" .. help .. "' for more information") return false end if true then os.log("options: " .. dump(options)) os.log("args: " .. dump(args)) end - if options['-c'] then + if options["-c"] then Z_SUBDIR = true end - if options['-r'] then - Z_METHOD = 'rank' - elseif options['-t'] then - Z_METHOD = 'time' + if options["-r"] then + Z_METHOD = "rank" + elseif options["-t"] then + Z_METHOD = "time" end - if options['-i'] then + if options["-i"] then Z_INTERACTIVE = 1 - elseif options['-I'] then + elseif options["-I"] then Z_INTERACTIVE = 2 end - if options['--cd'] or options['-e'] then - local path = '' - if options['-b'] then + if options["--cd"] or options["-e"] then + local path = "" + if options["-b"] then if Z_INTERACTIVE == 0 then path = cd_backward(args, options) else - path = cd_breadcrumbs('', Z_INTERACTIVE) + path = cd_breadcrumbs("", Z_INTERACTIVE) end - elseif options['-'] then + elseif options["-"] then path = cd_minus(args, options) elseif #args == 0 then path = nil @@ -1907,19 +1930,19 @@ function main(argv) end end if path ~= nil then - io.write(path .. (options['-e'] and "\n" or "")) + io.write(path .. (options["-e"] and "\n" or "")) end - elseif options['--add'] then + elseif options["--add"] then -- print('data: ' .. DATA_FILE) z_add(args) - elseif options['-x'] then + elseif options["-x"] then z_remove(args) - elseif options['--purge'] then + elseif options["--purge"] then local src, dst = z_purge() local fp = io.stderr - fp:write('purge: ' .. tostring(src) .. ' record(s) remaining, ') - fp:write(tostring(src - dst) .. ' invalid record(s) removed.\n') - elseif options['--init'] then + fp:write("purge: " .. tostring(src) .. " record(s) remaining, ") + fp:write(tostring(src - dst) .. " invalid record(s) removed.\n") + elseif options["--init"] then local opts = {} for _, key in ipairs(args) do opts[key] = 1 @@ -1933,21 +1956,21 @@ function main(argv) else z_shell_init(opts) end - elseif options['-l'] then + elseif options["-l"] then local M = z_match(args and args or {}, Z_METHOD, Z_SUBDIR) - if options['-s'] then + if options["-s"] then z_print(M, false, false) else z_print(M, true, false) end - elseif options['--complete'] then - local line = args[1] and args[1] or '' - local head = line:sub(Z_CMD:len() + 1):gsub('^%s+', '') + elseif options["--complete"] then + local line = args[1] and args[1] or "" + local head = line:sub(Z_CMD:len() + 1):gsub("^%s+", "") local M = z_match({ head }, Z_METHOD, Z_SUBDIR) for _, item in pairs(M) do print(item.name) end - elseif options['--help'] or options['-h'] then + elseif options["--help"] or options["-h"] then z_help() end return true @@ -1957,20 +1980,20 @@ end -- initialize from environment variable ----------------------------------------------------------------------- function z_init() - local _zl_data = os.getenv('_ZL_DATA') - local _zl_maxage = os.getenv('_ZL_MAXAGE') - local _zl_exclude = os.getenv('_ZL_EXCLUDE_DIRS') - local _zl_cmd = os.getenv('_ZL_CMD') - local _zl_matchname = os.getenv('_ZL_MATCH_NAME') - local _zl_skippwd = os.getenv('_ZL_SKIP_PWD') - local _zl_matchmode = os.getenv('_ZL_MATCH_MODE') - local _zl_hyphen = os.getenv('_ZL_HYPHEN') + local _zl_data = os.getenv("_ZL_DATA") + local _zl_maxage = os.getenv("_ZL_MAXAGE") + local _zl_exclude = os.getenv("_ZL_EXCLUDE_DIRS") + local _zl_cmd = os.getenv("_ZL_CMD") + local _zl_matchname = os.getenv("_ZL_MATCH_NAME") + local _zl_skippwd = os.getenv("_ZL_SKIP_PWD") + local _zl_matchmode = os.getenv("_ZL_MATCH_MODE") + local _zl_hyphen = os.getenv("_ZL_HYPHEN") if _zl_data ~= nil and _zl_data ~= "" then if windows then DATA_FILE = _zl_data else -- avoid windows environments affect cygwin & msys - if not string.match(_zl_data, '^%a:[/\\]') then + if not string.match(_zl_data, "^%a:[/\\]") then DATA_FILE = _zl_data end end @@ -1982,7 +2005,7 @@ function z_init() end end if _zl_exclude ~= nil and _zl_exclude ~= "" then - local part = _zl_exclude:split(',') + local part = _zl_exclude:split(",") local insensitive = path_case_insensitive() for _, name in ipairs(part) do if insensitive then @@ -1994,32 +2017,32 @@ function z_init() table.insert(Z_EXCLUDE, name) end end - if _zl_cmd ~= nil and _zl_cmd ~= '' then + if _zl_cmd ~= nil and _zl_cmd ~= "" then Z_CMD = _zl_cmd end if _zl_matchname ~= nil then local m = string.lower(_zl_matchname) - if (m == '1' or m == 'yes' or m == 'true' or m == 't') then + if m == "1" or m == "yes" or m == "true" or m == "t" then Z_MATCHNAME = true end end if _zl_skippwd ~= nil then local m = string.lower(_zl_skippwd) - if (m == '1' or m == 'yes' or m == 'true' or m == 't') then + if m == "1" or m == "yes" or m == "true" or m == "t" then Z_SKIPPWD = true end end if _zl_matchmode ~= nil then local m = tonumber(_zl_matchmode) Z_MATCHMODE = m - if (m == 1) then + if m == 1 then Z_MATCHNAME = true Z_SKIPPWD = true end end if _zl_hyphen ~= nil then local m = string.lower(_zl_hyphen) - if (m == '1' or m == 'yes' or m == 'true' or m == 't') then + if m == "1" or m == "yes" or m == "true" or m == "t" then Z_HYPHEN = true end end @@ -2030,8 +2053,8 @@ end ----------------------------------------------------------------------- function z_clink_init() local once = os.environ("_ZL_ADD_ONCE", false) - local _zl_clink_prompt_priority = os.environ('_ZL_CLINK_PROMPT_PRIORITY', 99) - local previous = '' + local _zl_clink_prompt_priority = os.environ("_ZL_CLINK_PROMPT_PRIORITY", 99) + local previous = "" function z_add_to_database() pwd = clink.get_cwd() if once then @@ -2054,8 +2077,23 @@ function z_clink_init() local z_parser = clink.arg.new_parser() z_parser:set_arguments({ z_match_completion }) - z_parser:set_flags("-c", "-r", "-i", "--cd", "-e", "-b", "--add", "-x", "--purge", - "--init", "-l", "-s", "--complete", "--help", "-h") + z_parser:set_flags( + "-c", + "-r", + "-i", + "--cd", + "-e", + "-b", + "--add", + "-x", + "--purge", + "--init", + "-l", + "-s", + "--complete", + "--help", + "-h" + ) clink.arg.register_parser("z", z_parser) end @@ -2215,21 +2253,20 @@ if [ "${+functions[compdef]}" -ne 0 ]; then fi ]] - ----------------------------------------------------------------------- -- initialize bash/zsh ---------------------------------------------------------------------- function z_shell_init(opts) print('ZLUA_SCRIPT="' .. os.scriptname() .. '"') print('ZLUA_LUAEXE="' .. os.interpreter() .. '"') - print('') + print("") if not opts.posix then print(script_zlua) elseif not opts.legacy then - local script = script_zlua:gsub('builtin ', '') + local script = script_zlua:gsub("builtin ", "") print(script) else - local script = script_zlua:gsub('local ', ''):gsub('builtin ', '') + local script = script_zlua:gsub("local ", ""):gsub("builtin ", "") print(script) end @@ -2253,13 +2290,13 @@ function z_shell_init(opts) print(script_complete_bash) if opts.fzf ~= nil then fzf_cmd = "fzf --nth 2.. --reverse --inline-info --tac " - local height = os.environ('_ZL_FZF_HEIGHT', '35%') - if height ~= nil and height ~= '' and height ~= '0' then - fzf_cmd = fzf_cmd .. ' --height ' .. height .. ' ' + local height = os.environ("_ZL_FZF_HEIGHT", "35%") + if height ~= nil and height ~= "" and height ~= "0" then + fzf_cmd = fzf_cmd .. " --height " .. height .. " " end - local flag = os.environ('_ZL_FZF_FLAG', '') - flag = (flag == '' or flag == nil) and '+s -e' or flag - fzf_cmd = fzf_cmd .. ' ' .. flag .. ' ' + local flag = os.environ("_ZL_FZF_FLAG", "") + flag = (flag == "" or flag == nil) and "+s -e" or flag + fzf_cmd = fzf_cmd .. " " .. flag .. " " print('zlua_fzf="' .. fzf_cmd .. '"') print(script_fzf_complete_bash) end @@ -2271,9 +2308,11 @@ function z_shell_init(opts) elseif opts.posix ~= nil then if prompt_hook then local script = script_init_posix - if once then script = script_init_posix_once end + if once then + script = script_init_posix_once + end if opts.legacy then - script = script:gsub('%&%)', ')') + script = script:gsub("%&%)", ")") end print(script) end @@ -2291,20 +2330,20 @@ function z_shell_init(opts) print('elif [ -n "$ZSH_VERSION" ]; then') print(once and script_init_zsh_once or script_init_zsh) -- print(script_complete_zsh) - print('else') + print("else") print(once and script_init_posix_once or script_init_posix) print('builtin() { cd "$2"; }') - print('fi') + print("fi") end end if opts.enhanced ~= nil then - print('export _ZL_MATCH_MODE=1') + print("export _ZL_MATCH_MODE=1") end if opts.nc then - print('export _ZL_NO_CHECK=1') + print("export _ZL_NO_CHECK=1") end if opts.echo then - print('_ZL_ECHO=1') + print("_ZL_ECHO=1") end end @@ -2403,7 +2442,6 @@ complete -c $_ZL_CMD -s 'b' -d 'jump backwards to given dir or to project root' complete -c $_ZL_CMD -s 'x' -x -d 'remove path from history' -a '(_z_complete)' ]] - function z_fish_init(opts) print('set -x ZLUA_SCRIPT "' .. os.scriptname() .. '"') print('set -x ZLUA_LUAEXE "' .. os.interpreter() .. '"') @@ -2422,13 +2460,13 @@ function z_fish_init(opts) end print(script_complete_fish) if opts.enhanced ~= nil then - print('set -x _ZL_MATCH_MODE 1') + print("set -x _ZL_MATCH_MODE 1") end if opts.echo then - print('set -g _ZL_ECHO 1') + print("set -g _ZL_ECHO 1") end if opts.nc then - print('set -x _ZL_NO_CHECK 1') + print("set -x _ZL_NO_CHECK 1") end end @@ -2537,7 +2575,6 @@ endlocal & popd & %CDCmd% "%NewPath%" :end ]] - ----------------------------------------------------------------------- -- powershell ----------------------------------------------------------------------- @@ -2617,7 +2654,6 @@ if (!$env:_ZL_NO_PROMPT_COMMAND -and (!$global:_zlua_inited)) { } ]] - ----------------------------------------------------------------------- -- initialize cmd/powershell ----------------------------------------------------------------------- @@ -2631,28 +2667,28 @@ function z_windows_init(opts) print('$script:ZLUA_SCRIPT = "' .. os.scriptname() .. '"') print(script_zlua_powershell) if opts.enhanced ~= nil then - print('$env:_ZL_MATCH_MODE = 1') + print("$env:_ZL_MATCH_MODE = 1") end if opts.once ~= nil then - print('$env:_ZL_ADD_ONCE = 1') + print("$env:_ZL_ADD_ONCE = 1") end if opts.echo ~= nil then - print('$env:_ZL_ECHO = 1') + print("$env:_ZL_ECHO = 1") end if opts.nc ~= nil then - print('$env:_ZL_NO_CHECK = 1') + print("$env:_ZL_NO_CHECK = 1") end if prompt_hook then print(script_init_powershell) end else - print('@echo off') - print('setlocal EnableDelayedExpansion') + print("@echo off") + print("setlocal EnableDelayedExpansion") print('set "LuaExe=' .. os.interpreter() .. '"') print('set "LuaScript=' .. os.scriptname() .. '"') print(script_init_cmd) if opts.newline then - print('echo.') + print("echo.") end end end @@ -2661,30 +2697,30 @@ end -- help ----------------------------------------------------------------------- function z_help() - local cmd = Z_CMD .. ' ' - print(cmd .. 'foo # cd to most frecent dir matching foo') - print(cmd .. 'foo bar # cd to most frecent dir matching foo and bar') - print(cmd .. '-r foo # cd to highest ranked dir matching foo') - print(cmd .. '-t foo # cd to most recently accessed dir matching foo') - print(cmd .. '-l foo # list matches instead of cd') - print(cmd .. '-c foo # restrict matches to subdirs of $PWD') - print(cmd .. '-e foo # echo the best match, don\'t cd') - print(cmd .. '-x path # remove path from history') - print(cmd .. '-i foo # cd with interactive selection') - print(cmd .. '-I foo # cd with interactive selection using fzf') - print(cmd .. '-b foo # cd to the parent directory starting with foo') + local cmd = Z_CMD .. " " + print(cmd .. "foo # cd to most frecent dir matching foo") + print(cmd .. "foo bar # cd to most frecent dir matching foo and bar") + print(cmd .. "-r foo # cd to highest ranked dir matching foo") + print(cmd .. "-t foo # cd to most recently accessed dir matching foo") + print(cmd .. "-l foo # list matches instead of cd") + print(cmd .. "-c foo # restrict matches to subdirs of $PWD") + print(cmd .. "-e foo # echo the best match, don't cd") + print(cmd .. "-x path # remove path from history") + print(cmd .. "-i foo # cd with interactive selection") + print(cmd .. "-I foo # cd with interactive selection using fzf") + print(cmd .. "-b foo # cd to the parent directory starting with foo") end ----------------------------------------------------------------------- -- LFS optimize ----------------------------------------------------------------------- os.lfs = {} -os.lfs.enable = os.getenv('_ZL_USE_LFS') -os.lfs.enable = '1' +os.lfs.enable = os.getenv("_ZL_USE_LFS") +os.lfs.enable = "1" if os.lfs.enable ~= nil then local m = string.lower(os.lfs.enable) - if (m == '1' or m == 'yes' or m == 'true' or m == 't') then - os.lfs.status, os.lfs.pkg = pcall(require, 'lfs') + if m == "1" or m == "yes" or m == "true" or m == "t" then + os.lfs.status, os.lfs.pkg = pcall(require, "lfs") if os.lfs.status then local lfs = os.lfs.pkg os.path.exists = function(name) @@ -2695,20 +2731,19 @@ if os.lfs.enable ~= nil then if not mode then return false end - return (mode.mode == 'directory') and true or false + return (mode.mode == "directory") and true or false end end end end - ----------------------------------------------------------------------- -- program entry ----------------------------------------------------------------------- if not pcall(debug.getlocal, 4, 1) then -- main script z_init() - if windows and type(clink) == 'table' and clink.prompt ~= nil then + if windows and type(clink) == "table" and clink.prompt ~= nil then z_clink_init() else main() diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index 32d83f08..191c76a2 100644 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -52,15 +52,15 @@ export KEYTIMEOUT=1 # Change cursor shape for different vi modes. function zle-keymap-select { - case $KEYMAP in - vicmd) echo -ne '\e[1 q' ;; # block - viins | main) echo -ne '\e[5 q' ;; # beam - esac + case $KEYMAP in + vicmd) echo -ne '\e[1 q' ;; # block + viins | main) echo -ne '\e[5 q' ;; # beam + esac } zle -N zle-keymap-select zle-line-init() { - zle -K viins # initiate `vi insert` as keymap (can be removed if `bindkey -V` has been set elsewhere) - echo -ne '\e[5 q' + zle -K viins # initiate `vi insert` as keymap (can be removed if `bindkey -V` has been set elsewhere) + echo -ne '\e[5 q' } zle -N zle-line-init echo -ne '\e[5 q' # Use beam shape cursor on startup. @@ -68,22 +68,22 @@ preexec() { echo -ne '\e[5 q'; } # Use beam shape cursor for each new prompt. # Run exa on directory change function cd() { - new_directory="$*" - if [ $# -eq 0 ]; then - new_directory=${HOME} - fi - builtin cd "${new_directory}" && exa -a --icons --group-directories-first + new_directory="$*" + if [ $# -eq 0 ]; then + new_directory=${HOME} + fi + builtin cd "${new_directory}" && exa -a --icons --group-directories-first } # Use lf to switch directories and bind it to ctrl-o function lfcd() { - tmp="$(mktemp)" - lfrun -last-dir-path="$tmp" "$@" - if [ -f "$tmp" ]; then - dir="$(bat "$tmp")" - rm -f "$tmp" >/dev/null - [ -d "$dir" ] && [ "$dir" != "$(pwd)" ] && cd "$dir" - fi + tmp="$(mktemp)" + lfrun -last-dir-path="$tmp" "$@" + if [ -f "$tmp" ]; then + dir="$(bat "$tmp")" + rm -f "$tmp" >/dev/null + [ -d "$dir" ] && [ "$dir" != "$(pwd)" ] && cd "$dir" + fi } # Navigate words with CTRL+ARROW keys diff --git a/.gitignore b/.gitignore index 8b137891..9bbbeeaf 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ - +.luarc.json