Browse Source

various fixes and tweaks

DanielFGray 2 years ago
parent
commit
da32ec78e8
4 changed files with 38 additions and 71 deletions
  1. 18
    11
      ix
  2. 13
    51
      pkgsearch
  3. 3
    3
      sshget
  4. 4
    6
      wifi

+ 18
- 11
ix View File

@@ -4,7 +4,7 @@ declare -r esc=$'\033'
4 4
 declare -r c_reset="${esc}[0m"
5 5
 declare -r c_red="${esc}[31m"
6 6
 declare OPTIND
7
-declare opts=()
7
+declare opts=( -# )
8 8
 declare id
9 9
 
10 10
 usage() {
@@ -83,24 +83,31 @@ get_pastes() {
83 83
     grep -A1 -P '\<a href="\/[a-zA-Z0-9]+"\>' |
84 84
     awk -F'--' '
85 85
       BEGIN {FS="<a href=\""}
86
-      /a href/{sub(/\">\[r\]<\/a>/, "\t", $2); printf "http://ix.io" $2}
86
+      /a href/{ sub(/\">\[r\]<\/a>/, "\t", $2); printf "http://ix.io" $2 }
87 87
       /@/{sub(/^\s+/, "", $0); print}
88 88
     '
89 89
 }
90 90
 
91 91
 list_pastes() {
92 92
   local highlighter
93
-  highlighter=$(select_from 'highlight -q --force -O ansi' pygmentize)
94
-  get_pastes "$(get_user_name)" | fzf \
93
+  highlighter=$(select_from 'highlight -q --force -O ansi' pygmentize cat)
94
+  url=$(get_pastes "$(get_user_name)" | fzf \
95 95
     --inline-info --cycle \
96 96
     --header='Ctrl-E = edit; Ctrl-V = view; Ctrl-D = delete' \
97
-    --preview="p={}; curl -s \"\${p## *}\" | head -n\$LINES ${highlighter:+ | $highlighter}" \
97
+    --preview="curl -s '{1}' | ${highlighter}" \
98 98
     --bind 'space:jump' \
99
-    --bind 'j:down' --bind 'k:up' \
100 99
     --bind 'q:abort' \
101
-    --bind "Ctrl-V:execute:p={}; p=\"\${p## *}\"; less -R < <(curl -s \"\$p\" ${highlighter:+ | $highlighter}) > /dev/tty" \
102
-    --bind 'Ctrl-E:execute:p={}; p="${p## *}"; curl -s "$p" | vipe > /dev/tty | ix -i "${p##*/}"' \
103
-    --bind 'Ctrl-D:execute:p={}; p="${p## *}"; ix -d "${p##*/}"'
100
+    --bind "Ctrl-V:execute:less -R < <(curl -s '{1}' ${highlighter:+ | $highlighter}) > /dev/tty" \
101
+    --bind 'Ctrl-E:execute:p={1}; edit=$(curl -s "$p" | vipe); ix -i "${p##*/}" <<< "$edit"' \
102
+    --expect='Ctrl-D')
103
+  if [[ -n "$url" ]]; then
104
+    mapfile -t res <<< "$url"
105
+    if [[ "${res[0]}" = 'Ctrl-D' ]]; then
106
+      ix -d "${res[1]}"
107
+      list_pastes
108
+      exit
109
+    fi
110
+  fi
104 111
 }
105 112
 
106 113
 has -v curl || die
@@ -112,10 +119,10 @@ has_account || create_account
112 119
 while getopts ":hld:i:n:" x; do
113 120
   case "$x" in
114 121
     h) usage; exit ;;
115
-    d) curl "${opts[@]}" -X DELETE "ix.io/$OPTARG"; exit ;;
122
+    d) curl -s "${opts[@]}" -X DELETE "$OPTARG"; exit ;;
116 123
     l)
117 124
       if [[ -z "$OPTARG" && -e ~/.netrc ]]; then
118
-        list_pastes | awk '{print $2}' | tee /dev/tty | xclip
125
+        list_pastes | cut -d' ' -f1 | tee /dev/tty | xclip
119 126
       else
120 127
         die 'no netrc found'
121 128
       fi

+ 13
- 51
pkgsearch View File

@@ -5,10 +5,7 @@ declare -r c_reset="${esc}[0m"
5 5
 declare -r c_red="${esc}[31m"
6 6
 declare -r c_green="${esc}[32m"
7 7
 declare -r c_blue="${esc}[34m"
8
-declare -a config_err
9
-declare -r config_dir="${XDG_CONFIG_DIR:-$HOME/.config}/pkgsearch"
10
-declare -r config_file="${config_dir}/conf"
11
-declare reverse
8
+declare distro
12 9
 declare preview_pos='right:hidden'
13 10
 
14 11
 usage() {
@@ -16,12 +13,6 @@ usage() {
16 13
 pkgsearch [options] [query]
17 14
   lists and installs packages from your distro's repositories
18 15
 
19
-  -r --reverse    reverse the orientation of the layout
20
-  -p --preview    options for the preview window
21
-                  is passed directly to fzf --preview-window
22
-                  defaults to 'right:hidden'
23
-  -h --help       show this help
24
-
25 16
   without any arguments pkgsearch will list all available packages from your cache
26 17
   note: on Arch Linux you must pass a string to query the AUR
27 18
 HELP
@@ -70,33 +61,11 @@ select_from() {
70 61
 
71 62
 fzf() {
72 63
   command fzf -e +s --multi --cycle --ansi \
73
-    ${reverse:+--reverse} \
74 64
     --bind='Ctrl-X:toggle-preview' \
75
-    --preview-window="$preview_pos" \
76 65
     --no-hscroll --inline-info \
77 66
     --header='tab to select multiple packages, Ctrl-X for more info on a package' "$@"
78 67
 }
79 68
 
80
-parse_config_file() {
81
-  local line k v nr=0
82
-  config_err=()
83
-  while IFS= read -r line; do
84
-    (( ++nr ))
85
-    [[ -z "$line" || "$line" = '#'* ]] && continue
86
-    k="${line%% *}"
87
-    v="${line#* }"
88
-    if [[ -z "$v" ]]; then
89
-      config_err+=( "missing value for \"$k\" in config file on line $nr" )
90
-      continue
91
-    fi
92
-    case "$k" in
93
-      reverse) [[ "$v" = 'true' ]] && reverse="1" ;;
94
-      preview) preview_pos="$v" ;;
95
-      *) config_err+=( "unknown key \"$k\" in config file on line $nr" )
96
-    esac
97
-  done
98
-}
99
-
100 69
 install() {
101 70
   local pkgs count
102 71
   mapfile -t pkgs
@@ -108,9 +77,9 @@ install() {
108 77
 }
109 78
 
110 79
 debian() {
111
-  fzf --preview='p={}; apt-cache show ${p%% *}' \
80
+  fzf --preview='apt-cache show {1}' \
112 81
       --query="$1" \
113
-    < <(apt-cache search '' | sort |
82
+    < <(apt-cache search '.*' | sort |
114 83
       sed -u -r "s|^([^ ]+)|${c_green}\1${c_reset}|") |
115 84
     cut -d' ' -f1 |
116 85
     install "sudo $(select_from 'apt' 'aptitude' 'apt-get') install"
@@ -120,7 +89,7 @@ arch() {
120 89
   local search packages
121 90
   search='pacman'
122 91
   [[ -n "$1" ]] && search=$(select_from 'pacaur' 'yaourt' 'packer' 'apacman' 'pacman')
123
-  packages=$(fzf --preview="p=\$(cut -d' ' -f2 <<< {}); $search -Si \$p" \
92
+  packages=$(fzf --preview="$search -Si {2}" \
124 93
     < <( $search -Ss "$1" |
125 94
       gawk '{
126 95
         getline descr;
@@ -151,22 +120,10 @@ fedora() {
151 120
     install 'sudo dnf install'
152 121
 }
153 122
 
154
-[[ -s "$config_file" ]] && parse_config_file < "$config_file"
155
-
156 123
 while true; do
157 124
   case "$1" in
158
-    -r|--reverse)
159
-      reverse=1
160
-      shift
161
-      ;;
162
-    -h|--help)
163
-      usage
164
-      exit
165
-      ;;
166
-    -p|--preview)
167
-      preview_pos="$2"
168
-      shift 2
169
-      ;;
125
+    -h|--help) usage; exit ;;
126
+    -p|--preview) preview_pos="$2"; shift 2 ;;
170 127
     *) break
171 128
   esac
172 129
 done
@@ -174,8 +131,13 @@ done
174 131
 has -v fzf gawk || die
175 132
 
176 133
 request="$*"
177
-osrelease=$(awk -F'=' '"NAME" == $1 { gsub("\"", "", $2); print tolower($2); }' /etc/os-release)
178
-case "${osrelease%% *}" in
134
+
135
+if [[ -r /etc/os-release ]]; then
136
+  distro=$(awk -F'=' '"NAME" == $1 { gsub("\"", "", $2); print tolower($2); }' /etc/os-release)
137
+  distro="${distro%% *}"
138
+fi
139
+
140
+case "$distro" in
179 141
   debian|ubuntu) debian "$request" ;;
180 142
   arch) arch "$request" ;;
181 143
   void) void "$request" ;;

