wifi script
This commit is contained in:
parent
7694058b9d
commit
f7d2e0d114
2 changed files with 37 additions and 23 deletions
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
-- Set <space> as the leader key
|
-- Set <space> as the leader key
|
||||||
-- See `:help mapleader`
|
-- See `:help mapleader`
|
||||||
-- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used)
|
-- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used)
|
||||||
|
@ -76,20 +75,19 @@ vim.opt.scrolloff = 10
|
||||||
-- quickfix to search and replace
|
-- quickfix to search and replace
|
||||||
vim.api.nvim_create_user_command('SearchAndReplace', function()
|
vim.api.nvim_create_user_command('SearchAndReplace', function()
|
||||||
-- Prompt for the first string (the one to replace)
|
-- Prompt for the first string (the one to replace)
|
||||||
local stringOne = vim.fn.input('Enter the string to replace: ')
|
local stringOne = vim.fn.input 'Enter the string to replace: '
|
||||||
-- Prompt for the second string (the replacement)
|
-- Prompt for the second string (the replacement)
|
||||||
local stringTwo = vim.fn.input('Enter the replacement string: ')
|
local stringTwo = vim.fn.input 'Enter the replacement string: '
|
||||||
|
|
||||||
-- Perform the search and replace in the quickfix list
|
-- Perform the search and replace in the quickfix list
|
||||||
vim.cmd('cfdo %s/' .. stringOne .. '/' .. stringTwo .. '/g | update')
|
vim.cmd('cfdo %s/' .. stringOne .. '/' .. stringTwo .. '/g | update')
|
||||||
|
|
||||||
-- Optionally close the buffers
|
-- Optionally close the buffers
|
||||||
vim.cmd('bd')
|
vim.cmd 'bd'
|
||||||
end, {})
|
end, {})
|
||||||
|
|
||||||
-- Map <leader>R to the LadderR command
|
-- Map <leader>R to the LadderR command
|
||||||
vim.api.nvim_set_keymap('n', '<leader>R', ':SearchAndReplace<CR>', { noremap = true, silent = true, desc = 'Search And [R]eplace'})
|
vim.api.nvim_set_keymap('n', '<leader>R', ':SearchAndReplace<CR>', { noremap = true, silent = true, desc = 'Search And [R]eplace' })
|
||||||
|
|
||||||
|
|
||||||
-- [[ Basic Keymaps ]]
|
-- [[ Basic Keymaps ]]
|
||||||
-- See `:help vim.keymap.set()`
|
-- See `:help vim.keymap.set()`
|
||||||
|
@ -204,7 +202,7 @@ require('lazy').setup({
|
||||||
-- after the plugin has been loaded:
|
-- after the plugin has been loaded:
|
||||||
-- config = function() ... end
|
-- config = function() ... end
|
||||||
|
|
||||||
{ -- Useful plugin to show you pending keybinds.
|
{ -- Useful plugin to show you pending keybinds.
|
||||||
'folke/which-key.nvim',
|
'folke/which-key.nvim',
|
||||||
event = 'VimEnter', -- Sets the loading event to 'VimEnter'
|
event = 'VimEnter', -- Sets the loading event to 'VimEnter'
|
||||||
opts = {
|
opts = {
|
||||||
|
@ -247,7 +245,7 @@ require('lazy').setup({
|
||||||
|
|
||||||
-- Document existing key chains
|
-- Document existing key chains
|
||||||
spec = {
|
spec = {
|
||||||
{ '<leader>c', group = '[C]ode', mode = { 'n', 'x' } },
|
{ '<leader>c', group = '[C]ode', mode = { 'n', 'x' } },
|
||||||
{ '<leader>d', group = '[D]ocument' },
|
{ '<leader>d', group = '[D]ocument' },
|
||||||
{ '<leader>r', group = '[R]ename' },
|
{ '<leader>r', group = '[R]ename' },
|
||||||
{ '<leader>s', group = '[S]earch' },
|
{ '<leader>s', group = '[S]earch' },
|
||||||
|
@ -287,7 +285,7 @@ require('lazy').setup({
|
||||||
{ 'nvim-telescope/telescope-ui-select.nvim' },
|
{ 'nvim-telescope/telescope-ui-select.nvim' },
|
||||||
|
|
||||||
-- Useful for getting pretty icons, but requires a Nerd Font.
|
-- Useful for getting pretty icons, but requires a Nerd Font.
|
||||||
{ 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font },
|
{ 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font },
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
-- Telescope is a fuzzy finder that comes with a lot of different things that
|
-- Telescope is a fuzzy finder that comes with a lot of different things that
|
||||||
|
@ -382,7 +380,7 @@ require('lazy').setup({
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ 'Bilal2453/luvit-meta', lazy = true },
|
{ 'Bilal2453/luvit-meta', lazy = true },
|
||||||
{
|
{
|
||||||
-- Main LSP Configuration
|
-- Main LSP Configuration
|
||||||
'neovim/nvim-lspconfig',
|
'neovim/nvim-lspconfig',
|
||||||
|
@ -394,7 +392,7 @@ require('lazy').setup({
|
||||||
|
|
||||||
-- Useful status updates for LSP.
|
-- Useful status updates for LSP.
|
||||||
-- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})`
|
-- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})`
|
||||||
{ 'j-hui/fidget.nvim', opts = {} },
|
{ 'j-hui/fidget.nvim', opts = {} },
|
||||||
|
|
||||||
-- Allows extra capabilities provided by nvim-cmp
|
-- Allows extra capabilities provided by nvim-cmp
|
||||||
'hrsh7th/cmp-nvim-lsp',
|
'hrsh7th/cmp-nvim-lsp',
|
||||||
|
@ -574,7 +572,6 @@ require('lazy').setup({
|
||||||
-- You can press `g?` for help in this menu.
|
-- You can press `g?` for help in this menu.
|
||||||
require('mason').setup()
|
require('mason').setup()
|
||||||
|
|
||||||
|
|
||||||
-- You can add other tools here that you want Mason to install
|
-- You can add other tools here that you want Mason to install
|
||||||
-- for you, so that they are available from within Neovim.
|
-- for you, so that they are available from within Neovim.
|
||||||
local ensure_installed = vim.tbl_keys(servers or {})
|
local ensure_installed = vim.tbl_keys(servers or {})
|
||||||
|
@ -636,7 +633,7 @@ require('lazy').setup({
|
||||||
-- python = { "isort", "black" },
|
-- python = { "isort", "black" },
|
||||||
--
|
--
|
||||||
-- You can use 'stop_after_first' to run the first available formatter from the list
|
-- You can use 'stop_after_first' to run the first available formatter from the list
|
||||||
javascript = { "prettier", stop_after_first = true },
|
javascript = { 'prettier', stop_after_first = true },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -780,7 +777,6 @@ require('lazy').setup({
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
-- Highlight todo, notes, etc in comments
|
-- Highlight todo, notes, etc in comments
|
||||||
{ 'folke/todo-comments.nvim', event = 'VimEnter', dependencies = { 'nvim-lua/plenary.nvim' }, opts = { signs = false } },
|
{ 'folke/todo-comments.nvim', event = 'VimEnter', dependencies = { 'nvim-lua/plenary.nvim' }, opts = { signs = false } },
|
||||||
|
|
||||||
|
@ -856,16 +852,16 @@ require('lazy').setup({
|
||||||
-- Here are some example plugins that I've included in the Kickstart repository.
|
-- Here are some example plugins that I've included in the Kickstart repository.
|
||||||
-- Uncomment any of the lines below to enable them (you will need to restart nvim).
|
-- Uncomment any of the lines below to enable them (you will need to restart nvim).
|
||||||
--
|
--
|
||||||
require 'kickstart.plugins.debug',
|
require 'kickstart.plugins.debug',
|
||||||
-- require 'kickstart.plugins.indent_line',
|
-- require 'kickstart.plugins.indent_line',
|
||||||
-- require 'kickstart.plugins.lint',
|
-- require 'kickstart.plugins.lint',
|
||||||
require 'kickstart.plugins.autopairs',
|
require 'kickstart.plugins.autopairs',
|
||||||
require 'kickstart.plugins.neo-tree',
|
require 'kickstart.plugins.neo-tree',
|
||||||
require 'kickstart.plugins.gitsigns', -- adds gitsigns recommend keymaps
|
require 'kickstart.plugins.gitsigns', -- adds gitsigns recommend keymaps
|
||||||
|
|
||||||
-- My plugins
|
-- My plugins
|
||||||
require 'kickstart.plugins.bufferline',
|
require 'kickstart.plugins.bufferline',
|
||||||
-- require 'kickstart.plugins.bottomline'
|
-- require 'kickstart.plugins.bottomline'
|
||||||
|
|
||||||
-- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua`
|
-- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua`
|
||||||
-- This is the easiest way to modularize your config.
|
-- This is the easiest way to modularize your config.
|
||||||
|
|
|
@ -78,6 +78,8 @@ forget_network() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to connect to a network
|
||||||
|
|
||||||
# Function to connect to a network
|
# Function to connect to a network
|
||||||
connect_to_network() {
|
connect_to_network() {
|
||||||
while true; do
|
while true; do
|
||||||
|
@ -113,6 +115,21 @@ connect_to_network() {
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Check if there's an existing connection profile for this network
|
||||||
|
if nmcli connection show | grep -q "$chosen_network"; then
|
||||||
|
# Try to connect using the saved profile
|
||||||
|
nmcli connection up "$chosen_network"
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
# Connection successful
|
||||||
|
notify-send "Connected to $chosen_network using saved profile."
|
||||||
|
break
|
||||||
|
else
|
||||||
|
# If connection fails, delete the saved profile and prompt for a new password
|
||||||
|
nmcli connection delete "$chosen_network"
|
||||||
|
notify-send "Failed to connect with saved password. Enter a new password."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Check if the network is secured
|
# Check if the network is secured
|
||||||
security_check=$(nmcli -t -f SSID,SECURITY dev wifi | grep "$chosen_network" | awk -F':' '{print $2}')
|
security_check=$(nmcli -t -f SSID,SECURITY dev wifi | grep "$chosen_network" | awk -F':' '{print $2}')
|
||||||
|
|
||||||
|
@ -133,6 +150,7 @@ connect_to_network() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Main menu function
|
# Main menu function
|
||||||
main_menu() {
|
main_menu() {
|
||||||
network_info=$(get_network_info)
|
network_info=$(get_network_info)
|
||||||
|
|
Loading…
Reference in a new issue