Giter Club home page Giter Club logo

p-gen / smenu Goto Github PK

View Code? Open in Web Editor NEW
2.3K 42.0 49.0 9.07 MB

smenu started as a lightweight and flexible terminal menu generator, but quickly evolved into a powerful and versatile CLI selection tool for interactive or scripting use.

License: Mozilla Public License 2.0

Makefile 3.10% Shell 5.90% M4 0.17% C 79.01% Roff 8.55% Scilab 3.27%
terminal interactive selection console menus command-line-interface command-line cli tui shell

smenu's People

Contributors

cypriani avatar jonnydubowsky avatar p-gen avatar sumbach avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

smenu's Issues

configure searches for non-existent file

The configure script looks for build-aux/compile which does not exist. The build still completed successfully when removing the reference.

Line 2387: ac_aux_files="config.guess config.sub compile missing install-sh"

Version output is sent to STDERR instead of STDOUT

Using Cygwin:

$ smenu -V
Version: 0.9.12-eff1fe6
$ var=$(smenu -V)
$ echo "$var"

$ var=$(smenu -V 2>&1)
$ echo "$var"
Version: 0.9.12-eff1fe6
$ smenu -V | sed -e 's/.* \(.*\)-.*/\1/'
Version: 0.9.12-eff1fe6
$ smenu -V 2>&1 | sed -e 's/.* \(.*\)-.*/\1/'
0.9.12
$

I don't know if it is on purpose or not, so here it goes.

Memory leak of gutter

What

Smenu leaks memory due to forgotten free() call.

Cause

Line 6038 the TELL returns from the function without freeing the variable
gutter allocated line 6018 using xstrdup, therefore leaking memory.

      char *    gutter;

      gutter = xstrdup(optarg);

      [...]

        if (n > 1)
          TELL("A multi columns gutter is not allowed -- ");

        offset += mblen;
      }

      free(gutter);
    }

Consequence

None, especially considering it happens in the main. But it bugs me ;)

Solution

Free gutter before calling TELL.

Related

I believe win.gutter_a allocated line 6031 is also leaked at that point.
I'm not certain of it though.

Version

Version 0.9.12 ; commit eff1fe6.

Error: Insufficient memory (attempt to calloc 2305843009213693952 bytes)

I do not consider this serious bug but look: this is weird!

$ smenu -V
Version: 1.0.0
$ echo '[A]' '[B]' '[C]' |smenu -ES '/([^[]]+)/\2/'
Error: Insufficient memory (attempt to calloc 2305843009213693952 bytes)

The issue is caused by the typo \2 (as well as \3, \4, etc.) in the subtitution part.

Even much weirder issue occures if you try \0 (of course a non-sense, but \0 we get a menu but what a menu it is)!