+ 3
- 3
sshget View File

@@ -25,7 +25,7 @@ HELP
25 25
 
26 26
 has() {
27 27
   local verbose=0
28
-  if [[ $1 == '-v' ]]; then
28
+  if [[ $1 = '-v' ]]; then
29 29
     verbose=1
30 30
     shift
31 31
   fi
@@ -63,10 +63,10 @@ for s in "${!domains[@]}"; do
63 63
   ssh "${domains[$s]}" "find ${paths[$s]}" | sed -r "s|^|${domains[$s]}:|" >> "$fifo" &
64 64
 done
65 65
 
66
-mapfile -t files < <( fzf -e --inline-info --multi --cycle < "$fifo" )
66
+mapfile -t files < <( fzf -e --inline-info --multi --cycle --bind='Ctrl-A:toggle-all,`:jump' < "$fifo" )
67 67
 
68 68
 if (( ${#files[@]} )); then
69
-  rsync -auvzP -e ssh "${files[@]}" .
69
+  rsync --protect-args -auvzP -e ssh "${files[@]}" .
70 70
 fi
71 71
 
72 72
 cleanup

+ 4
- 6
wifi View File

@@ -23,13 +23,11 @@ die() {
23 23
   exit 1
24 24
 }
25 25
 
26
-fzf() {
27
-  command fzf --ansi --inline-info "$@"
28
-}
29
-
30 26
 has -v nmcli fzf || die
31 27
 
32
-network=$(nmcli --color yes device wifi | fzf --nth=2 --header-lines=1 | sed -r 's/^\s*\*?\s*//; s/\s*(Ad-Hoc|Infra).*//')
28
+nmcli -d wifi rescan 2> /dev/null
29
+network=$(nmcli --color yes device wifi | fzf --ansi --height=40% --reverse --cycle --inline-info --header-lines=1)
33 30
 [[ -z "$network" ]] && exit
34
-
31
+network=$(sed -r 's/^\s*\*?\s*//; s/\s*(Ad-Hoc|Infra).*//' <<< "$network")
32
+echo "connecting to \"${network}\"..."
35 33
 nmcli -a device wifi connect "$network"

Loading…
Cancel
Save