From 3055ce0516322829f258105f38839adf50bf6e98 Mon Sep 17 00:00:00 2001 From: Solomon Laing Date: Fri, 26 Mar 2021 22:24:53 +0000 Subject: [PATCH] added bitwarden support --- .scripts/bw-unlock | 22 +++++++ .scripts/passwords | 40 +++++++++++++ .xmonad/xmonad.hs | 139 +++++++++++++++++++++++++-------------------- 3 files changed, 139 insertions(+), 62 deletions(-) create mode 100755 .scripts/bw-unlock create mode 100755 .scripts/passwords diff --git a/.scripts/bw-unlock b/.scripts/bw-unlock new file mode 100755 index 0000000..bae7379 --- /dev/null +++ b/.scripts/bw-unlock @@ -0,0 +1,22 @@ +#!/bin/bash + +## +# Depends: zenity +# +# Generates bw session key and saves it in tmp file where only current user has permissions +# +# By Solomon Laing (solomonlaing@pm.me) +# Date 2020-03-26 +## + +password=$(zenity --password) + +session=$(bw unlock "$password" | awk 'NF{last=$NF} END{print last}') + +loc="/tmp/bw-session" + +touch $loc -f + +chmod 600 $loc + +echo "$session" > /tmp/bw-session \ No newline at end of file diff --git a/.scripts/passwords b/.scripts/passwords new file mode 100755 index 0000000..db9ce8f --- /dev/null +++ b/.scripts/passwords @@ -0,0 +1,40 @@ +#!/bin/bash + +## +# Depends bw (bitwarden-cli), bw-unlock (personal script), xclip +# +# Processes bw to allow for searching of passwords by website (and if multple logins per website, by account). +# +# By Solomon Laing (solomonlaing@pm.me) +# Date 2020-03-26 +## + +# get bw-session, will only work if owned by current user +if ! session=$(cat /tmp/bw-session) +then + /home/solomon/.scripts/bw-unlock + session=$(cat /tmp/bw-session) +fi + +items=$(bw list items --session "$session") +options=$(echo "$items" | jq ".[].name" | sed 's/"//g') + +entry=$(echo "$options" | dmenu -i -p "Which entry?" $1) + +if ! password=$(bw get password "$entry" --session "$session") +then + + user_options=$(bw list items --search "$entry" --session "$session") + + # does not return array, not sure why yet + # user_options=$(echo "$items" | jq '.[] | select(.name == "'"$entry"'") | .') + + user=$(echo "$user_options" | jq '.[].login.username' | dmenu -i -p "Which account?" $1 | sed 's/"//g') + + pass=$(echo "$user_options" | jq '.[] | select(.login.username == "'"$user"'") | .login.password' | sed 's/"//g') + + echo "$pass" | xclip -sel clip + +else + echo "$password" | xclip -sel clip +fi diff --git a/.xmonad/xmonad.hs b/.xmonad/xmonad.hs index 43a782c..25af41d 100644 --- a/.xmonad/xmonad.hs +++ b/.xmonad/xmonad.hs @@ -136,97 +136,112 @@ clickable ws = ""++ws++"" ------------------------------------------------------------------------ -- Key bindings. Add, modify or remove key bindings here. +-- These are general keybindings custom script bindings are not included. myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $ - -- launch a terminal - [ ((modm .|. shiftMask, xK_Return), spawn $ XMonad.terminal conf) + [ + -- launch a terminal + ((modm .|. shiftMask, xK_Return), spawn $ XMonad.terminal conf) - -- launch rofi - , ((modm, xK_a ), spawn "rofi -show run") + -- launch rofi + , ((modm, xK_a ), spawn "rofi -show run") - -- launch dmenu - , ((modm, xK_o ), spawn "dmenu_run") + -- launch dmenu + , ((modm, xK_o ), spawn "dmenu_run") - -- prompt computer shutdown - , ((modm .|. shiftMask, xK_s ), spawn "/home/solomon/.scripts/prompt \"Are you sure you want to Shutdown?\" \"shutdown now\"") + -- launch rofi ssh + , ((modm .|. shiftMask, xK_a ), spawn "rofi -show ssh") - -- prompt computer reboot - , ((modm .|. shiftMask, xK_r ), spawn "/home/solomon/.scripts/prompt \"Are you sure you want to Restart?\" \"reboot\"") + -- launch my file manager + , ((modm, xK_l ), spawn myFileManager) - -- prompt computer lock - , ((modm .|. shiftMask, xK_l ), spawn "/home/solomon/.scripts/prompt \"Are you sure you want to lock?\" \"slock\"") + -- close focused window + , ((modm .|. shiftMask, xK_j ), kill) - -- launch rofi ssh - , ((modm .|. shiftMask, xK_a ), spawn "rofi -show ssh") + -- Rotate through the available layout algorithms + , ((modm, xK_space ), sendMessage NextLayout) - -- launch my file manager - , ((modm, xK_l ), spawn myFileManager) + -- Reset the layouts on the current workspace to default + , ((modm .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf) - -- close focused window - , ((modm .|. shiftMask, xK_j ), kill) + -- Resize viewed windows to the correct size + , ((modm, xK_b ), refresh) - -- Rotate through the available layout algorithms - , ((modm, xK_space ), sendMessage NextLayout) + -- Move focus to the next window + , ((modm, xK_Tab ), windows W.focusDown) - -- Reset the layouts on the current workspace to default - , ((modm .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf) + -- Move focus to the next window + , ((modm .|. shiftMask, xK_Tab ), windows W.focusUp) - -- Resize viewed windows to the correct size - , ((modm, xK_b ), refresh) + -- Move focus to the next window + , ((modm, xK_h ), windows W.focusDown) - -- Move focus to the next window - , ((modm, xK_Tab ), windows W.focusDown) + -- Move focus to the previous window + , ((modm, xK_t ), windows W.focusUp ) - -- Move focus to the next window - , ((modm .|. shiftMask, xK_Tab ), windows W.focusUp) + -- Move focus to the master window + , ((modm, xK_m ), windows W.focusMaster ) - -- Move focus to the next window - , ((modm, xK_h ), windows W.focusDown) + -- Swap the focused window and the master window + , ((modm, xK_Return), windows W.swapMaster) - -- Move focus to the previous window - , ((modm, xK_t ), windows W.focusUp ) + -- Swap the focused window with the next window + , ((modm .|. shiftMask, xK_Down ), windows W.swapDown ) - -- Move focus to the master window - , ((modm, xK_m ), windows W.focusMaster ) + -- Swap the focused window with the previous window + , ((modm .|. shiftMask, xK_Up ), windows W.swapUp ) - -- Swap the focused window and the master window - , ((modm, xK_Return), windows W.swapMaster) + -- Shrink the master area + , ((modm, xK_Left ), sendMessage Shrink) - -- Swap the focused window with the next window - , ((modm .|. shiftMask, xK_Down ), windows W.swapDown ) + -- Expand the master area + , ((modm, xK_Right ), sendMessage Expand) - -- Swap the focused window with the previous window - , ((modm .|. shiftMask, xK_Up ), windows W.swapUp ) + -- Push window back into tiling + , ((modm, xK_y ), withFocused $ windows . W.sink) - -- Shrink the master area - , ((modm, xK_Left ), sendMessage Shrink) + -- Increment the number of windows in the master area + , ((modm , xK_w ), sendMessage (IncMasterN 1)) - -- Expand the master area - , ((modm, xK_Right ), sendMessage Expand) + -- Deincrement the number of windows in the master area + , ((modm , xK_v), sendMessage (IncMasterN (-1))) - -- Push window back into tiling - , ((modm, xK_y ), withFocused $ windows . W.sink) + -- Toggle the status bar gap + -- Use this binding with avoidStruts from Hooks.ManageDocks. + -- See also the statusBar function from Hooks.DynamicLog. + -- + , ((modm , xK_b ), sendMessage ToggleStruts) - -- Increment the number of windows in the master area - , ((modm , xK_w ), sendMessage (IncMasterN 1)) + -- Quit xmonad + , ((modm .|. shiftMask, xK_apostrophe ), io (exitWith ExitSuccess)) - -- Deincrement the number of windows in the master area - , ((modm , xK_v), sendMessage (IncMasterN (-1))) + -- Restart xmonad + , ((modm , xK_apostrophe ), spawn "xmonad --recompile; xmonad --restart") + + -- Run xmessage with a summary of the default keybindings (useful for beginners) + , ((modm .|. shiftMask, xK_z ), spawn ("echo \"" ++ help ++ "\" | xmessage -file -")) + ] + ++ - -- Toggle the status bar gap - -- Use this binding with avoidStruts from Hooks.ManageDocks. - -- See also the statusBar function from Hooks.DynamicLog. -- - , ((modm , xK_b ), sendMessage ToggleStruts) + -- these are my general custom bindings and scripts + -- + [ + -- prompt computer shutdown + , ((modm .|. shiftMask, xK_s ), spawn "/home/solomon/.scripts/prompt \"Are you sure you want to Shutdown?\" \"shutdown now\"") - -- Quit xmonad - , ((modm .|. shiftMask, xK_apostrophe ), io (exitWith ExitSuccess)) + -- prompt computer reboot + , ((modm .|. shiftMask, xK_r ), spawn "/home/solomon/.scripts/prompt \"Are you sure you want to Restart?\" \"reboot\"") - -- Restart xmonad - , ((modm , xK_apostrophe ), spawn "xmonad --recompile; xmonad --restart") + -- prompt computer lock + , ((modm .|. shiftMask, xK_l ), spawn "/home/solomon/.scripts/prompt \"Are you sure you want to lock?\" \"slock\"") + + -- unlock bitwarden cli and store session key + , ((modm .|. shiftMask, xK_t ), spawn "/home/solomon/.scripts/bw-unlock") + + -- search for password using bitwarden cli through dmenu + , ((modm, xK_t ), spawn "/home/solomon/.scripts/passwords") - -- Run xmessage with a summary of the default keybindings (useful for beginners) - , ((modm .|. shiftMask, xK_z ), spawn ("echo \"" ++ help ++ "\" | xmessage -file -")) ] ++ @@ -267,8 +282,8 @@ myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $ -- increase backlight by 10 with mod+f9 ((modm, xK_F9), spawn "backlight_control +5") - -- decrese backlight by 10 with mod+f8x - ,((modm, xK_F8), spawn "backlight_control -5") + -- decrese backlight by 10 with mod+f8x + ,((modm, xK_F8), spawn "backlight_control -5") ] ++