$ smenu -ES '/([^[]]+)/\0/' <<< '[1] [2] [3]'
[0 [0 [0 

๐Ÿ˜„

(So a small typo and misuse of a -ES parameter caused by my initial misread of the manual page smenu(1) revealed such weird things in the end.)

Move most of the logic from main into functions?

Hello,

I am using the Nim language (https://nim-lang.org) which interfaces with C language seamlessly.

I'd like to use your project as a library where the input is a pointer to array of strings (and all the smenu options) and output is an another pointer to an array of strings.

Would it be possible for you to pack the core of smenu into such function whose API you provide via smenu.h?

In main, you then probably just parse the command line switches and pass the appropriate args to the smenu function.

Thoughts?


PS: I started with wrapping the smenu.h here, but then realized that I cannot do much with it as most of the smenu code is inline in the main.

To use smenu via Nim, I'd then need to literally translate all the C code to Nim manually.

Windows support?

Sadly enough I have to ask this. Is windows support planned? It could possibly be as simple as compiling to a .exe with visual studio's tools, however that is not my expertise. With MinTTY and all most unix builtins are supported already.

Question about multi-select

I'm not sure how to select multiple entries when using -T

When I hit enter (of course) it chooses the entry and exits. Is there another selection button that I can't find in the docs?

The length of a word has reached the limit of 512 characters.

I tried your "Bash example (CRTL-R replacement)" with 1.0.0.RC2 but all I get after hitting Ctrl-R is "The length of a word has reached the limit of 512 characters." I do have large history files (2MB/~30,000lines and 3.6MB/80,000lines), but hstr can easily handle them.

Problems on Mac OSX and FreeBSD

Hi.

First of all, this is a nice tool, congrats.

I had problems on Mac OSX and FreeBSD.

FreeBSD:

[snip]
config.status: executing depfiles commands
make all-am
CC smenu.o
smenu.c: In function 'sig_handler':
smenu.c:3942:10: error: 'SIGWINCH' undeclared (first use in this function)
case SIGWINCH:
^
smenu.c:3942:10: note: each undeclared identifier is reported only once for each function it appears in
smenu.c: In function 'main':
smenu.c:4972:13: error: 'SIGWINCH' undeclared (first use in this function)
sigaction(SIGWINCH, &sa, NULL);
^
*** Error code 1

Stop.
make[1]: stopped in /usr/home/dbaio/FreeBSD/ports/sysutils/smenu/work/smenu-0.9.8
*** Error code 1

Stop.
make: stopped in /usr/home/dbaio/FreeBSD/ports/sysutils/smenu/work/smenu-0.9.8

Mac OSX:

[snip]
config.status: executing depfiles commands
/Library/Developer/CommandLineTools/usr/bin/make all-am
CC smenu.o
smenu.c:3963:10: error: use of undeclared identifier 'SIGWINCH'
case SIGWINCH:
^
smenu.c:4993:13: error: use of undeclared identifier 'SIGWINCH'
sigaction(SIGWINCH, &sa, NULL);
^
2 errors generated.
make[1]: *** [smenu.o] Error 1
make: *** [all] Error 2

After see this, I builded smenu without problems:
https://github.com/martanne/vis/blob/master/configure#L213

FreeBSD:
-D__BSD_VISIBLE

MacOS:
-D_DARWIN_C_SOURCE

but now smenu is not working as on linux.

R=$(seq 600 | smenu -d -s '/190')

This above example on both MacOS and FreeBSD, freezes after one move.

I've tried different compilations on FreeBSD but the problem occurs always.

ldd /usr/local/bin/smenu
/usr/local/bin/smenu:
libncurses.so.8 => /lib/libncurses.so.8 (0x800832000)
libc.so.7 => /lib/libc.so.7 (0x800a86000)

ldd /usr/local/bin/smenu
/usr/local/bin/smenu:
libtinfo.so.6 => /usr/local/lib/libtinfo.so.6 (0x800832000)
libc.so.7 => /lib/libc.so.7 (0x800a6b000)

Do you have any thoughts or advices about this?

ps. I really want to port it on FreeBSD =)

Best regards.

smenu -l chops exterior quotes

Hi,
either I'm doing something wrong or smenu is. I would like to display and select quoted strings as in the following three choices:

printf %s\\n '"a"' "'a'" 'a'
"a"
'a'
a

but smenu displays the same three unquoted letters:

printf %s\\n '"a"' "'a'" 'a' | smenu -l
a
a
a

Platform: Linux 64-bit
smenu version: 0.9.16

Thank you

Precompiled binaries

Hi,

Would be nice to have pre-compiled binaries for different architecture to let user test/use smenu quickly without the need to compile it.

Regards,

A column context but limiting how many columns are produced

I have inputs which display livestreams, the view count and their title; e.g.

foobar 1234 title of the stream
baz 1337 another title for another stream

When using -c -C1 this more or less does what I want, making only the first column selectable and producing alignment over the view count. The problem is that the rest of the message is also aligned, which I'd like to avoid, e.g.

foobar | 1234 | title   | of    | the | stream
baz    | 1337 | another | title | for | another stream

Instead I would like something that behaves as follows:

foobar | 1234 | title of the stream
baz    | 1337 | another title for another stream

(Using | as a visual indicator of the columns, not much unlike -g '|| ')

I'm not sure if what I'm after can be done with existing features, I tried my best to look through the manual but didn't find anything particularly obvious.

-g|-gutter missing in -h output

Expected:

Some of the gutter text from master/usage.c

Actual:

$ smenu --version
Version: 1.1.0

$  smenu -h | grep -E '\-g|\-gutter'
  [-z|-zap|-zap-glyphs #bytes] [-n|-lines|-height [#height]] [-b|-blank] 
  [-f|-forgotten_timeout|-global_timeout #timeout] 
-f|-forgotten_timeout|-global_timeout

Same result from v1.1.0 glibc static release, and binary built using build.sh as of 4068e3a.

Option to start with search running

Would it be possible to add an option, which would start the prefedined search method without pressing additional keys like "/" ? What I am trying to achieve is to be able to run smenu with some server names and directly search for substrings.

thanks.

Support for multiple selections?

Hello,

I just tried out this neat utility and like the minimalism aspect of it.

Is there a way to do multiple selections?

Here's a trivial example (in tcsh):

set foo=`echo "A B C" | smenu` && echo $foo

Right now, I can set foo to "A", "B" or "C". Is there a way so that foo can be set to something like "A\0B", "A\0C", "C\0B", or even "A\0B\0C", where \0 is the null character?

feature request: exit 1 on Control-C pressed?

Hello,

Currently pressing control-c during smenu selection makes smenu exit 0 with no output. Is it possible to make smenu exit 1 in this case? My need is to distinguish between smenu's empty output due to empty input vs non-empty input and control-c pressed. Thank you for your consideration.

Gentoo Linux - All Tests PASS

For posterity. You may close this issue.

All tests PASS on Gentoo Linux (Dell Inspiron 2012?)

  All validated tests passed successfully !
  real	15m0.557s
  user	0m2.475s
  sys	0m4.731s
  jlpoole@themis /tmp/test
  themis /tmp/tests # emerge --info
  Portage 2.3.24 (python 3.5.5-final-0, default/linux/amd64/17.0, gcc-6.4.0, glibc-2.25-r11, 4.9.16-gentoo x86_64)
  =================================================================
  System uname: Linux-4.9.16-gentoo-x86_64-Intel-R-_Core-TM-_i5_CPU_M_460_@_2.53GHz-with-gentoo-2.4.1
  KiB Mem:     5893596 total,    498560 free
  KiB Swap:     524284 total,    524284 free
  Timestamp of repository gentoo: Sat, 26 May 2018 20:30:01 +0000
  Head commit of repository gentoo: 090b200fa862768e5db2ad569d32fa42f495408b
  sh bash 4.4_p12
  ld GNU ld (Gentoo 2.26.1 p1.0) 2.26.1
  app-shells/bash:          4.4_p12::gentoo
  dev-java/java-config:     2.2.0-r4::gentoo
  dev-lang/perl:            5.24.3-r1::gentoo
  dev-lang/python:          2.7.14-r1::gentoo, 3.4.5-r1::gentoo, 3.5.5::gentoo
  dev-util/cmake:           3.9.6::gentoo
  dev-util/pkgconfig:       0.29.2::gentoo
  sys-apps/baselayout:      2.4.1-r2::gentoo
  sys-apps/openrc:          0.34.11::gentoo
  sys-apps/sandbox:         2.13::gentoo
  sys-devel/autoconf:       2.13::gentoo, 2.69-r4::gentoo
  sys-devel/automake:       1.11.6-r3::gentoo, 1.15.1-r2::gentoo
  sys-devel/binutils:       2.26.1::gentoo, 2.28-r2::gentoo, 2.29.1-r1::gentoo
  sys-devel/gcc:            4.9.4::gentoo, 5.4.0-r3::gentoo, 6.4.0-r1::gentoo
  sys-devel/gcc-config:     1.8-r1::gentoo
  sys-devel/libtool:        2.4.6-r3::gentoo
  sys-devel/make:           4.2.1::gentoo
  sys-kernel/linux-headers: 4.13::gentoo (virtual/os-headers)
  sys-libs/glibc:           2.25-r11::gentoo
  Repositories:
  
  gentoo
      location: /usr/portage
      sync-type: rsync
      sync-uri: rsync://rsync.gentoo.org/gentoo-portage
      priority: -1000
      sync-rsync-verify-metamanifest: no
      sync-rsync-extra-opts: 
  
  JLPOOLE_OVERLAY
      location: /usr/local/portage
      masters: gentoo
  
  ACCEPT_KEYWORDS="amd64"
  ACCEPT_LICENSE="* -@EULA"
  CBUILD="x86_64-pc-linux-gnu"
  CFLAGS="-march=native -O2 -pipe"
  CHOST="x86_64-pc-linux-gnu"
  CONFIG_PROTECT="/etc /usr/share/gnupg/qualified.txt"
  CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/php/apache2-php7.0/ext-active/ /etc/php/apache2-php7.1/ext-active/ /etc/php/cgi-php7.0/ext-active/ /etc/php/cgi-php7.1/ext-active/ /etc/php/cli-php7.0/ext-active/ /etc/php/cli-php7.1/ext-active/ /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
  CXXFLAGS="-march=native -O2 -pipe"
  DISTDIR="/usr/portage/distfiles"
  FCFLAGS="-O2 -pipe"
  FEATURES="assume-digests binpkg-logs config-protect-if-modified distlocks ebuild-locks fixlafiles merge-sync multilib-strict news parallel-fetch preserve-libs protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
  FFLAGS="-O2 -pipe"
  GENTOO_MIRRORS="http://gentoo.osuosl.org/ http://mirror.usu.edu/mirrors/gentoo/"
  LANG="en_US.utf8"
  LDFLAGS="-Wl,-O1 -Wl,--as-needed"
  MAKEOPTS="-j3"
  PKGDIR="/usr/portage/packages"
  PORTAGE_CONFIGROOT="/"
  PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git"
  PORTAGE_TMPDIR="/var/tmp"
  USE="X acl amd64 berkdb bindist bzip2 cli crypt cxx dbus dri fortran gdbm iconv ipv6 jpeg lock modules multilib ncurses nls nptl openmp pam pcre php readline seccomp session ssl startup-notification tcpd thunar udev unicode xattr zlib" ABI_X86="64" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="karbon plan sheets stage words" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="mmx mmxext popcnt sse sse2 sse3 sse4_1 sse4_2 ssse3" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock isync itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 timing tsip tripmate tnt ublox ubx" INPUT_DEVICES="evdev synaptics" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php5-6 php7-0" POSTGRES_TARGETS="postgres9_5" PYTHON_SINGLE_TARGET="python3_5" PYTHON_TARGETS="python2_7 python3_5" RUBY_TARGETS="ruby23" USERLAND="GNU" VIDEO_CARDS="amdgpu fbdev intel nouveau radeon radeonsi vesa dummy v4l" XFCE_PLUGINS="brightness clock trash" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
  Unset:  CC, CPPFLAGS, CTARGET, CXX, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LC_ALL, LINGUAS, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
  
  themis /tmp/tests # 

Similar dmenu input behaviour

How would I go about to reproduce the input behaviour of dmenu?
I need to have the following behaviour with smenu as with dmenu, ie.

possible_new_option=$(
  cat ~/file-with-some-options |
  dmenu -p "Choose an option"
)

In case you are not familiar with this in dmenu, if
the file ~/file-with-some-options has no content, I simply
get an empty list to choose from and then the input I provide is the one
that dmenu will write to stdout. In the case that said file
has contents, then I can simply also choose one from the list, but also
give an input that is not in the list.

As far as I understand smenu, this is not possible, since one can not
input a string that is not given in the option, list. I would very
much like to be wrong here, since I'd like this to be possible
in order to have scripts that use smenu in the terminal and dmenu
on desktop contexts.

All I could do with smenu is something like this,

possible_new_option=$(
  cat ~/file-with-some-options |
  smenu -m "Choose an option"
)

but of course I am not able to input a random string and
if the file ~/file-with-some-options is empty then smenu simply returns.

If this is indeed possible, I would suggest putting it in the man file
for some dmenu users, which they will surely find useful.

Segmentation fault when using hidden timeout with word

$ echo "a b c" | smenu -x word d 5
# works without any problems

$ echo "a b c" | smenu -X word d 5
Segmentation fault (core dumped)

$ echo "a b c" | smenu -X current 5
# works without any problems

Kernel: 5.19.0-35-generic
OS: Ubuntu 22.04.2 LTS x86_64
Shell: bash 5.1.16

A word's length has reached the limit (256), exiting.

I am getting a crash on this, even though I am piping in 80 chars.
I have a file and the usage is:
selection=$(cut -c1-80 $TMPFILE | smenu -W$'\n' -n 22)

If I replace smenu with fzf it runs fine. I am not sure why smenu is giving this error.

Attaching the file for your information. Thanks a lot for the great work.

Problem handling text with apostrophe

Hi,

I have this array:

for index in "${!results[@]}"; do echo "${results[index]}"; done
https://www.twitch.tv/videos/441370188 (2019-06-19T19:56:36Z - 07:20:54) You can only haHAA once per day cuz I'm playing Bloodstained before SotN, okay? (After Mario first)
https://www.twitch.tv/videos/441316653 (2019-06-19T18:01:22Z - 01:53:34) You can only haHAA once per day cuz I'm playing Bloodstained before SotN, okay? (After Mario first)
https://www.twitch.tv/videos/440945888 (2019-06-18T21:28:41Z - 06:23:14) Bloodstained came out today AAAAAaaaa! (Any kickstarter backers here to rep? :)
https://www.twitch.tv/videos/440456749 (2019-06-17T20:14:21Z - 06:41:24) Future Banjo Smash Mains HMU (We're starting Banjo after Mario & Cadence!)
https://www.twitch.tv/videos/439512157 (2019-06-15T18:16:36Z - 11:44:47) Bumpin DOPE Phil Spencer interview during Mario Maker (Cadence of Hyrule after)

but if I pass it to smenu it get truncated

$ for index in "${!results[@]}"; do echo "${results[index]}"; done | smenu -n6 -l -d
 https://www.twitch.tv/videos/441370188 (2019-06-19T19:56:36Z - 07:20:54) You can only haHAA once per day cuzโ†’
 https://www.twitch.tv/videos/440945888 (2019-06-18T21:28:41Z - 06:23:14) Bloodstained came out today AAAAAaaaa! (Any kickstarter backers here to rep? :)
 https://www.twitch.tv/videos/440456749 (2019-06-17T20:14:21Z - 06:41:24) Future Banjo Smash Mains HMUโ†’

Seems to be a problem with handling apostrophe but I am not sure how to fix it

Freezes terminal with v0.9.12 in FreeBSD

I've tried just the example below:
$ R=$(awk -F: '$3 < 100 {print $1,$3,$4,$NF}' /etc/passwd \ | smenu -n10 -c)

screen shot 2018-04-09 at 19 42 03

Is there anything I can do to help in debugging?

Regards.

autoconf hardcoded version

Now autoconf 1.16 is used and after configure version of aclocal and automake is hadrcoded into Makefile. If I change it to 1.13, make still works fine (Centos -7.8).

I think hardcoded autoconf version is not a good choice...

v1.3.0 not working with TERM=xterm

Hi,
i've installed smenu from smenu-1.3.0-linux-glibc-x86-static.xz
i can't start smenu now:

# smenu 
'xterm': unknown terminal type.

According to #16 (comment)
xterm shout work.

If there is anything i can help, feel free to reach out!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.